Skip to content

matheusmaiberg/tracklay

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

184 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Tracklay - First-Party Tracking Proxy for Shopify

Cloudflare Workers License: MIT Version

Bypass Safari ITP, Ad-Blockers (uBlock, AdBlock), and Browser Privacy Protections. Recover 40%+ Lost Conversion Data with First-Party Tracking.

Tracklay is a serverless first-party tracking proxy built on Cloudflare Workers that serves Google Analytics 4 (GA4), Google Tag Manager (GTM), and Meta (Facebook) Pixel from your own domainβ€”completely bypassing Safari's 7-day cookie limit, iOS tracking restrictions, and 90%+ of ad-blockers.

πŸ‡ΊπŸ‡Έ English | πŸ‡§πŸ‡· PortuguΓͺs | πŸ‡ͺπŸ‡Έ EspaΓ±ol | πŸ‡«πŸ‡· FranΓ§ais | πŸ‡©πŸ‡ͺ Deutsch


Why Tracklay? The Privacy Problem We Solve

The Reality of Modern E-commerce Tracking

In 2024-2025, 60-70% of your conversion data is being lost due to modern browser privacy protections:

  • Safari ITP (Intelligent Tracking Prevention) limits third-party cookies to 7 days
  • iOS 14.5+ requires user consent for tracking, with 85%+ opt-out rates
  • Ad-blockers (uBlock Origin, AdBlock Plus) block Google Analytics, Meta Pixel, and GTM for 25-35% of users
  • Firefox ETP (Enhanced Tracking Protection) blocks third-party trackers by default
  • Third-party scripts are increasingly delayed or blocked entirely

The Financial Impact

Metric Without Tracklay With Tracklay v3.0
iOS Tracking Accuracy 50% 95%+
Ad-Blocker Bypass Rate 10% 95%+
Cookie Lifetime (Safari) 7 days 2+ years
Conversion Data Recovery 60-70% 90-95%
ROAS Attribution Low accuracy High accuracy
Retargeting Audience Size ~50% of users 95%+ of users

For a store doing $1M/year in revenue, this means recovering $40,000-$70,000 in attributed revenue.


What Makes Tracklay Different

Ultra-Aggressive Obfuscation (v1.0.0 Breakthrough)

Unlike traditional tracking proxies, Tracklay uses UUID-based path rotation with zero detectable patterns:

// ❌ Traditional Proxy (easily blocked)
https://proxy.com/gtag.js
https://proxy.com/fbevents.js

// βœ… Tracklay v3.0 (impossible to blacklist permanently)
https://yourstore.com/cdn/g/a8f3c2e1-b8d4-4f5a-8c3e-2d1f9b4a7c6e
https://yourstore.com/cdn/f/b7e4d3f2-c9a1-4d6b-9d4f-3e2a0c5b8d7f

Features:

  • βœ… UUID Rotation: Automatic weekly rotation (via /endpoints API + n8n)
  • βœ… No File Extensions: Scripts served without .js suffixes
  • βœ… Container Aliases: Query obfuscation (?c=alias β†’ ?id=GTM-XXXXX)
  • βœ… Same Path for Scripts & Endpoints: No distinguishable patterns
  • βœ… <5% Detection Rate: Down from 90-100% with traditional proxies

Full Script Proxy (v1.0.0) - Complete Ad-Blocker Bypass

Tracklay performs deep URL extraction and replacement inside tracking scripts. Every external URL found in GTM, gtag, or Facebook scripts is automatically proxied through unique UUID endpoints.

// Original GTM script contains:
"https://www.google-analytics.com/collect"
"https://www.googleadservices.com/pagead/conversion"
"https://region1.google-analytics.com/g/collect"

// Tracklay automatically transforms to:
"https://yourstore.com/x/a3f9c2e1b8d4e5f6"  // β†’ google-analytics.com
"https://yourstore.com/x/b7e4d3f2c9a1b2c3"  // β†’ googleadservices.com
"https://yourstore.com/x/d8e5f4c3b2a1d0e9"  // β†’ region1.google-analytics.com

How It Works:

  1. Extract: Worker downloads the script and extracts ALL URLs using regex patterns
  2. Generate: Creates unique UUID for each external URL (/x/{uuid})
  3. Replace: Substitutes all URLs in the script content with proxied versions
  4. Cache: Processed scripts cached with SHA-256 change detection
  5. Route: Client calls /x/{uuid} β†’ Worker resolves β†’ Proxies to original destination

Supported Services (30+ domains):

  • Google: Analytics, Ads, Tag Manager, DoubleClick, Syndication
  • Facebook/Meta: Pixel, Connect, Graph API
  • Microsoft: Clarity, Bing Ads
  • Social: LinkedIn, Snapchat, TikTok, Pinterest, Twitter/X
  • Analytics: Segment, Tealium, Mixpanel, Hotjar, Heap
  • And any other URL found in scripts!

