MediaMath Event Tracking | OpsBlu Docs

MediaMath Event Tracking

How to configure conversion tracking events for MediaMath. Covers pixel event setup, custom parameters, conversion value assignment, audience building.

Conversion Event Types

Purchase Events

Track e-commerce transactions with revenue:

function trackMediaMathPurchase(orderData) {
  var mtm = document.createElement('script');
  mtm.type = 'text/javascript';
  mtm.async = true;

  var pixelUrl = 'https://pixel.mathtag.com/event/js?' +
    'mt_id=' + encodeURIComponent('ADVERTISER_ID') +
    '&mt_adid=' + encodeURIComponent('PURCHASE_PIXEL_ID') +
    '&mt_exem=' +
    '&mt_excl=' +
    '&v1=' + encodeURIComponent(orderData.value) +
    '&v2=' + encodeURIComponent(orderData.orderId) +
    '&v3=' + encodeURIComponent(orderData.currency) +
    '&s1=' +
    '&s2=' +
    '&s3=';

  mtm.src = pixelUrl;
  var s = document.getElementsByTagName('script')[0];
  s.parentNode.insertBefore(mtm, s);
}

// Usage
trackMediaMathPurchase({
  value: '149.99',
  orderId: 'ORDER_12345',
  currency: 'USD'
});

Lead Generation Events

Track form submissions and lead captures:

function trackMediaMathLead(leadData) {
  var mtm = document.createElement('script');
  mtm.type = 'text/javascript';
  mtm.async = true;

  var pixelUrl = 'https://pixel.mathtag.com/event/js?' +
    'mt_id=' + encodeURIComponent('ADVERTISER_ID') +
    '&mt_adid=' + encodeURIComponent('LEAD_PIXEL_ID') +
    '&mt_exem=' +
    '&mt_excl=' +
    '&v1=' + encodeURIComponent(leadData.value) +
    '&v2=' + encodeURIComponent(leadData.type) +
    '&v3=' + encodeURIComponent(leadData.source) +
    '&s1=' +
    '&s2=' +
    '&s3=';

  mtm.src = pixelUrl;
  var s = document.getElementsByTagName('script')[0];
  s.parentNode.insertBefore(mtm, s);
}

// Usage
trackMediaMathLead({
  value: '50.00',
  type: 'contact_form',
  source: 'homepage'
});

Add to Cart Events

Track users adding products to cart:

function trackMediaMathAddToCart(productData) {
  var mtm = document.createElement('script');
  mtm.type = 'text/javascript';
  mtm.async = true;

  var pixelUrl = 'https://pixel.mathtag.com/event/js?' +
    'mt_id=' + encodeURIComponent('ADVERTISER_ID') +
    '&mt_adid=' + encodeURIComponent('ADD_TO_CART_PIXEL_ID') +
    '&mt_exem=' +
    '&mt_excl=' +
    '&v1=' + encodeURIComponent(productData.productId) +
    '&v2=' + encodeURIComponent(productData.price) +
    '&v3=' + encodeURIComponent(productData.category) +
    '&s1=' +
    '&s2=' +
    '&s3=';

  mtm.src = pixelUrl;
  var s = document.getElementsByTagName('script')[0];
  s.parentNode.insertBefore(mtm, s);
}

// Usage
trackMediaMathAddToCart({
  productId: 'SKU_12345',
  price: '49.99',
  category: 'electronics'
});

Audience Pixel Events

Page View Tracking

Create audience segments based on page visits:

function trackMediaMathPageView(pageData) {
  var mtm = document.createElement('script');
  mtm.type = 'text/javascript';
  mtm.async = true;

  var pixelUrl = 'https://pixel.mathtag.com/event/js?' +
    'mt_id=' + encodeURIComponent('ADVERTISER_ID') +
    '&mt_adid=' + encodeURIComponent('AUDIENCE_PIXEL_ID') +
    '&mt_exem=' +
    '&mt_excl=' +
    '&v1=' + encodeURIComponent(pageData.pageType) +
    '&v2=' + encodeURIComponent(pageData.category) +
    '&v3=' +
    '&s1=' +
    '&s2=' +
    '&s3=';

  mtm.src = pixelUrl;
  var s = document.getElementsByTagName('script')[0];
  s.parentNode.insertBefore(mtm, s);
}

// Usage on product pages
trackMediaMathPageView({
  pageType: 'product',
  category: 'widgets'
});

Dynamic Retargeting Events

Track product interactions for dynamic ads:

