Smartweb and HostedShop

Tracking on Smartweb, HostedShop and the new Dandomain Webshop – a script in the design and a sale code in the affiliate field.

Time
about 5 min
You need
Access to the shop admin (Design and Settings → Advanced)
View as Markdown

Smartweb, HostedShop and the new Dandomain Webshop are one and the same system, with the same menus and the same variables, so a single guide covers all three. Setup comes down to two snippets in two different places: the tracking code on every page, and the sale code in the affiliate field, which the shop runs on the order confirmation by itself.

These platforms only have a Danish admin, so the menu names below are given in Danish (as you will see them), with an English gloss in brackets.

Before you start

  • Access to the shop admin – both Design and Indstillinger → Avanceret (Settings → Advanced).
  • 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 the platform on its own. If it is not selected, choose Smartweb / HostedShop.

Step 1: The tracking code on every page

Go to Webshop → Design → Handlinger → Indsæt Javascript (Webshop → Design → Actions → Insert JavaScript) and paste the code into the field Hvis koden skal afvikles i starten, når sidens header indlæses (if the code should run at the start, when the page header loads).

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

The code belongs to the active design. If you switch design – even to a copy – check in Setup afterwards that the tracking code is still found.

Step 2: The sale code in the affiliate field

Go to Indstillinger → Avanceret → Affiliate marketing (Settings → Advanced → Affiliate marketing) and paste the code into the Salgs-tracking (sales tracking) field. Pick the site and language at the top of the field (for example "Site 1 Dansk"). The shop runs the code on the order confirmation and fills in the order number, amount and currency wherever there is a %-variable – don't edit the code.

Sale code – only in the affiliate fieldHTML
<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;
    }
    // Admin skriver %OrderId%; den aeldre hjaelpetekst %OrderID%. Den, der virker,
    // bliver erstattet; den anden staar tilbage med %-tegn.
    var id = '%OrderId%';
    if (id.indexOf('%') === 0) id = '%OrderID%';
    // Valutakoden (EUR) - ikke %OrderCurrencyCode%, som er symbolet.
    var val = '%OrderCurrencyISO%';
    // Grundlaget: ordrens varer uden moms, fragt og betalingsgebyr.
    var raw = '%OrderTotalExclVatExclFee%';
    var moms = false;
    // Reserve for aeldre admin uden variablen: totalen uden gebyr inkl. moms / 1,25.
    if (raw.indexOf('%') === 0) { raw = '%OrderTotalInclVatExclFee%'; moms = true; }
    // Staar variablen her endnu, ligger koden i et felt uden ordre (fx alle sider):
    // send intet - ellers bliver hver sidevisning et salg paa 0 kr.
    if (raw.indexOf('%') === 0) {
      console.error('Affilyflow: salgskoden skal i Indstillinger -> Affiliate marketing (koden koeres paa ordrebekraeftelsen).');
      return;
    }
    var total = tal(raw);
    if (moms) total = Math.round((total / 1.25) * 100) / 100;
    if (!(total > 0)) return;
    // Renderer variablerne ikke, staar teksten der stadig. Ordrenummeret maa
    // aldrig sendes raat - saa ville alle ordrer se ens ud for dubletsikringen
    // - og en valuta med %-tegn ville lande i salgsraekken.
    if (id.indexOf('%') === 0) id = '';
    if (val.indexOf('%') === 0) val = '';
    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; }
      affilyflow.conversion({ order: id, total: total, currency: val });
    })();
  })();
</script>

Commission is calculated on %OrderTotalExclVatExclFee%: the goods in the order excluding VAT, shipping and payment fee. If your admin doesn't know that variable (older versions), the code falls back to the total excluding fees divided by 1.25.

If you can't find Affiliate marketing, search for "affiliate" in the settings. The field has the same name on Smartweb, HostedShop and Dandomain Webshop. Dandomain does not offer support for affiliate setup – write to us instead.

Step 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 each code is in its own field – and that the same code isn't in two places. See also Testing and troubleshooting.

Common problems

What you seeCause
Setup can't find the tracking codeThe code isn't in the design that is active, or it is in the wrong one of the three fields.
The console says "salgskoden skal i Indstillinger -> Affiliate marketing"The sale code sits somewhere without an order, such as the design's JavaScript field. Move it to the affiliate field.
The console says "sporingskoden (track.js) mangler paa siden"The tracking code didn't make it onto the order confirmation. Check step 1.
Clicks, but never sales, from certain linksDeep links to /actions/cart/addmulti/ ("open basket") lose ?afid= – they produce clicks but never sales. Link to the product or category page instead.

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

Refunds

The platform doesn't report refunds to us. You need to reject a refunded purchase yourself within the approval period – see Approval and refunds.

Missing something?

Write to us – we answer quickly, and the page gets fixed.

Contact support