Skip to content

BryceEWatson/shopify-tyos-migrator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

106 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Shopify TY/OS Migrator β€” Automated Tracking Migration

JavaScript Node.js Shopify Playwright Fly.io pnpm

⚠️ Critical Timeline: Shopify sunsets Thank-You/Order-Status scripts for Plus merchants on August 28, 2025 and non-Plus on August 26, 2026¹.

A comprehensive solution for migrating tracking pixels from legacy Shopify Thank You/Order Status pages to the modern Customer Events API and Checkout UI Extensions. This Windows-safe monorepo achieves 100% automation rate for major advertising platforms.

πŸ’° Market Opportunity

Agencies charge $1.3k–$2.5k for manual migrations while tracking apps cost $10–$150/monthΒ². Our automated solution provides instant migration at a fraction of the cost.

πŸš€ Quick Start

One-Command Setup (Recommended)

# Automated setup for new developers
pnpm setup:dev

This will:

  • Check Node.js version (β‰₯22 required)
  • Install dependencies
  • Set up development environment
  • Create necessary directories
  • Provide next steps

Manual Setup

# Install dependencies
pnpm install

# Copy development environment config
cp .env.development .env

# Run migration scan on fixtures
pnpm migrate:scan

# Generate migrated pixel code
pnpm migrate:emit

# Run critical path tests
pnpm test:critical

# Start development server
pnpm dev:api          # API server (port 3001)
pnpm dev:landing      # Landing page (port 3000)

🎯 Key Features

Migration Capabilities

  • 8 Major Platforms Supported: Google Ads, GA4, Meta Pixel, TikTok, Pinterest, Snap, Klaviyo, Bing UET
  • 100% Automation Rate: Fully automated conversion from legacy tracking to Customer Events API
  • Server-Side Deduplication: Unique event IDs prevent duplicate conversion reporting
  • Dynamic Configuration: Merchant-specific conversion IDs via vendor-config.json

Enterprise Features

  • Shopify OAuth 2.0: Secure merchant authentication with Admin API access
  • Consent Mode v2: Full compliance with Google's consent requirementsΒ³
  • OAuth Authentication: Google SSO integration for improved conversion (20-40% boost)
  • SQLite Database: Scalable storage with automatic migration from JSON
  • WCAG Accessibility: Full compliance with modern accessibility standards
  • Security Hardened: HMAC validation, CSRF protection, input validation, encrypted tokens
  • Production Ready: Docker containers, Fly.io deployment, Prometheus metrics
  • Monitoring: Pino logging, Sentry integration, health checks
  • Backup System: Automated SQLite backups with Litestream to S3/B2
  • Session Management: Redis-backed sessions with 24-hour TTL

Developer Experience

  • Claude Code Ready: Optimized for AI-assisted development
  • Comprehensive Testing: E2E tests with Playwright, QA harness for validation
  • Modular Architecture: pnpm workspaces with clear separation of concerns
  • Windows Compatible: No special characters in filenames

πŸ“¦ Project Structure

shopify-tyos-migrator/
β”œβ”€β”€ apps/                    # Application servers
β”‚   β”œβ”€β”€ api/                # Production API with metrics & monitoring
β”‚   └── landing/            # Sign-up page with OAuth & SQLite
β”œβ”€β”€ extensions/             # Shopify extensions
β”‚   β”œβ”€β”€ thank-you-ui/      # Checkout UI extension template
β”‚   └── web-pixel/         # Customer Events pixel implementations
β”œβ”€β”€ packages/              # Shared packages
β”‚   β”œβ”€β”€ consent/          # Consent management utilities
β”‚   β”œβ”€β”€ e2e/             # Playwright end-to-end tests
β”‚   β”œβ”€β”€ migrator/        # CLI tool for code migration
β”‚   β”œβ”€β”€ patterns/        # Pattern matching utilities
β”‚   β”œβ”€β”€ qa-harness/      # QA testing framework
β”‚   └── reporting/       # Analytics and reporting tools
└── fixtures/            # Sample tracking code for testing

πŸ§ͺ Testing

Need help testing? See the Testing Guide for step-by-step instructions.

  • Manual Testing: docs/test-plans/manual-test-checklist.md - 130-point checklist
  • Quick Start: Focus on P0 tests (OAuth, Detection, Migration, Consent Mode)
  • Report Issues: Use gh issue create --label bug

πŸš€ Quick Start

# Prerequisites: Node.js >=22.0.0, pnpm

# Install dependencies (also sets up Git hooks)
pnpm i
pnpm --filter @pkg/e2e exec playwright install chromium

# Run migration workflow
pnpm migrate:scan    # Analyze tracking code in fixtures/
pnpm migrate:emit    # Generate Customer Events API code

# Run tests
pnpm test           # Run QA harness
pnpm e2e            # Run Playwright E2E tests

