Domain Migration for Tracker Mergers
When a tracking domain needs to merge with or migrate to a different domain (e.g., due to company acquisition, rebranding, or infrastructure consolidation), cookie migration presents unique challenges. Unlike simple redirects, tracker migrations require careful planning to preserve user identity, maintain attribution accuracy, and minimize disruption to ongoing campaigns.
The Migration Challenge
Scenario: A tracker operating on tracker-old.com needs to migrate to tracker-new.com (or merge with another tracker's domain). This migration must:
- Preserve User Identity: Existing cookies containing user IDs, session data, or tracking identifiers must be accessible on the new domain
- Maintain Attribution: Campaign tracking links, pixel fires, and conversion attribution must continue to work
- Minimize Data Loss: Historical tracking data should remain accessible
- Support Parallel Operations: During transition, both domains may need to function simultaneously
- Comply with Privacy Regulations: GDPR, CCPA, and other regulations may require explicit user consent for domain changes
Fundamental Cookie Limitations
Critical Constraint: Browsers enforce strict domain isolation for cookies. A cookie set on tracker-old.com cannot be directly accessed by tracker-new.com, even if:
- Both domains resolve to the same server
- Both domains are managed by the same organization
- Both domains have valid SSL certificates
- The migration is temporary
Why This Matters:
Cookie: user_id=abc123
Domain=tracker-old.com OldDomain->>Browser: HTTP 200 OK
Set-Cookie: user_id=abc123
Domain=tracker-old.com Note over Browser: Migration: tracker-old.com
redirects to tracker-new.com Browser->>OldDomain: GET /pixel.gif OldDomain->>Browser: HTTP 301 Moved Permanently
Location: https://tracker-new.com/pixel.gif Browser->>Browser: Check cookies for tracker-new.com Browser->>Browser: No cookies found (different domain) Browser->>NewDomain: GET /pixel.gif
Cookie: (none) Note over Browser,NewDomain: Cookie NOT sent because
Domain=tracker-old.com doesn't
match tracker-new.com
Strategy 1: HTTP Redirect with Cookie Copying
Approach: Use HTTP redirects to forward requests, and have the target domain read cookies from the source domain via redirect flow, then set new cookies on the target domain.
Implementation Flow:
- User visits
tracker-old.com/pixel.gif - Server at
tracker-old.comreads cookie:Cookie: user_id=abc123; Domain=tracker-old.com - Server responds with 301 redirect to
tracker-new.com/pixel.gif?user_id=abc123 - Browser follows redirect (cookie may be sent if
SameSiteallows) - Server at
tracker-new.comreceives request with user_id in query parameter - Server sets new cookie:
Set-Cookie: user_id=abc123; Domain=tracker-new.com
Sequence Diagram:
Cookie: user_id=abc123
Domain=tracker-old.com OldDomain->>OldDomain: Read cookie: user_id=abc123 OldDomain->>Browser: HTTP 301 Moved Permanently
Location: https://tracker-new.com/pixel.gif?user_id=abc123&t=1704067200 Browser->>Browser: Follow redirect Browser->>NewDomain: GET /pixel.gif?user_id=abc123&t=1704067200
Cookie: (none from old domain) NewDomain->>NewDomain: Extract user_id from query param NewDomain->>NewDomain: Validate timestamp (t=1704067200) NewDomain->>Browser: HTTP 200 OK
Set-Cookie: user_id=abc123
Domain=tracker-new.com
SameSite=None#59; Secure Note over Browser,NewDomain: New cookie set on target domain
User identity preserved
Advantages:
- ✅ Works even if cookies can't be sent cross-domain
- ✅ Preserves user identity
- ✅ Compatible with all browsers
- ✅ No JavaScript required
Disadvantages:
- ⚠️ Query parameters visible in URLs (privacy concern)
- ⚠️ URL length limitations
- ⚠️ Requires URL parameter parsing on target domain
- ⚠️ Potential for parameter tampering (requires validation)
Security Considerations:
- Validate Parameters: Always validate and sanitize query parameters
- Use Timestamps: Include expiration timestamps to prevent replay attacks
- HMAC Signing: Sign parameters with HMAC to prevent tampering
- HTTPS Only: Always use HTTPS to protect parameters in transit
Example Implementation:
// tracker-old.com handler
app.get('/pixel.gif', (req, res) => {
const userId = req.cookies.user_id;
const timestamp = Math.floor(Date.now() / 1000);
const signature = createHMAC(userId + timestamp, SECRET_KEY);
const redirectUrl = `https://tracker-new.com/pixel.gif?uid=${userId}&t=${timestamp}&sig=${signature}`;
res.redirect(301, redirectUrl);
});
// tracker-new.com handler
app.get('/pixel.gif', (req, res) => {
const { uid, t, sig } = req.query;
// Validate signature
if (!validateHMAC(uid + t, sig, SECRET_KEY)) {
return res.status(400).send('Invalid signature');
}
// Validate timestamp (5 minute window)
const timestamp = parseInt(t);
if (Math.abs(Date.now() / 1000 - timestamp) > 300) {
return res.status(400).send('Expired');
}
// Set cookie on new domain
res.cookie('user_id', uid, {
domain: 'tracker-new.com',
sameSite: 'None',
secure: true,
maxAge: 365 * 24 * 60 * 60 * 1000 // 1 year
});
res.send(gifPixel());
});
Strategy 2: Dual-Domain Cookie Setting
Approach: During the transition period, set cookies on both domains simultaneously. This ensures users who visit either domain have their identity preserved.
Implementation Flow:
- User visits
tracker-new.com/pixel.gif(no cookie yet) - Server checks if user has cookie on
tracker-old.comvia server-side lookup (using shared database) - If found, server sets cookie on
tracker-new.com - Server also sets cookie on
tracker-old.comvia redirect or CORS request - Both domains now have the cookie
Sequence Diagram:
Cookie: (none) NewDomain->>Database: Lookup user by IP/fingerprint Database-->>NewDomain: Found: user_id=abc123
originally from tracker-old.com NewDomain->>NewDomain: Set cookie on tracker-new.com NewDomain->>Browser: HTTP 200 OK
Set-Cookie: user_id=abc123
Domain=tracker-new.com
SameSite=None#59; Secure Note over Browser: Later: User visits old domain Browser->>OldDomain: GET /pixel.gif
Cookie: user_id=abc123
Domain=tracker-new.com (not sent) OldDomain->>Database: Lookup user Database-->>OldDomain: Found: user_id=abc123 OldDomain->>Browser: HTTP 200 OK
Set-Cookie: user_id=abc123
Domain=tracker-old.com
SameSite=None#59; Secure Note over Browser: Now both domains have cookies
Advantages:
- ✅ No URL parameters needed
- ✅ Works for both domains simultaneously
- ✅ Preserves user identity on both domains
- ✅ Seamless transition
Disadvantages:
- ⚠️ Requires shared database or backend service
- ⚠️ Requires fingerprinting or IP-based matching (privacy concerns)
- ⚠️ May create duplicate cookies temporarily
- ⚠️ More complex implementation
Privacy Considerations:
- Fingerprinting may be restricted by privacy regulations
- IP-based matching is unreliable (NAT, VPNs, mobile networks)
- Consider explicit user consent for domain migration
- Document cookie migration in privacy policy
Strategy 3: PostMessage-Based Cookie Migration
Approach: Use JavaScript and postMessage API to coordinate cookie migration between domains via iframe or popup communication.
Implementation Flow:
- User visits
tracker-new.com(embedded in publisher site) - Page loads iframe pointing to
tracker-old.com/migrate.html - Iframe reads cookie from
tracker-old.com - Iframe sends cookie value to parent via
postMessage - Parent page receives cookie value and sets it on
tracker-new.com
Sequence Diagram:
Cookie: user_id=abc123
Domain=tracker-old.com OldDomain->>Browser: Return HTML with postMessage script OldDomain->>Browser: JavaScript reads cookie: user_id=abc123 OldDomain->>Browser: postMessage({userId: 'abc123'}, 'https://tracker-new.com') Browser->>Browser: Receive message in tracker-new.com context Browser->>Browser: Set cookie: user_id=abc123
Domain=tracker-new.com Browser->>NewDomain: GET /pixel.gif
Cookie: user_id=abc123
Domain=tracker-new.com
Advantages:
- ✅ No URL parameters
- ✅ Can work cross-domain
- ✅ Preserves user identity
- ✅ JavaScript-based (flexible)
Disadvantages:
- ⚠️ Requires JavaScript (blocks non-JS environments)
- ⚠️ Blocked by some privacy tools (uBlock Origin, Privacy Badger)
- ⚠️ SameSite restrictions may block cookies in iframe
- ⚠️ Complex implementation
- ⚠️ May be blocked by ITP (Intelligent Tracking Prevention)
Implementation Example:
<!-- tracker-new.com pixel script -->
<script>
(function() {
// Check if cookie already exists on new domain
if (getCookie('user_id')) {
return; // Already migrated
}
// Create hidden iframe to old domain
const iframe = document.createElement('iframe');
iframe.src = 'https://tracker-old.com/migrate.html';
iframe.style.display = 'none';
document.body.appendChild(iframe);
// Listen for postMessage from old domain
window.addEventListener('message', function(event) {
// Verify origin
if (event.origin !== 'https://tracker-old.com') {
return;
}
// Set cookie on new domain
if (event.data.userId) {
document.cookie = `user_id=${event.data.userId}; Domain=tracker-new.com; SameSite=None#59; Secure; Max-Age=31536000`;
// Fire pixel with migrated cookie
const img = new Image();
img.src = 'https://tracker-new.com/pixel.gif';
}
});
})();
</script>
<!-- tracker-old.com/migrate.html -->
<script>
const userId = getCookie('user_id');
if (userId) {
// Send cookie to parent window (tracker-new.com)
window.parent.postMessage({ userId: userId }, 'https://tracker-new.com');
}
</script>
Strategy 4: Server-Side Session Migration
Approach: Use server-side session storage (Redis, database) instead of cookies for user identity. Cookies store only a session ID, which can be migrated easily.
Implementation Flow:
- User visits
tracker-old.com - Server creates session in shared Redis/database
- Server sets cookie:
Set-Cookie: session_id=xyz789; Domain=tracker-old.com - Session data stored server-side:
{session_id: 'xyz789', user_id: 'abc123', ...} - During migration,
tracker-new.comchecks session ID against same database - Server sets new cookie:
Set-Cookie: session_id=xyz789; Domain=tracker-new.com - Both domains can access same session data
Advantages:
- ✅ Cookie migration is simple (just session ID)
- ✅ All user data stored server-side (more secure)
- ✅ Both domains can access same session
- ✅ No URL parameters needed
- ✅ Works with SameSite restrictions
Disadvantages:
- ⚠️ Requires shared backend infrastructure
- ⚠️ Session ID must be migrated (via redirect or other method)
- ⚠️ More server-side resources needed
- ⚠️ Requires session invalidation/expiration logic
Hybrid Approach:
Combine server-side sessions with redirect-based migration:
// tracker-old.com
app.get('/pixel.gif', (req, res) => {
const sessionId = req.cookies.session_id || generateSessionId();
const userId = getUserIdFromSession(sessionId);
// Store session data server-side
redis.set(`session:${sessionId}`, JSON.stringify({
user_id: userId,
created_at: Date.now(),
migrated: false
}));
// Redirect with session ID (small, can be signed)
const signature = createHMAC(sessionId, SECRET_KEY);
res.redirect(301, `https://tracker-new.com/pixel.gif?sid=${sessionId}&sig=${signature}`);
});
// tracker-new.com
app.get('/pixel.gif', (req, res) => {
const { sid, sig } = req.query;
// Validate signature
if (!validateHMAC(sid, sig, SECRET_KEY)) {
return res.status(400).send('Invalid');
}
// Check session in shared storage
const sessionData = JSON.parse(redis.get(`session:${sid}`));
if (!sessionData) {
return res.status(404).send('Session not found');
}
// Set cookie on new domain
res.cookie('session_id', sid, {
domain: 'tracker-new.com',
sameSite: 'None',
secure: true,
maxAge: 30 * 24 * 60 * 60 * 1000 // 30 days
});
// Mark as migrated
sessionData.migrated = true;
redis.set(`session:${sid}`, JSON.stringify(sessionData));
res.send(gifPixel());
});
Recommended Migration Strategy
Best Practice: Multi-Phase Approach
For a tracker domain migration, use a phased approach combining multiple strategies:
Phase 1: Preparation (Weeks 1-2)
Set Up Dual Infrastructure:
- Deploy
tracker-new.cominfrastructure - Set up shared database/Redis for session storage
- Configure DNS for new domain
- Deploy
Implement Cookie Migration Logic:
- Add redirect handlers on
tracker-old.com - Implement cookie copying on
tracker-new.com - Add server-side session storage
- Add redirect handlers on
Testing:
- Test redirect flow
- Test cookie migration
- Test both domains simultaneously
- Verify attribution accuracy
Phase 2: Parallel Operation (Weeks 3-8)
Enable Dual-Domain Support:
- Both domains accept pixel requests
- Both domains set cookies
- Both domains read from shared session storage
Gradual Migration:
- Start redirecting a small percentage of traffic (5-10%)
- Monitor cookie migration success rate
- Gradually increase percentage
- Monitor for attribution gaps
Update Partner Integrations:
- Notify partners of new domain
- Provide migration timeline
- Update pixel URLs in ad platforms
- Update tracking links
Sequence Diagram - Parallel Operation:
Cookie: user_id=abc123
Domain=tracker-old.com alt Old domain still active OldDomain->>Database: Store/update session OldDomain->>Browser: HTTP 200 OK
Set-Cookie: user_id=abc123
Domain=tracker-old.com else Redirect enabled (gradual migration) OldDomain->>Browser: HTTP 301
Location: tracker-new.com/pixel.gif?uid=abc123&t=...&sig=... Browser->>NewDomain: GET /pixel.gif?uid=abc123&t=...&sig=... NewDomain->>Database: Store/update session NewDomain->>Browser: HTTP 200 OK
Set-Cookie: user_id=abc123
Domain=tracker-new.com end Note over Database: Both domains write to
same session storage
Phase 3: Full Migration (Weeks 9-12)
Complete Redirect:
- 100% of traffic redirected to
tracker-new.com tracker-old.comonly handles redirects- Monitor migration success rate
- 100% of traffic redirected to
Cookie Migration:
- All cookies migrated via redirect flow
- Both domains maintain cookies (for backward compatibility)
- Monitor for users still on old domain cookies
Validation:
- Verify attribution accuracy
- Check for data gaps
- Monitor error rates
- Validate campaign performance
Phase 4: Sunset (Weeks 13-16)
Maintain Redirects:
- Keep redirects active for extended period (6-12 months)
- Handle edge cases and late migrations
Monitor Old Domain:
- Track redirect volume
- Identify when traffic drops to near zero
- Plan domain decommissioning
Final Cleanup:
- After sufficient time (6-12 months), redirect can be removed
- Old domain can be decommissioned
- Update documentation
Migration Timeline Considerations
Short Timeline (1-2 months):
- Higher risk of data loss
- More aggressive redirect strategy
- May require URL parameter migration
- Less time for testing
Medium Timeline (3-4 months):
- Recommended approach
- Gradual migration
- Dual-domain support period
- Adequate testing time
Long Timeline (6+ months):
- Lowest risk
- Extensive parallel operation
- Maximum compatibility
- Most user-friendly
Cookie Attribute Configuration
Critical Settings for Migration:
Domain Attribute:
- Old domain:
Domain=tracker-old.com - New domain:
Domain=tracker-new.com - Cannot use parent domain if domains are unrelated
- Old domain:
SameSite Attribute:
- Use
SameSite=None#59; Securefor cross-domain scenarios - Required for redirect-based migration
- Allows cookies to be sent with redirects
- Use
Secure Flag:
- Always use
Secureflag (HTTPS only) - Required when
SameSite=None - Protects cookies in transit
- Always use
Path Attribute:
- Use
Path=/for maximum compatibility - Ensures cookies work across all paths
- Use
Example Configuration:
Set-Cookie: user_id=abc123; Domain=tracker-new.com; Path=/; SameSite=None#59; Secure; Max-Age=31536000
Privacy and Compliance
GDPR Considerations:
- Domain migration may require updated privacy policy
- Users must be informed of domain changes
- Cookie consent may need to be re-obtained
- Consider explicit consent for domain migration
CCPA Considerations:
- Disclose domain migration in privacy policy
- Provide opt-out mechanisms for both domains
- Ensure user data portability
Best Practices:
Update Privacy Policy:
- Document domain migration
- Explain cookie migration process
- Provide opt-out mechanisms
User Notification:
- Consider notifying users of domain change
- Provide clear explanation
- Offer opt-out if required
Consent Management:
- Migrate consent signals
- Ensure consent applies to new domain
- Re-obtain consent if necessary
Testing Strategy
Pre-Migration Testing:
Cookie Migration Tests:
- Test redirect flow
- Verify cookie copying
- Test parameter validation
- Test signature verification
Cross-Browser Testing:
- Chrome/Edge (Chromium)
- Firefox
- Safari (especially ITP behavior)
- Mobile browsers
Privacy Tool Testing:
- Test with ad blockers enabled
- Test with privacy extensions
- Test with ITP enabled (Safari)
Attribution Testing:
- Verify campaign tracking
- Test conversion attribution
- Validate pixel fires
- Check for data gaps
During Migration Testing:
Monitor Migration Success Rate:
- Track percentage of successful migrations
- Identify failure patterns
- Monitor error rates
Attribution Validation:
- Compare attribution before/after migration
- Identify discrepancies
- Validate conversion tracking
Performance Monitoring:
- Monitor redirect latency
- Check cookie migration time
- Validate server response times
Common Pitfalls and Solutions
Pitfall 1: Cookie Not Migrated
Symptoms:
- User appears as new user on new domain
- Attribution lost
- Session data missing
Solutions:
- Ensure redirect includes user identifier
- Verify signature validation
- Check SameSite policy
- Test in target browsers
Pitfall 2: Duplicate Users
Symptoms:
- Same user appears as two different users
- Attribution split between domains
- Data inconsistencies
Solutions:
- Use shared session storage
- Implement user deduplication logic
- Monitor for duplicate entries
- Use fingerprinting carefully
Pitfall 3: Attribution Gaps
Symptoms:
- Conversions not attributed
- Campaign performance drops
- Missing tracking data
Solutions:
- Extend parallel operation period
- Maintain redirects longer
- Use server-side session storage
- Implement fallback mechanisms
Pitfall 4: Privacy Tool Blocking
Symptoms:
- Migration blocked by ad blockers
- PostMessage blocked
- Redirects blocked
Solutions:
- Use server-side redirects (not client-side)
- Avoid postMessage for critical flows
- Implement fallback mechanisms
- Test with privacy tools enabled
Migration Success Metrics
Key Metrics to Monitor:
Migration Success Rate:
- Percentage of cookies successfully migrated
- Target: >95% migration rate
Attribution Accuracy:
- Conversion attribution maintained
- Campaign performance consistent
- No significant data gaps
User Experience:
- No user-visible errors
- Minimal latency impact
- Seamless transition
Technical Performance:
- Redirect latency <200ms
- Cookie migration time <500ms
- Error rate <1%
Conclusion
Domain migration for trackers requires careful planning and execution. The recommended approach combines:
- HTTP Redirects for immediate migration
- Server-Side Session Storage for data persistence
- Dual-Domain Support during transition
- Gradual Migration to minimize risk
- Extended Parallel Operation for compatibility
By following a phased approach and testing thoroughly, tracker migrations can be executed with minimal data loss and maximum attribution accuracy.
Key Takeaways:
- Cookies cannot be directly shared between unrelated domains
- Redirect-based migration with parameter passing is most reliable
- Server-side session storage provides best data persistence
- Gradual migration minimizes risk
- Extended parallel operation ensures compatibility
- Privacy compliance must be maintained throughout migration
Related Topics
- Redirect Cookie Behavior - How cookies work with HTTP redirects
- Cookie Attributes - Understanding SameSite and Secure
- Cross-Domain Behavior - Cross-domain scenarios
- HTTP Headers - Set-Cookie and Cookie headers
- Privacy and Compliance - Browser privacy features
Additional Resources
- RFC 6265 - HTTP State Management Mechanism - Cookie specification
- MDN Web Docs on HTTP Cookies - Comprehensive cookie documentation
- GDPR Cookie Consent Guidelines - GDPR compliance for cookies
- CCPA Cookie Requirements - CCPA compliance information