03.
Phase 2: Tracking Implementation
Critical — This is why their ads aren't optimizing properly.
2.1 Meta ViewContent Event
sections/main-product.liquid — After line 28
{% comment %} Meta Pixel - ViewContent Event {% endcomment %}
<script>
document.addEventListener('DOMContentLoaded', function() {
if (typeof fbq !== 'undefined') {
fbq('track', 'ViewContent', {
content_ids: ['{{ product.id }}'],
content_name: {{ product.title | json }},
content_type: 'product',
content_category: '{{ product.type }}',
value: {{ product.price | divided_by: 100.0 }},
currency: '{{ cart.currency.iso_code }}'
});
}
});
</script>
2.2 Meta AddToCart Event
assets/product-form.js — Inside success callback
// After successful cart add:
if (typeof fbq !== 'undefined') {
fbq('track', 'AddToCart', {
content_ids: [variantId.toString()],
content_name: productTitle,
content_type: 'product',
value: price,
currency: window.Shopify?.currency?.active || 'USD'
});
}
2.3 Klaviyo Events
sections/main-product.liquid
{% comment %} Klaviyo - Viewed Product {% endcomment %}
<script>
document.addEventListener('DOMContentLoaded', function() {
var _learnq = window._learnq || [];
_learnq.push(['track', 'Viewed Product', {
ProductName: {{ product.title | json }},
ProductID: {{ product.id | json }},
SKU: {{ product.selected_or_first_available_variant.sku | json }},
Categories: {{ product.collections | map: 'title' | json }},
ImageURL: '{{ product.featured_image | image_url: width: 1024 }}',
URL: '{{ shop.url }}{{ product.url }}',
Brand: {{ product.vendor | json }},
Price: {{ product.price | divided_by: 100.0 }}
}]);
});
</script>
2.4 Snapchat Pixel
Need from client: Snapchat Pixel ID from their Snapchat Ads account.
layout/theme.liquid — Inside <head>
{% comment %} Snapchat Pixel {% endcomment %}
<script type="text/javascript">
(function(e,t,n){if(e.snaptr)return;var a=e.snaptr=function()
{a.handleRequest?a.handleRequest.apply(a,arguments):a.queue.push(arguments)};
a.queue=[];var s='script';r=t.createElement(s);r.async=!0;
r.src=n;var u=t.getElementsByTagName(s)[0];
u.parentNode.insertBefore(r,u);})(window,document,
'https://sc-static.net/scevent.min.js');
snaptr('init', 'YOUR_SNAP_PIXEL_ID', {
'user_email': '{{ customer.email | default: "" }}'
});
snaptr('track', 'PAGE_VIEW');
</script>