OnyxMetric
Integration Guides

PrestaShop

Add OnyxMetric analytics to your PrestaShop store

PrestaShop's back office has no built-in setting for custom <head> code. Add the tag through a header-injection module from the Addons marketplace, or directly in your theme's head.tpl. Clear the cache afterwards either way.

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 PrestaShop

  1. In the back office, go to Modules > Module Manager and install a module that injects custom HTML into the page header, such as a "Custom HTML" or "Header code" module from the PrestaShop Addons marketplace.
  2. Open the module's configuration, paste the snippet into its head code field, and save.
  3. Go to Advanced Parameters > Performance and click Clear cache.

Edit a child theme. Changes to the parent theme are lost on theme updates.

  1. Over SFTP or a file manager, open /themes/your-theme-name/templates/_partials/head.tpl.
  2. Paste the snippet at the end of the file, before the closing </head> tag, and save.
  3. Go to Advanced Parameters > Performance and click Clear cache.

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.js returns 200 and 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

Add this to your theme's order-confirmation.tpl, or output it from a module hooked to the order confirmation page. PrestaShop renders templates with Smarty, which fills in the $order variables:

{if isset($order)}
<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 () {
    window.onyx.event('purchase', {
      transaction_id: '{$order.details.reference}',
      value: {$order.totals.total.amount},
      currency: '{$order.totals.total.currency}'
    });
  }, 5000);
})();
</script>
{/if}

waitForOnyx polls until the tracking script from head.tpl has defined window.onyx, so the event is not lost when the confirmation script runs first.

Troubleshooting

  • Script not on the page: clear the cache under Advanced Parameters > Performance, and temporarily disable any JavaScript combine or minify module.
  • Theme update overwrote the snippet: keep template edits in a child theme.
  • Purchase event missing: the $order Smarty variables differ between PrestaShop versions. Compare them with your version's order-confirmation.tpl and place a test order.

Next steps

On this page