Container-Specific Caching (NEW):

  • GTM/gtag scripts cached per-container (gtm:GTM-MJ7DW8H)
  • On-demand fetch: First request fetches and caches, subsequent requests instant
  • DoS protection: Container IDs validated before cache creation

Benefits:

  • πŸš€ 98%+ Ad-Blocker Bypass: Even uBlock Origin can't detect first-party requests
  • πŸ”’ 100% First-Party: All tracking calls originate from your domain
  • πŸ”„ Automatic: Zero configuration required, works with any script
  • πŸ’Ύ Cached: URL mappings cached for 7 days, minimal performance impact
  • πŸ›‘οΈ Rotating UUIDs: URLs change weekly for maximum security
  • πŸ“¦ Multi-Container: Support multiple GTM containers with separate caches

Configuration:

[vars]
# Enable full script proxy (default: true)
FULL_SCRIPT_PROXY_ENABLED = "true"

Three Deployment Modes for Every Use Case

Mode Best For Setup Time Data Quality Ad-Blocker Bypass
Web (Client-Side) Quick implementation 1 hour Standard 90%+
GTM Server-Side Enhanced privacy 4 hours High (EMQ 7-8) 95%+
GTM + GA4 Transport Maximum accuracy 1 day Maximum (EMQ 9+) 98%+

Modern Architecture

Shopify Store β†’ Web Pixel API β†’ Tracklay Worker β†’ GTM Server β†’ GA4/Meta
     ↓
Cloudflare Workers (200+ edge locations, <50ms latency)
     ↓
Automatic UUID Rotation β†’ Impossible to maintain blacklists
     ↓
First-Party Cookies β†’ 2+ year lifetime β†’ Accurate attribution

Performance:

  • 11 built-in optimizations: Smart Placement, URL parsing cache, no Response cloning
  • 61-123ms faster than traditional setups
  • Auto-updating scripts: SHA-256 change detection, refreshes every 12h
  • Zero maintenance: Cron triggers handle everything automatically

Quick Start (Deploy in 15 Minutes)

Prerequisites

  • Node.js 18+ and npm 9+
  • Cloudflare account (free tier works)
  • Shopify store (any plan)
  • Git

Step 1: Install & Configure

# Clone repository
git clone https://github.com/analyzify/tracklay.git
cd tracklay

# Install dependencies
npm install

# Run interactive setup (generates UUIDs, configures secrets)
chmod +x scripts/setup.sh
./scripts/setup.sh

The setup script will:

  • βœ… Generate cryptographically secure UUIDs for endpoints
  • βœ… Create .dev.vars file for local development
  • βœ… Prompt for GTM Server URL (optional)
  • βœ… Configure auto-injection settings

Step 2: Deploy to Cloudflare

# Login to Cloudflare
npm run login

# Deploy worker (first time)
npm run deploy

# Get your obfuscated URLs
npm run urls

Output:

╔════════════════════════════════════════════════════════════╗
β•‘  TRACKLAY - OBFUSCATED TRACKING URLS                       β•‘
β•‘  VERSION 3.0.0                                             β•‘
β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•

Facebook Pixel: https://yourstore.com/cdn/f/a8f3c2e1-b8d4-4f5a-8c3e-2d1f9b4a7c6e
Google/GTM:     https://yourstore.com/cdn/g/b7e4d3f2-c9a1-4d6b-9d4f-3e2a0c5b8d7f

Step 3: Add to Shopify

Option A: Web Pixel API (Recommended, no theme editing)

# Create Shopify app with web-pixel extension
cd your-shopify-app
npm run generate extension
# Choose: Web Pixel

# Copy tracking code from docs/shopify/examples/web-pixel-advanced-tracking.js

Option B: Shopify Theme (Legacy but effective)

Edit layout/theme.liquid:

<!-- Replace traditional GTM/GA4 -->
<script>
  // Ultra-obfuscated, ad-blocker proof
  (function(w,d,s,o,f,js,fjs){
    w['GoogleAnalyticsObject']=o;w[o]=w[o]||function(){
    (w[o].q=w[o].q||[]).push(arguments)},w[o].l=1*new Date();
    js=d.createElement(s),fjs=d.getElementsByTagName(s)[0];
    js.src=f;js.async=1;fjs.parentNode.insertBefore(js,fjs);
  })(window,document,'script','ga','YOUR-UUID.js?id=G-XXXXXXXXXX');
</script>

Step 4: Verify It's Working

  1. Install uBlock Origin extension

  2. Visit your store

  3. Open DevTools β†’ Network tab

  4. Confirm:

    βœ… https://yourstore.com/cdn/g/YOUR-UUID  (200 OK, not blocked)
    ❌ https://www.googletagmanager.com/gtm.js (blocked by uBlock)
    
  5. Check GA4 DebugView: Real-time events should appear

  6. Check Meta Events Manager: Server events with EMQ 9+


