Stickybeak Docs Dashboard Get early access

Backends

OpenCart

OpenCart analytics with Stickybeak starts by adding its script to your rendered pages; this guide shows you where it belongs and how to track page views, goals and purchase revenue. It is a lighter alternative to Google Analytics for OpenCart, with live visitors, goals and revenue attribution in one script.

Core files

These are edits to OpenCart's own files, so an upgrade will overwrite them.

Add the script

  1. Add OpenCart conversion tracking

    Copy your snippet from Settings in the dashboard and paste it, with the queue line above it, before </head>:

    <script>window.stickybeak = window.stickybeak || function () { (window.stickybeak.q = window.stickybeak.q || []).push(arguments); };</script>
    <script
      defer
      data-site="YOUR_SITE_ID"
      data-domain="example.com"
      src="https://app.usestickybeak.com/_cfw/s.js"
    ></script>

    OpenCart 3 keeps the same file under catalog/view/theme/default/template/common/header.twig; if you use another theme, edit that theme's copy.

  2. Refresh the theme cache

    In the admin dashboard, click the gear icon (Developer Settings) and refresh the theme cache.

Check it's working

Publish and refresh the theme cache from Developer Settings before checking the storefront. Follow Verify your install for the full check.

Track goals

Add data-goal to buttons and links in your theme's templates, like the add-to-cart button on the product page. See Custom goals.

Track purchases

The success page controller clears the order from the session as soon as it runs.

$this->load->model('checkout/order');
$order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);

if ($order_info) {
    $data['stickybeak_purchase'] = json_encode([
        'revenue'  => $this->currency->format($order_info['total'], $order_info['currency_code'], $order_info['currency_value'], false),
        'currency' => $order_info['currency_code'],
        'order_id' => (string) $order_info['order_id'],
    ], JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT);
}

Then add the call to the template the success page renders (common/success.twig, which other "success" pages share; they won't have the variable, so nothing happens there):

{% if stickybeak_purchase %}
  <script>window.stickybeak("purchase", {{ stickybeak_purchase|raw }});</script>
{% endif %}

See Revenue.

If it isn't working

  • Core-file edits are overwritten by upgrades; keep an OCMOD or reapply them. Refresh the theme cache.

See Troubleshooting.