# Start services
pnpm dev:landing    # Start sign-up page (port 3000)
pnpm dev:api        # Start API server (port 3001)
pnpm dev            # Start API server (default)

πŸͺ Local Quality Checks

This project uses Git hooks for quality assurance instead of CI/CD:

  • Pre-commit: Runs tests, linting, and security checks automatically
  • Pre-push: Comprehensive validation before pushing to remote
  • No external CI/CD dependencies - everything runs locally

See Local Development Guide for details.

πŸ”§ Configuration

1. Vendor Configuration

Create vendor-config.json from the sample:

cp vendor-config.sample.json vendor-config.json

Edit with your actual vendor IDs. See docs/VENDOR_SETUP.md for detailed instructions on where to find each vendor's IDs and how to configure them via environment variables.

2. OAuth Setup (Landing Page)

Create .env in apps/landing/:

cp apps/landing/.env.example apps/landing/.env

Configure Google OAuth:

GOOGLE_CLIENT_ID=your-client-id.apps.googleusercontent.com
GOOGLE_CLIENT_SECRET=your-secret
SESSION_SECRET=change-this-in-production
ADMIN_API_KEY=secure-api-key-for-admin-endpoints

3. Database Configuration

The landing page uses SQLite by default. Data is stored in apps/landing/signups.db.

  • Automatic migration from existing signups.json files
  • Prepared statements prevent SQL injection
  • Indexes on email and timestamp for performance

4. Cache Configuration (Redis via Upstash)

The API server uses Redis caching for improved performance with graceful fallback if unavailable.

  • Provider: Upstash Redis (serverless, TLS-encrypted)
  • Free Tier: 500K commands/month, 256MB storage
  • Health Monitoring: Available at /healthz endpoint

For detailed setup instructions and configuration options, see docs/REDIS_SETUP.md.

πŸ” Environment Variables

API Server (apps/api)

Variable Description Default Required
API_PORT API server port 3001 No
NODE_ENV Environment (development/production) development No
DATABASE_URL SQLite database path ./data/api.db No
ALLOWED_ORIGINS CORS allowed origins (comma-separated) * in dev Yes in prod
REDIS_URL Redis connection URL - No
SESSION_SECRET Session encryption key - Yes
LOG_LEVEL Logging level (error/warn/info/debug) info No
SENTRY_DSN Sentry error tracking DSN - No

Landing Page (apps/landing)

Variable Description Default Required
PORT Server port 3000 No
NODE_ENV Environment (development/production) development No
ALLOWED_ORIGINS CORS allowed origins (comma-separated) - Yes in prod
GOOGLE_CLIENT_ID Google OAuth client ID - Yes
GOOGLE_CLIENT_SECRET Google OAuth client secret - Yes
SESSION_SECRET Session encryption key - Yes
DATABASE_PATH SQLite database path ./data/signups.db No
ADMIN_API_KEY Admin API authentication key - Recommended

Production Deployment

When deploying to production (e.g., Fly.io), ensure these are set:

  • NODE_ENV=production
  • ALLOWED_ORIGINS with your actual domains
  • Strong SESSION_SECRET values (use openssl rand -hex 32)
  • REDIS_URL for distributed caching (Upstash Redis configured)
  • SENTRY_DSN for error tracking (optional but recommended)

Fly.io CLI Setup:

# Setup Fly.io CLI path (if not in PATH)
./scripts/setup-fly-path.sh

# Or use full path directly:
/home/bryce/.fly/bin/fly status --app tyos-migrator-api
/home/bryce/.fly/bin/fly secrets list --app tyos-migrator-api

πŸ“‹ Available Commands

Command Description
pnpm dev:api Start API server
pnpm dev:landing Start sign-up page with OAuth
pnpm migrate:scan Scan fixtures for tracking patterns
pnpm migrate:emit Generate migrated pixel code
pnpm test Run QA harness tests
pnpm e2e Run all Playwright E2E tests
pnpm report Generate migration reports

πŸ§ͺ Testing

The project includes comprehensive testing:

# Unit/Integration Tests
pnpm test                    # QA harness - validates migration parity

# E2E Tests
pnpm e2e                     # All E2E tests
pnpm --filter @pkg/e2e test deduplication.spec.js  # Specific test file

# Manual Testing
pnpm dev:landing             # Test sign-up flow at http://localhost:3000
curl http://localhost:3000/api/admin/stats  # Check statistics (dev mode)

🎨 Visual Validation (CI/CD)

Pull requests automatically capture screenshots of your changes for visual review:

  • Automatic PR Screenshots: Every PR builds and runs your code locally, capturing screenshots
  • Visual Comparison: Compare PR changes against production site
  • Embedded in PR Comments: Screenshots appear directly in PR comments (small images embedded, large images linked)
  • Production-like Environment: Services run with production configuration for accurate testing

