How can I effectively track purchase events with Twitter Pixel?

Hello. I’m trying to get a post-purchase pixel working to track purchase events using the Twitter Pixel. I’ve added the following script to the post-purchase script section in Shopify (we have not upgraded to checkout extensibility).


Am I approaching this the right way? I know there is a customer events section in Shopify for custom pixels, but I have not dove into that.

In addition, I’ve attempted to add the pixel tracking via Shopify’s custom pixels, and it works for my add to cart event, but not my purchase events.

// Step 1. Initialize the JavaScript pixel SDK (make sure to exclude HTML)
!function(e,t,n,s,u,a){e.twq||(s=e.twq=function(){s.exe?s.exe.apply(s,arguments):s.queue.push(arguments);
},s.version='1.1',s.queue=[]);var f=t.createElement(n),h=t.getElementsByTagName(n)[0];
f.async=!0,f.src='https://static.ads-twitter.com/uwt.js',h.parentNode.insertBefore(f,h)}(window,document,'script');
twq('init','[base-pixel-redacted]'); // Initialize Twitter Pixel with your base pixel ID

// Step 2. Subscribe to customer events with analytics.subscribe(), and add tracking
// Track Cart Additions
analytics.subscribe("cart_addition", event => {
  twq('track','[cart-id-redacted]', { 
    content_ids: event.data.product_ids,
    content_type: 'product',
    value: event.data.total_price,
    currency: 'USD'
  });
});

// Track Purchases
analytics.subscribe("checkout_completed", event => {
  twq('track','[purchase-id-redacted]', { 
    value: event.data.checkout.totalPrice.amount, 
    currency: event.data.checkout.currencyCode,
    email_address: event.data.checkout.email 
  });
});

Hello!
Did you find the solution? I have the same issue!
Thanks a lot,

Letty

Have you had any luck? Suck as well

I have the same issue, I contacted shopify team and nobody tell us how to fire the X pixel. This request have 2,041 Views, and still no help from Shopify…

@Rafael_Miranda @ajsmith227 @Letty12345 @maxrfinch

To track purchase for twitter pixel Google tag manager GTM would be the most suitable solution that you can follow.

But before that you would need to configure a custom pixel datalayer in customer events.

Once you configure the datalayer follow these steps:

  1. Create the triggers to track the events
  2. Create datalayer to pass event parameter like value, currency and transaction ID
  3. import Twitter template and create tag for each event you want to track.

Thank you

Use Shopify custom pixels and trigger the Twitter Pixel purchase event when the checkout_completed event fires. Subscribe to the event and send order data (value, currency, product IDs) to Twitter:

analytics.subscribe("checkout_completed", (event) => {
  twq('track', 'Purchase', {
    value: event.data.checkout.totalPrice.amount,
    currency: event.data.checkout.currencyCode,
    contents: event.data.checkout.lineItems.map(i => ({
      content_id: i.variant.product.id,
      content_price: i.variant.price.amount,
      quantity: i.quantity
    }))
  });
});

If tracking still fails, consider using a consent and data orchestration platform like Ketch to manage event collection and ensure reliable firing of purchase events across pixels.