Custom-built store

Set up tracking on a store that was built for you, e.g. in Laravel or PHP – without knowing any field names.

Time
5–30 min
You need
Your website saved; access to the layout and the order confirmation page (or a developer)
View as Markdown

If your store was developed for you – in Laravel, Symfony or any other framework – tracking needs two things: a script on every page and a way to report the sale. You can often report the sale without touching the order confirmation page at all, because your site already sends the purchase to Google Analytics. If it doesn't, it takes a single line of HTML.

Before you start

  • Open Program → Setup and choose Custom-built store under Where do you sell?.
  • Enter your website in the first field of the install step and save it – the scan and the test link both use it.
  • The snippets in Setup have your store ID filled in. In this guide, DIN_BUTIK stands for your store ID.

The amount commission is calculated on

Commission is calculated on the goods after discounts, excluding VAT and shipping. Fees are not included either. That is the amount to report the sale with – whichever route you choose below.

Step 1: The script on every page

Add the script to <head> in your shared layout so it is on every page – including the order confirmation. It remembers the affiliate click when the customer lands, so a later purchase can be credited.

<head> · every pageHTML
<script src="https://app.affilyflow.com/t/DIN_BUTIK.js" async></script>

The script is loaded with async, so it never holds the page back. What it stores, and when, is described in track.js.

Step 2: Start with "Scan your site"

Press Scan your site under Find the sale automatically. We fetch your front page and a product page (at most three pages, possibly via a category page) and look for two things:

  • Google Analytics 4 ecommerce – events such as view_item, add_to_cart or begin_checkout with items, sent through dataLayer or gtag.
  • Google Tag Manager or a GA4 tag without any visible purchase data.

If we find ecommerce data, we also measure whether the amounts in Google Analytics include VAT: we compare the price in view_item with the price the product page itself shows. If that can't be measured, your country's standard VAT rate is used.

The scan also looks for a cookie banner. If the site uses Cookiebot, Cookie Information or one of the built-in banners the script can read (DanDomain Classic, Smartweb), Cookie banner is set to Wait for consent: the script gets data-consent="required" and only stores the click once the customer has accepted marketing cookies. You can change the setting in Setup at any time. See Consent and cookies.

ResultWhat it means
Found: your site sends purchase data to Google AnalyticsSetup switches to Automatically from Google Analytics. See route A.
Google Tag Manager found – but no purchase data visibleIf your developer knows that Tag Manager sends the purchase to GA4, you can choose route A. Otherwise route B.
No Google Analytics purchase data foundUse the line on the order confirmation page – route B.
The site refused the scanFor example because of bot protection. Use route B, or choose route A if you know the site sends the purchase to GA4.

Under Settings → How the sale is reported you can always switch between Automatically from Google Analytics and Line on the order confirmation page. To skip the scan, press Show it next to Rather add a line to the order confirmation page yourself?.

Route A: Automatically from Google Analytics

If your order confirmation page already sends a GA4 purchase event, the script can read the purchase itself. No code goes on the confirmation page, and nobody needs to know the template's field names. Choose Automatically from Google Analytics in Setup. The script from step 1 stays exactly as it is: the settings are saved in Setup, and our server adds them to the script. A change reaches your site within a few minutes.

  • VAT in the amount: Includes VAT (25%) deducts the VAT. If the amounts in Google Analytics are without VAT, choose Excludes VAT.
  • Shipping in the amount: Includes shipping or Excludes shipping tells us whether shipping is part of the Google Analytics amount. With Detect, the script works it out: if value is larger than the item lines, shipping is assumed to be included and is deducted.

The script reads the event in both forms:

What the script reads on the confirmation pageJavaScript
dataLayer.push({ event: 'purchase', ecommerce: { transaction_id: 'A-1008', value: 724.00, shipping: 49.00, currency: 'DKK', items: [ /* ... */ ] } });
// eller
gtag('event', 'purchase', { transaction_id: 'A-1008', value: 724.00, shipping: 49.00, currency: 'DKK', items: [ /* ... */ ] });