function trackMediaMathProductView(product) {
  var mtm = document.createElement('script');
  mtm.type = 'text/javascript';
  mtm.async = true;

  var pixelUrl = 'https://pixel.mathtag.com/event/js?' +
    'mt_id=' + encodeURIComponent('ADVERTISER_ID') +
    '&mt_adid=' + encodeURIComponent('DYNAMIC_PIXEL_ID') +
    '&mt_exem=' +
    '&mt_excl=' +
    '&v1=' + encodeURIComponent(product.id) +
    '&v2=' + encodeURIComponent(product.price) +
    '&v3=' + encodeURIComponent(product.category) +
    '&s1=' + encodeURIComponent(product.name) +
    '&s2=' + encodeURIComponent(product.image) +
    '&s3=' + encodeURIComponent(product.url);

  mtm.src = pixelUrl;
  var s = document.getElementsByTagName('script')[0];
  s.parentNode.insertBefore(mtm, s);
}

// Usage
trackMediaMathProductView({
  id: 'SKU_12345',
  name: 'Blue Widget',
  price: '49.99',
  category: 'widgets',
  image: 'https://example.com/images/product.jpg',
  url: 'https://example.com/products/blue-widget'
});

GTM Event Tracking

Purchase Event in GTM

Create a Custom HTML tag triggered by purchase event:

<script type="text/javascript">
  (function() {
    var orderValue = {{DLV - Transaction Value}};
    var orderId = {{DLV - Transaction ID}};
    var currency = {{DLV - Currency}};

    var mtm = document.createElement('script');
    mtm.type = 'text/javascript';
    mtm.async = true;
    mtm.src = 'https://pixel.mathtag.com/event/js?mt_id={{MM Advertiser ID}}&mt_adid={{MM Purchase Pixel ID}}&mt_exem=&mt_excl=&v1=' + orderValue + '&v2=' + orderId + '&v3=' + currency + '&s1=&s2=&s3=';
    var s = document.getElementsByTagName('script')[0];
    s.parentNode.insertBefore(mtm, s);
  })();
</script>

Trigger: Custom Event - purchase

Lead Event in GTM

<script type="text/javascript">
  (function() {
    var formName = {{DLV - Form Name}};
    var leadSource = {{DLV - Lead Source}};

    var mtm = document.createElement('script');
    mtm.type = 'text/javascript';
    mtm.async = true;
    mtm.src = 'https://pixel.mathtag.com/event/js?mt_id={{MM Advertiser ID}}&mt_adid={{MM Lead Pixel ID}}&mt_exem=&mt_excl=&v1=50.00&v2=' + formName + '&v3=' + leadSource + '&s1=&s2=&s3=';
    var s = document.getElementsByTagName('script')[0];
    s.parentNode.insertBefore(mtm, s);
  })();
</script>

Trigger: Form Submission - All Forms

Custom Variable Mapping

Variable 1 (v1) - Transaction Value or Product ID

// For conversions
v1: orderValue  // e.g., "149.99"

// For audience pixels
v1: productId   // e.g., "SKU_12345"

Variable 2 (v2) - Transaction ID or Product Price

// For conversions
v2: orderId     // e.g., "ORDER_12345"

// For audience pixels
v2: productPrice  // e.g., "49.99"

Variable 3 (v3) - Additional Data

// For conversions
v3: currency    // e.g., "USD"

// For audience pixels
v3: category    // e.g., "electronics"

Segment Variables (s1, s2, s3)

For audience segmentation:

s1: productName     // e.g., "Blue Widget"
s2: productImage    // e.g., "https://example.com/image.jpg"
s3: productUrl      // e.g., "https://example.com/product"

Video Event Tracking

Video Start

function trackMediaMathVideoStart(videoData) {
  var mtm = document.createElement('script');
  mtm.type = 'text/javascript';
  mtm.async = true;

  var pixelUrl = 'https://pixel.mathtag.com/event/js?' +
    'mt_id=' + encodeURIComponent('ADVERTISER_ID') +
    '&mt_adid=' + encodeURIComponent('VIDEO_START_PIXEL_ID') +
    '&mt_exem=' +
    '&mt_excl=' +
    '&v1=' + encodeURIComponent(videoData.videoId) +
    '&v2=' + encodeURIComponent(videoData.title) +
    '&v3=' + encodeURIComponent(videoData.duration) +
    '&s1=' +
    '&s2=' +
    '&s3=';

  mtm.src = pixelUrl;
  var s = document.getElementsByTagName('script')[0];
  s.parentNode.insertBefore(mtm, s);
}

