Skip to content
Browse the docs

Install Spurn with Google Tag Manager

Add Spurn through a Google Tag Manager custom template, then use its verdict to stop your remarketing and conversion tags firing for fake clicks.

Before you start#

  • Publish access to the GTM container on your site.
  • Your site's public key from Spurn: Sites, then your site, then the Install tab (it is also on the Keys tab). It looks like sp_pub_XXXXXXXXXXXXXXXXXXXXXXXX.
  • The Spurn template. Once it is listed in GTM's Community Template Gallery, add it from Templates, then Search Gallery, and skip to step 2. Until then, import the file template.tpl, which support@spurn.io sends on request.

1. Import the template#

  1. In GTM, open Templates. Under Tag Templates, click New.
  2. In the template editor, open the menu (three dots, top right) and choose Import.
  3. Choose template.tpl, then click Save and close the editor.

The template's permissions, which you can review on its Permissions tab:

  • Injects scripts from https://spurn.io/*.
  • Accesses global variables: it reads and writes spurnConfig, which tells the tag your site key, and reads and calls spurn, to report conversions.
  • Logs to console, in Preview mode only.

The template does two jobs, picked with What this tag does: Load the Spurn tag and Report a purchase or lead. You add one tag for each.

2. Add the tag#

  1. Open Tags and click New.
  2. Under Tag Configuration, choose Spurn click-fraud protection (listed under Custom).
  3. Set What this tag does to Load the Spurn tag.
  4. Fill in Site key with your public key. Leave Script URL as https://spurn.io/s.js unless Spurn support tells you otherwise.
  5. Under Triggering, choose Initialization - All Pages.
  6. Save, then Submit and Publish the container.

Fire it on every page. A paid visitor often lands on one page and buys on another, and the tag needs to see both. On organic visits it does nothing.

3. Use the verdict (optional)#

On a paid landing, once Spurn has scored the visit, the tag pushes this to the data layer. It pushes it again at the start of each later page of that paid session.

{ event: 'spurn_verdict', spurn_verdict: 'invalid', spurn_score: 87 }

spurn_verdict is valid, suspicious, invalid or pending. spurn_score runs from 0 to 100.

Create the variable:

  1. Variables, then New, then Data Layer Variable.
  2. Data Layer Variable Name: spurn_verdict. Save it as spurn_verdict.

Hold back tags for invalid visitors with an exception:

  1. Triggers, then New, then Custom Event. Name it Spurn - invalid visitor.
  2. Event name: .*, with Use regex matching on.
  3. This trigger fires on Some Custom Events: spurn_verdict equals invalid.
  4. Open each remarketing and conversion tag (add to cart, sign-up, purchase) and add Spurn - invalid visitor under Exceptions.

GTM checks an exception on each event, so the tag is held back on every event after the verdict arrives. It can't take back a tag that already fired when the page loaded, before Spurn answered.

To fire a tag only for paid visitors Spurn has checked, use a Custom Event trigger on the event name spurn_verdict, firing on Some Custom Events where spurn_verdict does not equal invalid. Organic visitors never get this event, so don't make it the only trigger of a tag that should fire for them too.

4. Report conversions (optional)#

A click that led to a purchase or a lead counts in its favour, and the dashboard shows which paid clicks converted.

  1. Create Data Layer Variables for your order's value, currency and id. With a standard GA4 ecommerce data layer, those are ecommerce.value, ecommerce.currency and ecommerce.transaction_id.
  2. Add another tag with Spurn click-fraud protection, and set What this tag does to Report a purchase or lead.
  3. Fill in Order value, Currency (default USD) and Order ID with those variables. The value is in major units (49.9 for $49.90).
  4. Trigger it on your purchase or lead event, for example a Custom Event trigger on purchase, or a Page View trigger on your confirmation page.
  5. Save and publish.

Only visitors who arrived on a paid click are reported. Outside a paid session the tag does nothing, so it is safe to fire for every order.

Check it works#

  1. Add your own IP address to the allowlist in Spurn (Blocking, then Allowlist), so your tests are never blocked.
  2. Open GTM's Preview with https://yoursite.com/?gclid=test-123. The Spurn tag fires, and a spurn_verdict event appears shortly after.
  3. After publishing, open Clicks in Spurn. The visit is there, and the site's Install tab shows Receiving.

A test landing counts as a real paid click and uses one credit.

Troubleshooting#

The tag fires but nothing arrives. Check the site key is the public key and the test URL has a click id. Visits without one are ignored by design.

Clicks are rejected for the wrong site. Spurn checks the page reporting a click against your site's domain and extra hosts. Add any other domain the container runs on in Sites, then your site.

The script is blocked. With a Content Security Policy, allow script-src https://spurn.io and connect-src https://spurn.io. Ad blockers can block GTM itself in your own browser.

Consent mode. If you hold tags until consent, Spurn waits too, and visitors who decline aren't checked. The tracking template still records the IP behind Google and Microsoft clicks: /docs/guides/tracking-template.

What data is sent#

On paid landings only: the landing URL and referrer, the IP address and user agent, browser signals used to spot automation, and engagement such as time on page. Conversions send the value, currency and id you give them. See /docs/detection.