Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
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).
<script type="text/javascript">
(function() {
var order = window.Shopify.order;
var currency = order.currency;
// Total value of the order
var orderValue = order.totalPrice;
var contents = order.lineItems.map(function(item) {
return {
content_type: 'product',
content_id: item.id,
content_name: item.title,
content_price: item.price, // Price in the currency of the shop
quantity: item.quantity
};
});
// Trigger the Twitter Pixel event
twq('event', '[event-name-redacted]', {
value: orderValue,
currency: currency,
contents: contents,
conversion_id: order.number,
email_address: order.customer.email,
phone_number: order.customer.phone
});
})();
</script>
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
Hey Community! As the holiday season unfolds, we want to extend heartfelt thanks to a...
By JasonH Dec 6, 2024Dropshipping, a high-growth, $226 billion-dollar industry, remains a highly dynamic bus...
By JasonH Nov 27, 2024Hey Community! It’s time to share some appreciation and celebrate what we have accomplis...
By JasonH Nov 14, 2024