# PrestaShop

> Tracking on PrestaShop via Google Analytics 4 – the tracking code in the theme and the official ps_googleanalytics module. No module from us yet.

PrestaShop is tracked via the [Google Analytics route](https://www.affilyflow.com/en/docs/reference/google-analytics): the tracking code sits on every page, and PrestaShop's official Google Analytics module sends the purchase to Google Analytics 4 from the order confirmation – with order ID, amount, tax and shipping. The tracking code reads that, and we calculate commission on the goods excluding VAT and shipping.

> [!NOTE]
> We don't have a PrestaShop module yet. This guide requires the store to have Google Analytics 4 switched on – and Google Analytics sends nothing when the customer declines statistics cookies, so that purchase is lost. The guide is written from PrestaShop's documentation and the module's source code and has not yet been verified on a real PrestaShop store: run a test purchase before you rely on it.

## Before you start

- Access to the theme (or a "custom code" module) and to **Modules**.
- The snippets from **Program → Setup** in Affilyflow, where your store ID is already filled in. In this guide, `DIN_BUTIK` stands for your store ID.
- Setup usually recognises PrestaShop on its own. If it is not selected, choose **PrestaShop** under *Other systems*.

## 1. The tracking code on every page

PrestaShop has no field for head code in the admin itself. There are two routes:

- **A custom code module** from Addons that adds code to the head on every page. The easiest route without a developer.
- **The theme:** add the code to the head template (in the Classic theme, `templates/_partials/head.tpl`) or register the script under `assets` in the theme's `theme.yml`. Theme changes can be overwritten by a theme update – a child theme holds up better.

```html title="Tracking code – goes on every page"
<script src="https://app.affilyflow.com/t/DIN_BUTIK.js" async></script>
```

After every theme update, check in Setup that the tracking code is still found. If you don't have access to the theme, send the guide to your developer with **Send to developer** in Setup.

## 2. Switch on Google Analytics 4

Install and enable PrestaShop's official **Google Analytics** module (`ps_googleanalytics`) under **Modules → Module Catalog**, and enter your **Measurement ID** (G-…). The module sends `purchase` to Google Analytics 4 from the order confirmation with `transaction_id`, `value`, `tax`, `shipping` and `currency`. Another GA4 module works too, as long as it sends the `purchase` event.

**How we calculate:** PrestaShop sends shipping *including* VAT, and `tax` as all of the VAT. The base is therefore `value − shipping` (the goods including VAT) multiplied by `(value − tax) / value` – the goods excluding VAT and shipping, after discount. Setup stores this rule on the store when you choose PrestaShop – there is nothing for you to configure.

> [!NOTE]
> **The order number:** PrestaShop's module sends the order's internal ID (`id_order`) – the number in the **ID** column under *Orders* – not the reference (e.g. `XKBKNABJK`) that appears in emails and in the order detail. That is the number you see on the sale with us. Search for the ID under *Orders* when you need to find a sale.

Without consent to statistics cookies, Google Analytics sends nothing, and we can't see that purchase.

### For developers: without Google Analytics

If you don't want to use Google Analytics, a developer can add the [sale line](https://www.affilyflow.com/en/docs/reference/sale-line) to the theme's `order-confirmation.tpl`. Here the order number is the reference, as you know it. The amount is the total minus shipping (variables from the Classic theme's order presenter), and `data-affilyflow-vat` removes the VAT – 25 is the Danish rate, change it to yours.

```html title="order-confirmation.tpl · order confirmation only"
<div hidden data-affilyflow-order="{$order.details.reference}" data-affilyflow-total="{$order.totals.total.amount - $order.subtotals.shipping.amount}" data-affilyflow-vat="25" data-affilyflow-currency="{$currency.iso_code}"></div>
```

The variable names have not been verified on a real store – check the amount in the live test. Use one route only: the line *or* Google Analytics – otherwise the same purchase can be reported twice, each time with a different order number (reference and ID).

## 3. Test

Go to the **Test tracking** step in Setup, press **Open test link** and place a test order in the tab that opens – accept statistics cookies in the banner. Stay in Setup – the live test shows the test click and the purchase with order ID and amount, and asks whether the amount is right. A test purchase gives no commission and no fee. A purchase without a click from a link is not counted.

If you take payment with a redirect (MobilePay, Quickpay …), check that the customer lands on the order confirmation afterwards – if the customer never comes back to `order-confirmation`, the purchase isn't sent. See also [Testing and troubleshooting](https://www.affilyflow.com/en/docs/store/testing-and-troubleshooting).

## Common problems

| What you see | Cause |
|---|---|
| Setup can't find the tracking code | The theme has been updated, and the change in the head is gone. Use a child theme or a custom code module. |
| Clicks, but never sales | Google Analytics 4 isn't switched on, the customer declined statistics cookies, or the customer never landed on the order confirmation after paying. |
| You can't find the sale in the admin | We show `id_order`, not the reference. Search for the ID under *Orders*. |

## Refunds

PrestaShop doesn't report refunds or credit slips to us. You need to reject a refunded purchase yourself within the approval period – see [Approval and refunds](https://www.affilyflow.com/en/docs/store/approval-and-refunds).

Source: https://www.affilyflow.com/en/docs/store/prestashop