The visual validation workflow triggers on PRs that modify frontend code and posts results as a sticky comment.

Using Visual Validation

  1. Automatic: Opens a PR β†’ workflow runs β†’ screenshots posted
  2. Manual Trigger: Run workflow manually from Actions tab
  3. Local Testing:
    # Test screenshot capture with custom URLs
    LANDING_URL=http://localhost:3000 \
    API_URL=http://localhost:3001 \
    node scripts/capture-screenshots.js

πŸ”’ Security Features

  • Input Validation: Comprehensive sanitization of all user inputs
  • CSRF Protection: State parameter validation in OAuth flow
  • SQL Injection Prevention: Prepared statements in SQLite
  • Authentication: OAuth 2.0 with Google, API key for admin endpoints
  • Secure Sessions: HTTPOnly cookies, secure flag in production
  • Content Security: XSS protection through proper encoding

πŸ“Š Migration Workflow

  1. Scan Phase: Analyzes tracking code in fixtures/ directory

    pnpm migrate:scan
    # Output: packages/migrator/out/scan.json
  2. Configuration: Set up vendor IDs in vendor-config.json

  3. Emit Phase: Generates Customer Events API code

    pnpm migrate:emit
    # Output: extensions/web-pixel/src/generated/*.js
  4. Validation: Run QA harness to verify parity

    pnpm test
    # Expected: 100% parity between baseline and migrated

🎯 Supported Vendors

Vendor Type Consent Gating Deduplication
Google Ads Advertising βœ… βœ…
GA4 Analytics ❌ βœ…
Meta Pixel Advertising βœ… βœ…
TikTok Advertising βœ… βœ…
Pinterest Advertising βœ… βœ…
Snap Advertising βœ… βœ…
Klaviyo Analytics ❌ βœ…
Bing UET Advertising βœ… βœ…

πŸ“ˆ Performance Metrics

  • Automation Rate: 100% (target: 50%)
  • Vendor Coverage: 8 major platforms
  • Conversion Boost: +20-40% with OAuth implementation
  • Test Coverage: Comprehensive E2E and unit tests
  • Accessibility: WCAG 2.1 Level AA compliant

🚧 Production Deployment

⚠️ Important: Always run pre-deployment checks before deploying to production. See DEPLOYMENT-CHECKLIST.md for details.

Pre-Deployment Safety Checks

Run the automated safety check before deploying:

./scripts/pre-deploy-check.sh

This validates:

  • CSP configuration (prevents broken styles/scripts)
  • Security tests pass
  • No hardcoded secrets
  • Docker builds succeed
  • Critical page elements exist

See CSP-CONFIGURATION.md for Content Security Policy details.

Docker Deployment

Both API and Landing services include production-ready Dockerfiles:

# Build images
docker build -f apps/api/Dockerfile -t tyos-api .
docker build -f apps/landing/Dockerfile -t tyos-landing .

# Run containers
docker run -p 3001:3001 tyos-api
docker run -p 3000:3000 tyos-landing

Fly.io Deployment

Deploy to Fly.io with included configurations:

# Prerequisites
fly auth login  # or use FLY_API_TOKEN env variable

# Deploy from monorepo root
fly deploy --app tyos-migrator-api --config apps/api/fly.toml --dockerfile apps/api/Dockerfile
fly deploy --app tyos-migrator-landing --config apps/landing/fly.toml --dockerfile apps/landing/Dockerfile

Live Deployments:

Database Backup

Automated backup with Litestream to S3/B2:

  • Continuous replication (60s sync interval)
  • Daily snapshots
  • 7-day retention
  • Nightly verification with scripts/backup-verify.js

Monitoring

  • Health Checks: /healthz endpoints on both services
  • Metrics: Prometheus metrics at /metrics
  • Logging: Structured logging with Pino
  • Error Tracking: Optional Sentry integration
  • Alerts: Slack webhook notifications for backup failures

πŸ“š Documentation

For Pilot Merchants

For Developers

Complete Documentation Index

🀝 Contributing

This project uses pnpm workspaces and follows conventional commits. Please ensure all tests pass before submitting PRs.

πŸ“„ License

MIT License - See LICENSE file for details


References

ΒΉ Shopify Checkout Liquid sunset dates - Plus: August 28, 2025; Non-Plus: August 26, 2026 (Source: Opportunity Radar)
Β² Agency and app pricing data from market research (Source: Assumption Validation Report)
Β³ Google Consent Mode v2 requirements and implementation (Source: Opportunity Radar)
⁴ Migration from order.* to checkout.* variables required (Source: Shopify documentation)

About

Automated Shopify tracking pixel migration from legacy Thank You/Order Status pages to Customer Events API. 100% automation rate across 8 major ad platforms. Deployed on Fly.io.

Topics

Resources

License

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors