Installing 1st party tracking (v2) via custom pixel in Shopify

1. Add new pixel

Go to your Shopify Store Settings / Custom Events and click the Add custom pixel button.

Enter the Pixel name and click the Add pixel button.

2. Enter pixel code

Copy and paste the below code. Please don’t forget to replace the OFFER_SID value twice with your offer sID. You can find it in the Offer list of the marketplace or ask your account manager.

analytics.subscribe('page_viewed', async (event) => {
  const offerSID = 'OFFER_SID';
  const searchParams = new URLSearchParams(event.context.document.location.search);
  // Cookie expires after one year
  const expires = new Date();
  expires.setTime(expires.getTime() + 1000*60*60*24*365);
  const domain = event.context.document.location.hostname;
  const secure = (event.context.document.location.protocol === 'https:') ? 'secure;' : '';

  // Handle tmt_data query parameter
  if ( searchParams.has('tmt_data')) {
    const tmtData  = searchParams.get('tmt_data');
    if ( tmtData ) {
      browser.cookie.set(`tc_${offerSID}=${tmtData};expires=${expires.toUTCString()};path=/;domain=${domain};samesite=lax;${secure}`);
    }
  }

  // Handle tmt_ufp query parameter
  if ( searchParams.has('tmt_ufp')) {
    const tmtUFP  = searchParams.get('tmt_ufp');
    if ( tmtUFP ) {
      browser.cookie.set(`tc_ufp=${tmtUFP};expires=${expires.toUTCString()};path=/;domain=${domain};samesite=lax;${secure}`);
    }
  }
});

// Checkout
analytics.subscribe('checkout_completed', async (event) => {
  const offerSID = 'OFFER_SID';
  const tmtData = await browser.cookie.get('tc_' + offerSID);
  const tmtUFP  = await browser.cookie.get('tc_ufp');

  const checkout = event.data.checkout;

  // Transaction Amount Adjustments
  let transactionAmount = checkout.totalPrice?.amount;
  transactionAmount -= checkout.shippingLine?.price.amount;
  transactionAmount -= checkout.totalTax.amount;

  const payload = {
    campaignID:         offerSID,
    transactionID:      checkout.order?.id,
    transactionAmount:  transactionAmount.toFixed(2),
    currency:           checkout.currencyCode,
    conversionType:     'sale',
    tmtData:            tmtData,
    ufp:                tmtUFP,
    method:             'tmt_cookie',
  };

  //Handle discount codes
  let allDiscountCodes = checkout.discountApplications.map((discount) => {
    if (discount.type === 'DISCOUNT_CODE') {
      return discount.title;
    }
  });
  allDiscountCodes = allDiscountCodes.join(",");

  if ( allDiscountCodes ) {
    payload.code = allDiscountCodes;
  }

  const params = new URLSearchParams(payload);
  // Call our tracking endpoint
  fetch('https://p.trackmytarget.com/?' + params.toString());
});

3. Set pixel permissions

After entering your pixel code make sure to check all permissions under the Required section.

4. Save an Connect your pixel

Click the Save button
and then the Connect one. That’s it.

Boost your affiliate program

Download our free whitepaper for insights into 2020’s top affiliate marketing trend: self-service affiliate programs

© 2025 Target Circle AS | Terms & Privacy | Cookie preferences | Email

Learn the 2020’s Top Affiliate Marketing Trends