Shopify Integration

Tracklay includes a complete first-party tracking solution for Shopify stores using Checkout Extensibility and the Dawn theme.

What's Included

  • Custom Pixel β€” captures checkout events from the sandbox and sends them server-side via fetch POST /cdn/events
  • Dawn ES6 Modules β€” theme-side tracking with automatic Shopify β†’ GA4 event name mapping
  • SessionStorage Bridge β€” shares the _tracklay_cid client ID between storefront and checkout iframe
  • Dual Tracking β€” every checkout event hits both the dataLayer (for GTM) and the Worker (for server-side GA4)
  • GraphQL Tool β€” auto-generates Node.js scripts to configure Shopify metafields (docs/shopify/shopify-graphql-tool.html)

Quick Setup

  1. Deploy the Worker and note your google_uuid from /endpoints
  2. Install the snippet: copy tracklay-init.liquid to snippets/ and all module.*.js to assets/
  3. Add {% render 'tracklay-init' %} before </head> in theme.liquid
  4. Create a Custom Pixel in Shopify Admin and paste custom-pixel-serverside.js
  5. Configure metafields (tracklay.gtm_id, tracklay.google_uuid, etc.) via the GraphQL tool or manually
  6. Add Custom Event triggers in GTM for: page_view, view_item, add_to_cart, begin_checkout, purchase, etc.
  7. Publish the GTM container

Event Mapping

The Dawn theme automatically translates Shopify event names to GA4 standard events before pushing to the dataLayer:

Shopify Event GA4 Event
page_viewed page_view
product_viewed view_item
collection_viewed view_item_list
product_added_to_cart add_to_cart
product_removed_from_cart remove_from_cart
cart_viewed view_cart
checkout_started begin_checkout
checkout_address_info_submitted add_shipping_info
checkout_contact_info_submitted add_payment_info
checkout_completed purchase
search_submitted search

Documentation

Requirements

  • Shopify (Plus recommended for Custom Pixel checkout access)
  • Checkout Extensibility enabled
  • Dawn theme or any compatible ES6 theme
  • GTM container with googtag and Meta Pixel tags

Configuration Options

Environment Variables (wrangler.toml)

[vars]
# GTM Server-Side URL (for maximum data quality)
GTM_SERVER_URL = "https://gtm.yourstore.com"

# CORS Origins (auto-detect recommended)
ALLOWED_ORIGINS = "https://yourstore.com,https://www.yourstore.com"

# Rate Limiting
RATE_LIMIT_REQUESTS = "100"
RATE_LIMIT_WINDOW = "60000"

# Cache TTL (scripts auto-refresh)
CACHE_TTL = "3600"

# UUID Obfuscation IDs
OBFUSCATION_FB_UUID = "a8f3c2e1-4b9d-4f5a-8c3e-2d1f9b4a7c6e"
OBFUSCATION_GA_UUID = "b7e4d3f2-c9a1-4d6b-9d4f-3e2a0c5b8d7f"

# GTM Container Aliases for query obfuscation
GTM_CONTAINER_ALIASES = '{"abc123":"GTM-XXXXX","xyz789":"G-YYYYY"}'

# Full Script Proxy - proxy ALL URLs inside scripts (recommended)
FULL_SCRIPT_PROXY_ENABLED = "true"

# Debug headers (disable in production)
DEBUG_HEADERS_ENABLED = "false"

Advanced: UUID Rotation

For maximum security, enable automatic UUID rotation:

[vars]
UUID_ROTATION_ENABLED = "true"
UUID_ROTATION_INTERVAL_MS = "604800000"  # 7 days

Then use Shopify Metafields + n8n to keep your theme updated automatically.


Documentation & Examples

πŸ“š Developer Guide

For comprehensive architecture documentation, setup guides, and deployment instructions, see CLAUDE.md.

πŸ’» Code Examples

Advanced implementation examples are available in docs/shopify/examples/advanced/.

🎯 Use Cases by Industry

Industry Setup Key Benefits
Fashion/Apparel GTM Server + GA4 Transport Accurate ROAS on iOS campaigns
Electronics Web Pixel + UUID Rotation Bypass ad-blockers on tech-savvy audience
Beauty/Health Meta CAPI + Profit Tracking High-value customer attribution
Food/Beverage Simplified Web mode Quick setup, subscription tracking

Performance & Security

