___TERMS_OF_SERVICE___ By creating or modifying this file you agree to Google Tag Manager's Community Template Gallery Developer Terms of Service available at https://developers.google.com/tag-manager/gallery-tos (or such other URL as Google may provide), as modified from time to time. ___INFO___ { "type": "TAG", "id": "cvt_temp_public_id", "version": 1, "securityGroups": [], "displayName": "Freebuff Pixel", "categories": [ "ADVERTISING", "CONVERSIONS", "ANALYTICS" ], "brand": { "id": "brand_freebuff", "displayName": "Freebuff" }, "description": "Installs the Freebuff Ads site pixel (freebuff-tag.v2.js). It measures visits from Freebuff ad clicks only: page views, engagement, your GA4 events and goal pages, so Freebuff can report and optimise your campaigns. Or, in Tag only mode, sends nothing to Freebuff and stores a Freebuff click reference in your PostHog or Mixpanel, for conversions captured through your analytics tool. Fire on All Pages.", "containerContexts": [ "WEB" ] } ___TEMPLATE_PARAMETERS___ [ { "type": "SELECT", "name": "mode", "displayName": "Mode", "macrosInSelect": false, "selectItems": [ { "value": "pixel", "displayValue": "Full pixel" }, { "value": "tag_only", "displayValue": "Tag only (conversions from your analytics tool)" } ], "simpleValueType": true, "defaultValue": "pixel", "alwaysInSummary": true, "help": "Full pixel loads the Freebuff site pixel. Tag only sends no pixel events or conversions: on a page reached from a Freebuff ad it stores a click reference (never the click id) as the property freebuff_ref in your PostHog or Mixpanel, and your analytics tool's webhook destination sends conversions to Freebuff." }, { "type": "TEXT", "name": "tagId", "displayName": "Freebuff tag ID", "simpleValueType": true, "alwaysInSummary": true, "help": "Your advertiser tag ID, shown in the Freebuff Ads console under Tracking. It starts with fbt_ and is public, not a secret.", "enablingConditions": [ { "paramName": "mode", "paramValue": "tag_only", "type": "NOT_EQUALS" } ], "valueValidators": [ { "type": "NON_EMPTY" }, { "type": "REGEX", "args": [ "^fbt_[A-Za-z0-9_-]{22}$" ], "errorMessage": "A Freebuff tag ID is fbt_ followed by 22 letters, digits, - or _." } ] } ] ___SANDBOXED_JS_FOR_WEB_TEMPLATE___ const injectScript = require('injectScript'); const encodeUriComponent = require('encodeUriComponent'); const isConsentGranted = require('isConsentGranted'); // Tag only: no pixel. The script stores a click ref in the page's analytics // tool. Google Consent Mode is read here, with the pixel's rule (ad and // analytics storage both granted); the script reads the other consent // platforms and Global Privacy Control itself, as the pixel does. const tagId = data.tagId; if (data.mode === 'tag_only') { if (!isConsentGranted('ad_storage') || !isConsentGranted('analytics_storage')) { data.gtmOnSuccess(); } else { injectScript( 'https://freebuff.com/freebuff-ref.v1.js', data.gtmOnSuccess, data.gtmOnFailure, 'freebuff-ref-v1' ); } } else if (!tagId) { data.gtmOnFailure(); } else { // The tag reads its tag ID from its own script URL, and drains any // freebuff(...) calls queued before it loads. injectScript( 'https://freebuff.com/freebuff-tag.v2.js?t=' + encodeUriComponent(tagId), data.gtmOnSuccess, data.gtmOnFailure, 'freebuff-tag-v2' ); } ___WEB_PERMISSIONS___ [ { "instance": { "key": { "publicId": "inject_script", "versionId": "1" }, "param": [ { "key": "urls", "value": { "type": 2, "listItem": [ { "type": 1, "string": "https://freebuff.com/freebuff-tag.v2.js*" }, { "type": 1, "string": "https://freebuff.com/freebuff-ref.v1.js" } ] } } ] }, "clientAnnotations": { "isEditedByUser": true }, "isRequired": true }, { "instance": { "key": { "publicId": "access_consent", "versionId": "1" }, "param": [ { "key": "consentTypes", "value": { "type": 2, "listItem": [ { "type": 3, "mapKey": [ { "type": 1, "string": "consentType" }, { "type": 1, "string": "read" }, { "type": 1, "string": "write" } ], "mapValue": [ { "type": 1, "string": "ad_storage" }, { "type": 8, "boolean": true }, { "type": 8, "boolean": false } ] }, { "type": 3, "mapKey": [ { "type": 1, "string": "consentType" }, { "type": 1, "string": "read" }, { "type": 1, "string": "write" } ], "mapValue": [ { "type": 1, "string": "analytics_storage" }, { "type": 8, "boolean": true }, { "type": 8, "boolean": false } ] } ] } } ] }, "clientAnnotations": { "isEditedByUser": true }, "isRequired": true } ] ___TESTS___ scenarios: - name: Injects the Freebuff pixel with the tag ID, once per page code: |- mock('injectScript', (url, onSuccess, onFailure, cacheToken) => { assertThat(url).isEqualTo('https://freebuff.com/freebuff-tag.v2.js?t=fbt_AbCdEfGhIjKlMnOpQrStUv'); assertThat(cacheToken).isEqualTo('freebuff-tag-v2'); onSuccess(); }); runCode({ tagId: 'fbt_AbCdEfGhIjKlMnOpQrStUv' }); assertApi('injectScript').wasCalled(); assertApi('gtmOnSuccess').wasCalled(); assertApi('gtmOnFailure').wasNotCalled(); - name: Fails the tag when the script cannot load code: |- mock('injectScript', (url, onSuccess, onFailure) => { onFailure(); }); runCode({ tagId: 'fbt_AbCdEfGhIjKlMnOpQrStUv' }); assertApi('gtmOnFailure').wasCalled(); - name: Fails without a tag ID and injects nothing code: |- runCode({ tagId: '' }); assertApi('injectScript').wasNotCalled(); assertApi('gtmOnFailure').wasCalled(); - name: A tag created before the mode setting stays the full pixel code: |- mock('injectScript', (url, onSuccess) => { assertThat(url).isEqualTo('https://freebuff.com/freebuff-tag.v2.js?t=fbt_AbCdEfGhIjKlMnOpQrStUv'); onSuccess(); }); runCode({ mode: 'pixel', tagId: 'fbt_AbCdEfGhIjKlMnOpQrStUv' }); assertApi('gtmOnSuccess').wasCalled(); - name: Tag only injects the click ref script, never the pixel, with no tag ID code: |- mock('isConsentGranted', (type) => true); mock('injectScript', (url, onSuccess, onFailure, cacheToken) => { assertThat(url).isEqualTo('https://freebuff.com/freebuff-ref.v1.js'); assertThat(cacheToken).isEqualTo('freebuff-ref-v1'); onSuccess(); }); runCode({ mode: 'tag_only', tagId: '' }); assertApi('injectScript').wasCalled(); assertApi('gtmOnSuccess').wasCalled(); assertApi('gtmOnFailure').wasNotCalled(); - name: Tag only injects nothing when Consent Mode denies ad or analytics storage code: |- mock('isConsentGranted', (type) => type !== 'analytics_storage'); runCode({ mode: 'tag_only' }); assertApi('injectScript').wasNotCalled(); assertApi('gtmOnSuccess').wasCalled(); ___NOTES___ Created on 2026-09-29 for COD-708. Source of truth: integrations/gtm-freebuff-pixel/ in the Freebuff repository.