How To Implement Outbrain Pixel and Track Conversions in Shopify
If you are using Shopify to host your online business and want to start tracking conversions across your Shopify site, this article will help you install the Outbrain tracking pixel sitewide.
Our best practice is to utilize a custom tracking code, which can be placed directly in your Shopify account. Head to Settings > Customer Events > Custom Pixels and insert the following code:
!function(_window, _document) {
var OB_ADV_ID = 'EXTERNAL_MARKETER_ID';
if (_window.obApi) {
var toArray = function(object) {
return Object.prototype.toString.call(object) === '[object Array]' ? object : [object];
};
_window.obApi.marketerId = toArray(_window.obApi.marketerId).concat(toArray(OB_ADV_ID));
return;
}
var api = _window.obApi = function() {
api.dispatch ? api.dispatch.apply(api, arguments) : api.queue.push(arguments);
};
api.version = '1.1';
api.loaded = true;
api.marketerId = OB_ADV_ID;
api.queue = [];
var tag = _document.createElement('script');
tag.async = true;
tag.src = '//amplify.outbrain.com/cp/obtp.js';
tag.type = 'text/javascript';
var script = _document.getElementsByTagName('script')[0];
script.parentNode.insertBefore(tag, script);
}(window, document);
analytics.subscribe('page_viewed', (event) => {
obApi('track', 'PAGE_VIEW');
});
analytics.subscribe("product_added_to_cart", (event) => {
obApi('track', 'Add to Cart');
});
analytics.subscribe("checkout_started", (event) => {
obApi('track', 'Checkout');
});
analytics.subscribe("checkout_completed", (event) => {
obApi('track', 'Purchase', {
currency: event.data?.checkout?.currencyCode,
orderValue: event.data?.checkout?.totalPrice?.amount,
});
});
PLEASE NOTE:
- When viewing your dashboard, make sure to replace EXTERNAL_MARKETER_ID with the alphanumeric chain that appears in the URL.
- The above code will track Add to Cart, Checkout, and Purchase events.
- Shopify has a standard set of events that can be tracked, allowing users to configure these in the code if they wish. keep in mind that Outbrain has not yet tested those events.
- This code is only relevant for Shopify users who have updated to Checkout Extensibility.
For Reference:
Shopify’s Custom Pixel Guide: https://help.shopify.com/en/manual/promoting-marketing/pixels/custom-pixels/code
Was this article helpful?
YesNo