# Shoporama

> The tracking code in an HTML field and the sale code in the theme's thanks.html – with the amount excluding VAT and shipping.

On Shoporama the tracking code lives in an HTML field, which is added to every page. The sale code, on the other hand, goes in the theme's **thanks.html** – the receipt page – because that is the only place where Shoporama knows the order. Both are done in the Shoporama admin; most stores don't need a developer.

Shoporama's admin is in Danish, so the menu names below are given in Danish (as you will see them), with an English gloss in brackets.

## Before you start

- A user with access to **Webshop → HTML-felter** (HTML fields) and **Design → Kodeeditor** (Code editor).
- 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.
- If you would rather have your developer do it, send them the guide with **Send to developer** in Setup.

## 1. The tracking code in an HTML field

Go to **Webshop → HTML-felter** (Webshop → HTML fields) and create a new field:

1. Give it a name without spaces, for example `affilyflow`.
2. Choose the placement **i slutningen af `<head>`** (at the end of `<head>`).
3. Paste the code and save.

```html title="Tracking code – in an HTML field"
<script src="https://app.affilyflow.com/t/DIN_BUTIK.js" async></script>
```

Shoporama adds the field to every page – including basket, checkout and receipt.

> [!NOTE]
> Shoporama can serve a page from its cache for up to 4 hours. To see the code straight away, open the shop in the browser where you are logged in to the admin, or add `?test=1` to the address.

## 2. The sale code in thanks.html

Open **Design → Kodeeditor** (Design → Code editor) in the Shoporama admin, find the file **thanks.html** (the receipt page) and paste the sale code anywhere in the file. Save. If you use a standard theme, it may need to be copied before the file can be edited – Shoporama tells you in the editor. The code doesn't touch Shoporama's own tracking.

```smarty title="Sale code – only in the theme's thanks.html"
<{if $order}>
<script>
  (function () {
    // Laeser beloebet, uanset om det kommer med valuta eller tusindtalsseparator.
    function tal(v) {
      // '499,-' og '1.249,-' er almindelige i Danmark: et afsluttende ',-' fjernes,
      // og et minus taeller kun forrest.
      var t = String(v).replace(/[^0-9.,-]/g, '').replace(/[.,]?-+$/, '').replace(/(?!^)-/g, '').replace(/^[.,]+|[.,]+$/g, '');
      var k = t.lastIndexOf(','), p = t.lastIndexOf('.');
      if (k > -1 && p > -1) t = k > p ? t.split('.').join('').replace(',', '.') : t.split(',').join('');
      else {
        var sep = k > -1 ? ',' : p > -1 ? '.' : '';
        if (sep && (t.split(sep).length > 2 || t.length - t.lastIndexOf(sep) === 4)) t = t.split(sep).join('');
        else if (sep === ',') t = t.replace(',', '.');
      }
      return Number(t) || 0;
    }
    function num(v) {
      var s = String(v).trim();
      var n = Number(s);
      return s && isFinite(n) ? n : tal(s);
    }
    // |escape:"javascript": en rabatkode (eller et ordrenummer) med et ' maa ikke
    // kunne bryde scriptet (research 21. okt 2026).
    var id = '<{$order->getWebshopOrderId()|escape:"javascript"}>';
    var val = '<{$order->getCurrency()|escape:"javascript"}>';
    var ialt = '<{$order->getTotalPriceExVat()}>';
    var fragt = '<{$order->getShippingPriceExVat()}>';
    // Rabatkoden paa ordren: en PERSONLIG kode tilskriver salget, ogsaa uden klik (0159).
    var kode = '<{$order->getVoucherCode()|escape:"javascript"}>';
    // Staar variablerne her endnu, ligger koden i et HTML-felt: send intet.
    if (ialt.indexOf('$order') !== -1) {
      console.error('Affilyflow: salgskoden skal i temaets thanks.html - i et HTML-felt kender Shoporama ikke ordren.');
      return;
    }
    if (id.indexOf('$order') !== -1) id = '';
    if (val.indexOf('$order') !== -1) val = '';
    // Fragt over totalen betyder, at tallene ikke er i samme enhed: send intet (audit 19. okt, M3).
    if (num(fragt) > num(ialt)) {
      console.error('Affilyflow: fragten er stoerre end ordrens total - kontakt info@affilyflow.com.');
      return;
    }
    var total = Math.round((num(ialt) - num(fragt)) * 100) / 100;
    if (!(total > 0)) return;
    var tries = 0;
    (function send() {
      if (!window.affilyflow) { if (tries++ < 50) setTimeout(send, 200); else console.error('Affilyflow: sporingskoden (track.js) mangler paa siden - salget er ikke registreret.'); return; }
      var o = { order: id, total: total, currency: val };
      if (kode && kode.indexOf('$order') === -1) o.coupon = kode;
      affilyflow.conversion(o);
    })();
  })();
</script>
<{/if}>
```

Shoporama fills in the order number, currency, amount and any discount code itself wherever there is a `<{…}>`. The amount is the order total excluding VAT minus shipping excluding VAT – discounts have already been deducted. Shoporama doesn't document whether a payment fee, if any, is included in the total. The discount code is sent along, so a [personal discount code](https://www.affilyflow.com/en/docs/store/personal-discount-codes) can earn commission, even without a click.

> [!WARNING]
> The sale code must not go in an HTML field. Shoporama doesn't run the variables that provide the order number and amount there, so the code sends nothing. If `<{if $order}>` shows up as text on the page, or the browser console says "salgskoden skal i temaets thanks.html", move the code to thanks.html.

## 3. Test

Go to the **Test tracking** step in Setup, press **Open test link** and place a test order in the tab that opens. Stay in Setup – the live test shows the test click and the purchase with order number 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 the sale doesn't appear, check that the tracking code is in an HTML field and the sale code in thanks.html – not the other way round, and not the same code in two places.

## Common problems

| What you see | Cause |
|---|---|
| Setup can't find the tracking code | The page may be coming from Shoporama's cache – give it a moment. Also check that the field is inserted **at the end of `<head>`**: a field that isn't added automatically doesn't appear on the pages. |
| You can't see **HTML-felter** under Webshop | Your user lacks access. Ask the store owner to grant it or to paste the code in. |
| The console says "fragten er stoerre end ordrens total" | The figures from the theme don't add up (shipping is larger than the order total). Write to info@affilyflow.com. |

The console messages are in Danish – they are written by the snippet above, which is the same for every store.

## Cookie banner

If the shop uses Shoporama's own cookie banner, the tracking code can wait for the customer's consent to marketing. See [Consent and cookies](https://www.affilyflow.com/en/docs/store/consent-and-cookies).

## Refunds

Shoporama doesn't report refunds 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/shoporama