Video Complete

function trackMediaMathVideoComplete(videoData) {
  var mtm = document.createElement('script');
  mtm.type = 'text/javascript';
  mtm.async = true;

  var pixelUrl = 'https://pixel.mathtag.com/event/js?' +
    'mt_id=' + encodeURIComponent('ADVERTISER_ID') +
    '&mt_adid=' + encodeURIComponent('VIDEO_COMPLETE_PIXEL_ID') +
    '&mt_exem=' +
    '&mt_excl=' +
    '&v1=' + encodeURIComponent(videoData.videoId) +
    '&v2=' + encodeURIComponent(videoData.watchPercentage) +
    '&v3=' +
    '&s1=' +
    '&s2=' +
    '&s3=';

  mtm.src = pixelUrl;
  var s = document.getElementsByTagName('script')[0];
  s.parentNode.insertBefore(mtm, s);
}

Mobile App Event Tracking

iOS App Events

import UIKit

func trackMediaMathEvent(pixelId: String, parameters: [String: String]) {
    var urlComponents = URLComponents(string: "https://pixel.mathtag.com/event/img")!

    var queryItems: [URLQueryItem] = [
        URLQueryItem(name: "mt_id", value: "ADVERTISER_ID"),
        URLQueryItem(name: "mt_adid", value: pixelId),
        URLQueryItem(name: "mt_exem", value: ""),
        URLQueryItem(name: "mt_excl", value: "")
    ]

    // Add custom parameters
    queryItems.append(URLQueryItem(name: "v1", value: parameters["v1"] ?? ""))
    queryItems.append(URLQueryItem(name: "v2", value: parameters["v2"] ?? ""))
    queryItems.append(URLQueryItem(name: "v3", value: parameters["v3"] ?? ""))

    urlComponents.queryItems = queryItems

    if let url = urlComponents.url {
        URLSession.shared.dataTask(with: url).resume()
    }
}

// Track purchase
trackMediaMathEvent(
    pixelId: "PURCHASE_PIXEL_ID",
    parameters: [
        "v1": "99.99",
        "v2": "ORDER_12345",
        "v3": "USD"
    ]
)

Android App Events

import java.net.URL
import java.net.HttpURLConnection

fun trackMediaMathEvent(pixelId: String, parameters: Map<String, String>) {
    Thread {
        try {
            val urlString = "https://pixel.mathtag.com/event/img?" +
                "mt_id=ADVERTISER_ID" +
                "&mt_adid=$pixelId" +
                "&mt_exem=" +
                "&mt_excl=" +
                "&v1=${parameters["v1"] ?: ""}" +
                "&v2=${parameters["v2"] ?: ""}" +
                "&v3=${parameters["v3"] ?: ""}" +
                "&s1=&s2=&s3="

            val url = URL(urlString)
            val connection = url.openConnection() as HttpURLConnection
            connection.requestMethod = "GET"
            connection.connect()
            connection.disconnect()
        } catch (e: Exception) {
            e.printStackTrace()
        }
    }.start()
}

// Track purchase
trackMediaMathEvent(
    pixelId = "PURCHASE_PIXEL_ID",
    parameters = mapOf(
        "v1" to "99.99",
        "v2" to "ORDER_12345",
        "v3" to "USD"
    )
)

Testing & Validation

Browser Console Testing

// Test pixel firing
function testMediaMathPixel() {
  console.log('Testing MediaMath pixel...');

  trackMediaMathPurchase({
    value: '99.99',
    orderId: 'TEST_ORDER_' + Date.now(),
    currency: 'USD'
  });

  console.log('Pixel fired - check Network tab');
}

// Run test
testMediaMathPixel();

Network Tab Verification

  1. Open browser Developer Tools
  2. Go to Network tab
  3. Filter by "mathtag"
  4. Trigger conversion event
  5. Verify pixel request with correct parameters

Best Practices

  • Always use unique transaction IDs to prevent duplicate conversions
  • Encode URL parameters to handle special characters
  • Implement consent management before firing pixels
  • Use server-side pixels for critical conversions
  • Test pixels in staging environment before production
  • Document pixel IDs and variable mappings
  • Monitor pixel performance in TerminalOne dashboard
  • Implement error handling for failed pixel fires
  • Use GTM for centralized pixel management
  • Keep pixel code asynchronous to avoid blocking page load