Out of the box, events mentioned in Event Tag - Client side will be tracked. In addition to that, events for View Product, Add to cart and Purchase need to be implemented using Customer Events.
In Shopify admin:
- Go to Settings > Customer events.
- Choose Add custom pixel.
- Give it a name and copy the example below in the Code section.
- Update the INSTANCE_KEY on line 11 to your specific instancekey.
// Capture localization context from init event
var _instanceKey = 'INSTANCE_KEY';
var _marketId = '';
var _webPresenceId = '';
var _languageCode = '';
// bootstrap event tag
(function(w, d, l, i, u) {
w._twa = l;w[l] = w[l] || [];
w[l].push({ 'twa.start': new Date().getTime(), event: 'twa.js' });
w[l].push({ 'twa.instance': i, event: 'twa.init' });
var f = d.getElementsByTagName('script')[0], j = d.createElement('script');
j.async = true;j.src = u;
f.parentNode.insertBefore(j, f);
})(window, document, 'tweakwiseLayer', _instanceKey, "https://navigator-analytics.tweakwise.com/bundles/scout.js");
analytics.subscribe("init", function(event) {
_marketId = event.context?.localization?.market?.id ?? '';
_webPresenceId = event.context?.localization?.market?.custom?.webPresenceId ?? '';
_languageCode = event.context?.localization?.language?.isoCode ?? '';
});
function buildProductKey(variantId) {
return _marketId + '_' + _webPresenceId + '_' + _languageCode + '_' + variantId;
}
analytics.subscribe("item_click", function(event){
if(!tweakwiseLayer) {
console.log('tweakwise - layer not present')
return;
}
console.log('tweakwise - product clicked', event)
tweakwiseLayer.push({
event: 'itemClick',
data: event.customData
});
})
analytics.subscribe("product_viewed", function (event) {
tweakwiseLayer.push({
event: 'productView',
data: {
productKey: buildProductKey(event.data.productVariant.id)
}
});
})
analytics.subscribe("product_added_to_cart", function (event) {
tweakwiseLayer.push({
event: 'addtocart',
data: {
productKey: buildProductKey(event.data.cartLine?.merchandise.id),
quantity: event.data.cartLine?.quantity,
totalAmount: event.data.cartLine?.cost.totalAmount.amount,
}
});
})
analytics.subscribe("checkout_completed", function (event) {
tweakwiseLayer.push({
event: 'purchase',
data: {
productKeys: event.data.checkout.lineItems.map(o => buildProductKey(o.variant.id)),
revenue: event.data?.checkout?.totalPrice?.amount
}
});
});Event Tag adoption
| Feature | Support |
|---|---|
| SessionStart | ✅ |
| PageView | ✅ |
| PageImpression | ✅ |
| ItemClick | ✅ |
| AddToCart | ✅ |
| AddToWishlist | ⚠️ (customization on wishlist plugin) |
| Purchase | ✅ |
| Search | ✅ |
