Overview
Cross-domain tracking enables MediaMath to maintain user attribution and retargeting across multiple domains in your conversion funnel. This is critical for:
- Main website to separate checkout domain
- Multiple country-specific domains
- Third-party payment processors
- Partner/affiliate websites
MediaMath Cookie Behavior
MediaMath uses third-party cookies to track users across domains:
- Cookie Name:
mt_mop,mt_misc - Domain:
.mathtag.com(third-party) - Expiration: Configurable in TerminalOne (default 30-90 days)
- Purpose: User identification and frequency capping
First-Party Cookie Alternative
For improved tracking in browsers with third-party cookie restrictions:
// Set first-party cookie with MediaMath user ID
function setMediaMathFirstPartyCookie(userId) {
var expiryDays = 90;
var date = new Date();
date.setTime(date.getTime() + (expiryDays * 24 * 60 * 60 * 1000));
var expires = "expires=" + date.toUTCString();
document.cookie = "mm_user_id=" + userId + ";" + expires + ";path=/;domain=.yourdomain.com;SameSite=Lax";
}
// Get first-party cookie
function getMediaMathFirstPartyCookie() {
var name = "mm_user_id=";
var decodedCookie = decodeURIComponent(document.cookie);
var cookieArray = decodedCookie.split(';');
for (var i = 0; i < cookieArray.length; i++) {
var cookie = cookieArray[i].trim();
if (cookie.indexOf(name) === 0) {
return cookie.substring(name.length, cookie.length);
}
}
return null;
}
Cross-Domain Implementation
Same Pixel Across All Domains
Deploy the same MediaMath universal pixel on all domains:
// Domain A: www.example.com
(function() {
var mtm = document.createElement('script');
mtm.type = 'text/javascript';
mtm.async = true;
mtm.src = 'https://pixel.mathtag.com/event/js?mt_id=ADVERTISER_ID&mt_adid=PIXEL_ID&mt_exem=&mt_excl=&v1=&v2=&v3=&s1=&s2=&s3=';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(mtm, s);
})();
// Domain B: checkout.example.com
// Use the SAME pixel configuration
(function() {
var mtm = document.createElement('script');
mtm.type = 'text/javascript';
mtm.async = true;
mtm.src = 'https://pixel.mathtag.com/event/js?mt_id=ADVERTISER_ID&mt_adid=PIXEL_ID&mt_exem=&mt_excl=&v1=&v2=&v3=&s1=&s2=&s3=';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(mtm, s);
})();
Subdomain Tracking
For subdomains under the same root domain:
Cookie Domain Configuration
// Set cookie domain to share across subdomains
function setSharedCookie(name, value) {
var expiryDays = 90;
var date = new Date();
date.setTime(date.getTime() + (expiryDays * 24 * 60 * 60 * 1000));
var expires = "expires=" + date.toUTCString();
// Note the leading dot for subdomain sharing
document.cookie = name + "=" + value + ";" + expires + ";path=/;domain=.example.com;SameSite=Lax";
}
Subdomain Examples
www.example.com → domain=.example.com
app.example.com → domain=.example.com
checkout.example.com → domain=.example.com
Cross-Domain Parameter Passing
Method 1: URL Parameters
Pass user identifier across domains via URL:
function appendMediaMathId(url) {
var mmUserId = getMediaMathFirstPartyCookie();
if (mmUserId) {
var separator = url.indexOf('?') > -1 ? '&' : '?';
url += separator + 'mm_uid=' + mmUserId;
}
return url;
}
// Apply to cross-domain links
document.addEventListener('DOMContentLoaded', function() {
var crossDomainLinks = document.querySelectorAll('a[href*="checkout.example.com"]');
crossDomainLinks.forEach(function(link) {
link.href = appendMediaMathId(link.href);
});
});
Method 2: Form Field Injection
For forms submitting to another domain:
function injectMediaMathIdIntoForm(formElement) {
var mmUserId = getMediaMathFirstPartyCookie();
if (mmUserId) {
var hiddenField = document.createElement('input');
hiddenField.type = 'hidden';
hiddenField.name = 'mm_uid';
hiddenField.value = mmUserId;
formElement.appendChild(hiddenField);
}
}
// Apply to checkout form
document.addEventListener('DOMContentLoaded', function() {
var checkoutForm = document.getElementById('checkout-form');
if (checkoutForm) {
checkoutForm.addEventListener('submit', function(e) {
injectMediaMathIdIntoForm(checkoutForm);
});
}
});
Server-Side Cross-Domain Tracking
Extract and Forward User ID
// On destination domain, extract mm_uid from URL
function extractMediaMathId() {
var urlParams = new URLSearchParams(window.location.search);
var mmUserId = urlParams.get('mm_uid');
if (mmUserId) {
setMediaMathFirstPartyCookie(mmUserId);
}
}
// Call on page load
extractMediaMathId();
Server-Side Implementation (Node.js)
const express = require('express');
const app = express();
app.get('/checkout', (req, res) => {
const mmUserId = req.query.mm_uid || req.cookies.mm_user_id;
if (mmUserId) {
res.cookie('mm_user_id', mmUserId, {
maxAge: 90 * 24 * 60 * 60 * 1000, // 90 days
domain: '.example.com',
httpOnly: false,
sameSite: 'lax'
});
}
res.render('checkout');
});
Server-Side Implementation (Python)
from flask import Flask, request, make_response
app = Flask(__name__)
@app.route('/checkout')
def checkout():
mm_user_id = request.args.get('mm_uid') or request.cookies.get('mm_user_id')
response = make_response(render_template('checkout.html'))
if mm_user_id:
response.set_cookie(
'mm_user_id',
mm_user_id,
max_age=90 * 24 * 60 * 60, # 90 days
domain='.example.com',
httponly=False,
samesite='Lax'
)
return response
Third-Party Payment Processors
For payment processors like PayPal, Stripe:
Pre-Redirect Tracking
Fire conversion pixel before redirect:
function trackBeforePaymentRedirect(orderData) {
// Fire MediaMath pixel before redirect
var mtm = document.createElement('script');
mtm.type = 'text/javascript';
mtm.async = false; // Synchronous to ensure firing before redirect
var pixelUrl = 'https://pixel.mathtag.com/event/js?' +
'mt_id=' + encodeURIComponent('ADVERTISER_ID') +
'&mt_adid=' + encodeURIComponent('CHECKOUT_PIXEL_ID') +
'&mt_exem=' +
'&mt_excl=' +
'&v1=' + encodeURIComponent(orderData.value) +
'&v2=' + encodeURIComponent(orderData.orderId) +
'&v3=' + encodeURIComponent('checkout_initiated') +
'&s1=&s2=&s3=';
mtm.src = pixelUrl;
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(mtm, s);
// Add small delay before redirect
setTimeout(function() {
window.location.href = orderData.paymentUrl;
}, 500);
}
Post-Return Conversion
Fire final conversion after payment completion:
// On return URL: /order-confirmation?order_id=12345
function trackPaymentReturn() {
var urlParams = new URLSearchParams(window.location.search);
var orderId = urlParams.get('order_id');
if (orderId) {
// Fetch order details from server
fetch('/api/orders/' + orderId)
.then(response => response.json())
.then(order => {
// Fire conversion pixel
fireMediaMathConversionPixel(order);
});
}
}
Multiple Top-Level Domains
For separate TLDs (e.g., example.com, example.co.uk):
Shared User Identification
// Store in localStorage for cross-domain access
function storeMediaMathIdGlobally(userId) {
if (typeof localStorage !== 'undefined') {
localStorage.setItem('mm_global_user_id', userId);
localStorage.setItem('mm_global_timestamp', Date.now());
}
}
// Retrieve and sync
function syncMediaMathIdAcrossDomains() {
if (typeof localStorage !== 'undefined') {
var globalUserId = localStorage.getItem('mm_global_user_id');
var timestamp = localStorage.getItem('mm_global_timestamp');
// Check if ID is recent (within 90 days)
var ninetyDaysAgo = Date.now() - (90 * 24 * 60 * 60 * 1000);
if (globalUserId && timestamp > ninetyDaysAgo) {
setMediaMathFirstPartyCookie(globalUserId);
}
}
}
syncMediaMathIdAcrossDomains();
Testing Cross-Domain Tracking
Verify Cookie Persistence
function testCrossDomainTracking() {
console.log('=== MediaMath Cross-Domain Test ===');
// Check for cookies
var mmCookies = document.cookie.split(';').filter(cookie => {
return cookie.trim().startsWith('mm_') || cookie.trim().indexOf('mt_') > -1;
});
console.log('MediaMath Cookies:', mmCookies);
// Check first-party cookie
var fpCookie = getMediaMathFirstPartyCookie();
console.log('First-Party Cookie:', fpCookie);
// Check localStorage
if (typeof localStorage !== 'undefined') {
console.log('LocalStorage ID:', localStorage.getItem('mm_global_user_id'));
}
console.log('===================================');
}
testCrossDomainTracking();
Browser Developer Tools
- Open Developer Tools
- Go to Application tab
- Check Cookies for both domains
- Verify third-party cookies from
.mathtag.com - Check first-party cookies on your domain
Privacy Considerations
GDPR Compliance
// Only fire pixels with user consent
function fireMediaMathPixelWithConsent(pixelId, data) {
if (window.gdprConsent && window.gdprConsent.advertising) {
fireMediaMathPixel(pixelId, data);
} else {
console.log('MediaMath pixel blocked - no consent');
}
}
Third-Party Cookie Blocking
With Safari ITP and Firefox ETP:
// Detect third-party cookie support
function detectThirdPartyCookieSupport(callback) {
var iframe = document.createElement('iframe');
iframe.style.display = 'none';
iframe.src = 'https://pixel.mathtag.com/cookie-test.html';
iframe.onload = function() {
// Send message to check cookie
iframe.contentWindow.postMessage('test', '*');
};
window.addEventListener('message', function(event) {
if (event.origin === 'https://pixel.mathtag.com') {
callback(event.data.cookieSupported);
}
});
document.body.appendChild(iframe);
}
// Use fallback if third-party cookies blocked
detectThirdPartyCookieSupport(function(supported) {
if (!supported) {
console.log('Third-party cookies blocked - using first-party fallback');
// Implement first-party cookie strategy
}
});
Best Practices
- Deploy same MediaMath pixel ID across all domains for consistent tracking
- Use first-party cookies as fallback for third-party cookie restrictions
- Pass user identifiers via URL parameters for critical cross-domain flows
- Fire pixels before redirects to third-party payment processors
- Test cookie persistence across all domains in your funnel
- Implement consent management before setting cookies
- Document your cross-domain setup and cookie strategy
- Monitor cookie drop rates across different browsers
- Use server-side tracking for critical conversions
- Regularly audit cross-domain tracking after site updates