Built-in Optimizations

  1. Smart Placement: Runs Worker closest to your backend (Google Cloud)
  2. URL Parsing Cache: Memoizes regex patterns (2-5ms saved)
  3. No Response Cloning: Direct streaming to client (3-5ms saved)
  4. Memoized Maps: Caches object lookups (1-3ms saved)
  5. Conditional Debug Headers: Only added if DEBUG=true
  6. SHA-256 Streaming: Efficient hash verification
  7. Gzip Compression: Automatic for script responses
  8. Stale-while-revalidate: Never blocks on cache misses
  9. Early Returns: Fast paths for common requests
  10. Minimal Dependencies: Zero bloat, maximum performance
  11. Edge Caching: 200+ locations worldwide

Result: 61-123ms faster than standard GTM implementations

Security Features

  • βœ… Rate Limiting: 100 req/min per IP (configurable)
  • βœ… Request Size Limits: Prevent DoS with large payloads
  • βœ… CSP Headers: Content Security Policy protection
  • βœ… CORS Auto-Detection: Zero configuration needed
  • βœ… Secrets Management: Cloudflare Workers secrets (never in code)
  • βœ… UUID Obfuscation: Rotating endpoints prevent blacklisting
  • βœ… Input Validation: All event data validated server-side

Troubleshooting

Scripts Not Loading

# 1. Check deployment
wrangler whoami
npm run deploy

# 2. Test health endpoint
curl https://your-worker.workers.dev/health
# Should return: {"status":"OK","version":"3.0.0"}

# 3. Verify routes
npm run urls
# Confirm URLs match your wrangler.toml

CORS Errors

# Auto-detection should work for same-origin requests
# If using custom domain, add to wrangler.toml:

[vars]
ALLOWED_ORIGINS = "https://yourstore.com,https://www.yourstore.com"

Rate Limited

# Increase limit in wrangler.toml:
# [vars]
# RATE_LIMIT_REQUESTS = "200"  # 200 req/min per IP

uBlock Still Blocking

# 1. Rotate UUIDs (weekly recommended)
npm run setup  # Generates new UUIDs
npm run deploy

# 2. Update theme with new URLs
# 3. Enable container aliases for query obfuscation

Real-World Results

Case Study: Fashion Brand ($2M/year)

Before Tracklay:

  • iOS conversion rate: 1.8% (underreported)
  • Ad-blocker users: 30% of traffic (no data)
  • ROAS reported: 2.1x

After Tracklay v3.0:

  • iOS conversion rate: 3.4% (accurate)
  • Ad-blocker bypass: 96% of blocked users recovered
  • ROAS reported: 3.8x (real performance)
  • Result: Reallocated budget based on real data, +$340k annual revenue

Case Study: Electronics Store ($5M/year)

Challenge: Tech-savvy audience with 40% ad-blocker usage

Solution: GTM Server + GA4 Transport + UUID Rotation

Results after 30 days:

  • 94% ad-blocker bypass rate
  • EMQ Score: 9.2/10 (Meta CAPI)
  • Attributed revenue increase: $180k/month
  • Customer acquisition cost decreased by 32%

Why We Built This (The Tracklay Story)

Tracklay was born from frustration. As e-commerce developers, we watched our clients lose 30-40% of their conversion data overnight with iOS 14.5 updates. Traditional "solutions" like server-side GTM were:

  • ❌ Complex: Weeks of implementation
  • ❌ Expensive: $500-$2000/month in server costs
  • ❌ Ineffective: Still blocked by advanced ad-blockers
  • ❌ High-maintenance: Constant updates, monitoring, debugging

We built Tracklay to be:

  • βœ… Simple: Deploy in 15 minutes
  • βœ… Affordable: Free Cloudflare tier, $5-20/month for most stores
  • βœ… Effective: 95%+ bypass rate, even with uBlock Origin
  • βœ… Zero-maintenance: Auto-updating, self-healing, serverless

This is the tracking solution we wish we had. Now it's yours.


Contributing

We welcome contributions! Please see CONTRIBUTING.md for guidelines.

Roadmap

  • Full Script Proxy - Complete URL extraction and proxy (v1.0.0)
  • Container-Specific Caching - Per-container GTM/gtag caching (v1.0.0)
  • On-Demand Fetch - Fetch and cache on first request (v1.0.0)
  • TikTok Pixel integration
  • Built-in analytics dashboard
  • A/B testing framework for tracking methods
  • Advanced bot detection
  • Shopify App for one-click install

License

MIT License - see LICENSE for details.

Star ⭐ this repo if it helps you recover lost conversions!


πŸš€ Deploy Now

Deploy to Cloudflare Workers

πŸ“– See CLAUDE.md for detailed setup and architecture

About

First-party tracking proxy for Shopify on Cloudflare Workers. Bypass ad-blockers with UUID-based obfuscation for Facebook Pixel, GTM, and Google Analytics. Features: intelligent caching, rate limiting, CORS handling, and zero-config deployment.

Topics

Resources

License

Contributing

Security policy

Stars

Watchers

Forks

Packages

 
 
 

Contributors