BigCommerce
Add OnyxMetric analytics to your BigCommerce store
BigCommerce's Script Manager adds scripts to every storefront page without theme edits. It is also where the order-confirmation purchase event goes. Editing the theme's head.html works too.
Copy your tracking snippet
In OnyxMetric, open your site's Site Settings and copy the tracking script. It looks like this:
<script src="https://app.onyxmetric.com/api/script.js?siteId=YOUR_SITE_ID" async></script>YOUR_SITE_ID is the numeric ID of your site.
Add the snippet to BigCommerce
- In the control panel, go to Storefront > Script Manager and click Create a Script.
- Fill in the settings:
- Name: OnyxMetric Analytics
- Placement: Head
- Location: All pages
- Script category: Analytics
- Script type: Script
- Paste the snippet into Script contents and click Save.
Back up your theme before editing files.
- Go to Storefront > Themes, click Advanced on your current theme, then Edit Theme Files.
- Open templates > components > common > head.html.
- Paste the snippet at the end, before the closing
</head>tag, and click Save.
Check that it works
Load your live site and click through a few pages. Pageviews show up in the OnyxMetric dashboard within seconds.
If nothing arrives:
- View the page source and search for
script.js?siteId=to confirm the tag is present. - In the browser's Network tab, check that
script.jsreturns200and that requests go to/api/track. - Turn off ad blockers, or proxy the script through your own domain.
- Read script troubleshooting for other causes.
Track purchases
Create a second script in Script Manager with Placement: Footer, Location: Order Confirmation, and Script type: Script. BigCommerce runs Script Manager contents through Handlebars, so expressions such as checkout.order.id are filled in with real order data:
<script>
(function () {
function waitForOnyx(callback, timeout) {
var start = Date.now();
(function check() {
if (window.onyx && typeof window.onyx.event === 'function') {
callback();
} else if (Date.now() - start < timeout) {
setTimeout(check, 100);
}
})();
}
waitForOnyx(function () {
{{#if checkout.order}}
window.onyx.event('purchase', {
transaction_id: '{{checkout.order.id}}',
value: {{checkout.subtotal.value}},
currency: '{{checkout.currency.code}}'
});
{{/if}}
}, 5000);
})();
</script>waitForOnyx polls until the tracking script from the head has defined window.onyx, so the event is not lost if the confirmation page runs the footer script first.
Troubleshooting
- Script not on the page: confirm it is enabled in Script Manager, then purge the cache under Server Settings > Store-level caching > Purge cache.
- Purchase event missing: the script must use the Order Confirmation location. The
checkout.order,checkout.subtotal, andcheckout.currencyobjects depend on your checkout version, so place a test order to confirm the event arrives.
Next steps
- Track custom events such as signups, purchases, and clicks.
- Identify users to tie sessions to accounts.
- Proxy the script through your own domain to get past ad blockers.
- Script attributes let you skip or mask URLs and tag events.