The order number is transaction_id, and the amount is value – minus shipping when it is included – divided by the VAT. The script watches dataLayer for 60 seconds, so an event that fires after the page has loaded is picked up too.

More about this route in Google Analytics.

Route B: The line on the order confirmation page

If the site doesn't send the purchase to Google Analytics, add one line of HTML anywhere in <body> on the order confirmation page – the page the customer sees after a completed purchase:

Confirmation page · anywhere in <body>HTML
<div hidden data-affilyflow-order="DIN_ORDRE_ID" data-affilyflow-total="DIT_BELOEB"></div>

Replace DIN_ORDRE_ID with your variable for the order number and DIT_BELOEB with the value of the goods after discounts, excluding VAT and shipping. There is no JavaScript to write: the script finds the line and reports the sale. The script from step 1 must be on the confirmation page as well.

This is how it looks in the most common template languages. The field names are examples – use the ones your system has on the confirmation page:

Laravel (Blade)Blade
<div hidden data-affilyflow-order="{{ $order->id }}" data-affilyflow-total="{{ $order->subtotal }}"></div>
PHPPHP
<div hidden data-affilyflow-order="<?= $order->id ?>" data-affilyflow-total="<?= $order->subtotal ?>"></div>
TwigTwig
<div hidden data-affilyflow-order="{{ order.id }}" data-affilyflow-total="{{ order.subtotal }}"></div>
LiquidLiquid
<div hidden data-affilyflow-order="{{ order.id }}" data-affilyflow-total="{{ order.subtotal }}"></div>
SmartySmarty
<div hidden data-affilyflow-order="{$order.id}" data-affilyflow-total="{$order.subtotal}"></div>

What else the line can do

AttributeEffect
data-affilyflow-vat="25"The amount includes 25% VAT, which is deducted.
data-affilyflow-currency="EUR"The currency, when you sell in a currency other than your settlement currency. Without it, the store's settlement currency is used.
data-affilyflow-order="?orderId"Reads the order number from the orderId parameter in the page URL.
data-affilyflow-total="#af-total"Reads the amount from the text of the element with the ID af-total.
data-affilyflow-coupon="KODE"The customer's discount code(s), separated by commas. A personal code earns the affiliate commission, even without a click.

Amounts such as 1249.50 and 1.249,50 both work. If your page renders the confirmation after loading (e.g. Livewire or React), the script still finds the line: it watches the page for 60 seconds, and once the line is there, it waits up to 20 seconds for the order number and amount to be filled in. Each line is reported only once.

All the details are in The sale line.

Don't know the field names?

Your code does. Under Let your AI coding assistant set it up in Setup you'll find a ready-made prompt. Paste it into Claude Code, Cursor, Copilot or ChatGPT inside your project – the assistant can see the code, find the confirmation page and the right fields, and add the line. In the English dashboard the prompt looks like this (with your address and store ID):

Prompt for the AI coding assistantTekst
Set up Affilyflow affiliate tracking in this project (yourshop.com).

1. Add this script to <head> in the shared layout so it is on every page:
<script src="https://app.affilyflow.com/t/DIN_BUTIK.js" async></script>

2. Find the view the customer sees after a completed purchase (the order confirmation/receipt) and the variables available there. Add this anywhere in <body> on that page:
<div hidden data-affilyflow-order="ORDER_NUMBER" data-affilyflow-total="AMOUNT"></div>
   - ORDER_NUMBER = the order number as the customer sees it.
   - AMOUNT = the goods after discounts, EXCLUDING VAT and EXCLUDING shipping and fees, with a dot as decimal separator (e.g. 540.00). If only an amount including VAT is available, divide it by 1.25 (25% VAT).
   - If the order has discount codes, also add data-affilyflow-coupon="CODE" (several separated by commas). A personal code the store has given an affiliate earns commission even without a click.
   - Use the template language’s normal (escaped) output. Don’t invent field names – find them in the order model, controller or view.
   - Don’t change checkout or any files other than the layout and the confirmation view.

