Stickybeak Docs Dashboard Get early access

Backends

PrestaShop

PrestaShop 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 PrestaShop, with live visitors, goals and revenue attribution in one script.

Add the script

  1. Add the module file

    Copy your site ID from Settings in the dashboard and put it in SITE_ID:

    <?php
    if (!defined('_PS_VERSION_')) {
        exit;
    }
    
    class Stickybeak extends Module
    {
        const SITE_ID = 'YOUR_SITE_ID';
        const DOMAIN = 'example.com';
    
        public function __construct()
        {
            $this->name = 'stickybeak';
            $this->tab = 'analytics_stats';
            $this->version = '1.0.0';
            $this->author = 'Your name';
            $this->ps_versions_compliancy = ['min' => '8.0.0', 'max' => _PS_VERSION_];
            parent::__construct();
            $this->displayName = 'Stickybeak';
            $this->description = 'Adds the Stickybeak analytics tag.';
        }
    
        public function install()
        {
            return parent::install()
                && $this->registerHook('displayHeader')
                && $this->registerHook('displayOrderConfirmation');
        }
    
        public function hookDisplayHeader()
        {
            $queue = '<script>window.stickybeak = window.stickybeak || function () { (window.stickybeak.q = window.stickybeak.q || []).push(arguments); };</script>';
            if (_PS_MODE_DEV_) {
                return $queue; // no tracking while debug mode is on
            }
            return $queue . sprintf(
                '<script defer data-site="%s" data-domain="%s" src="https://app.usestickybeak.com/_cfw/s.js"></script>',
                self::SITE_ID,
                self::DOMAIN
            );
        }
    
        public function hookDisplayOrderConfirmation($params)
        {
            $order = $params['order'];
            $currency = new Currency((int) $order->id_currency);
            $props = [
                'revenue'  => (float) $order->total_paid,
                'currency' => $currency->iso_code,
                'order_id' => $order->reference,
            ];
            $json = json_encode($props, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT);
            return '<script>window.stickybeak("purchase", ' . $json . ');</script>';
        }
    }
  2. Install it

    Zip the stickybeak folder and upload it under Modules → Module Manager → Upload a module, or copy the folder to modules/ on the server and click Install next to it.

  3. Clear the cache

    Under Advanced Parameters → Performance, click Clear cache. Then open your shop and you should appear on the wall within a few seconds.

The tag isn't added while debug mode is on, so a development copy stays out of your numbers.

Check it's working

Install the module on production, clear Advanced Parameters → Performance → Clear cache, then check in a private window. Follow Verify your install for the full check.

Track goals

Add data-goal to links and buttons in your theme's templates, such as the add-to-cart button in templates/catalog/_partials/product-add-to-cart.tpl.

<button class="btn btn-primary add-to-cart" data-button-action="add-to-cart" type="submit" data-goal="add_to_cart">

See Custom goals.

Track purchases

The displayOrderConfirmation hook runs on the page customers see after placing an order, and gets the order itself.

Want revenue before tax and shipping instead? Use $order->total_products in place of total_paid.

See Revenue.

If it isn't working

  • Debug mode omits the tag. Install the module only on production if staging runs without debug mode.

See Troubleshooting.