3. Finally, tell me which files you changed and which variables you used for the order number, amount and discount codes.

4. Then ask me whether the click and the sale should also be stored from the server (recommended: then iPhone, Safari and ad blockers no longer matter). Only do it if I say yes, and follow https://www.affilyflow.com/en/docs/store/server-side-tracking.md

The test happens afterwards in Affilyflow: Setup → Open test link → place a test order. The page shows the order number and amount that came through.

If you know the field names yourselves, open Know the field names yourselves? and enter the variables for the order number and the amount – the line is built with them. The buttons under the fields show the syntax in Blade, PHP, Twig, Liquid and Smarty.

If a developer or an agency is doing the work, press Send to developer. We email them the guide with the script, the line, the prompt and the test step.

Step 3: Test tracking

  1. Go to the Test tracking step, press Open test link and place a test order in the tab that opens – in the same browser.
  2. Stay on Setup. The live test shows the test click and then the purchase with order number and amount. It follows along for up to 10 minutes.
  3. Answer the question: Is this the value of the goods after discounts, excluding VAT and shipping, on your test order? If you answer no, enter the correct amount, and the live test tells you what's wrong – for example that the amount includes VAT or shipping.

On route A the live test also shows the calculation, e.g. "Calculated as: DKK 724.00 from Google Analytics − DKK 49.00 shipping ÷ 1.25 (VAT 25%) = DKK 540.00". If the amount includes VAT or shipping, you can fix it with one click (Deduct VAT or Deduct shipping). The fix applies from the next sale, without changing the script – make a new test purchase to see it.

A test purchase earns no commission, carries no fee and doesn't count in your figures. Cancel the order in your shop afterwards.

Common errors

Errors from the line or the script appear in the browser console on the confirmation page:

The console saysCause
data-affilyflow-order must be the order numberThe order number is empty or still shows the placeholder.
data-affilyflow-total must be the amount (goods excl. VAT and shipping)The amount is empty or 0.
the purchase event has no amountThe GA4 purchase event had no amount.

If no sale comes through at all, check that the script is also on the confirmation page and that the test purchase was made in the same browser as the test link. More in Testing and troubleshooting.

Tracking from your server

The script stores the click in the browser, where Safari and iPhone delete it after about 7 days without a visit. An ad blocker can also stop the script. If you have a developer, your own server can store the click and report the sale instead – then tracking holds for the whole period. The script and the line can stay in place as a fallback; the same order only counts once. The snippets for Laravel, PHP, Node.js and Next.js are in Setup under For developers: even more precise tracking, with your store ID filled in. The full guide is in Server-side tracking.

Personal discount codes

A discount code you link to a specific affiliate earns that affiliate commission – even when the customer hasn't clicked a link, for example because they declined cookies. The code has to come along when the sale is reported: data-affilyflow-coupon on the line, the coupon field in the GA4 purchase, or coupons from your server. See Personal discount codes.

Lead programs

If the program pays per lead rather than per purchase, no amount needs to be reported. Enter the address of your thank-you page under Automatic lead tracking in Setup. The script then carries the thank-you page's address and counts leads on its own:

<head> · every page · lead programHTML
<script src="https://app.affilyflow.com/track.js" data-store="DIN_BUTIK" data-lead-url="/tak"></script>

Here the script is loaded without async, because it has to count the lead before the thank-you page possibly sends the customer on elsewhere. If you leave the field empty, Setup shows a lead script for the thank-you page instead.

Other ways to report the sale

The line and the Google Analytics route cover most systems. The older JavaScript function affilyflow.conversion() still works – see track.js. If you report the sale from your own server, see Server-side tracking and the Conversion API.

Missing something?

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

Contact support