___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": "Reveata Analytics", "categories": ["ANALYTICS", "CONVERSIONS"], "brand": { "id": "brand_reveata", "displayName": "Reveata" }, "description": "Loads the Reveata tracking script (privacy-friendly analytics that ties revenue to traffic), and sends goals or identify calls.", "containerContexts": [ "WEB" ] } ___TEMPLATE_PARAMETERS___ [ { "type": "RADIO", "name": "action", "displayName": "What this tag does", "radioItems": [ { "value": "load", "displayValue": "Load the Reveata script (fire on All Pages)" }, { "value": "goal", "displayValue": "Track a goal" }, { "value": "identify", "displayValue": "Identify the visitor" } ], "simpleValueType": true, "defaultValue": "load" }, { "type": "TEXT", "name": "host", "displayName": "Reveata address", "simpleValueType": true, "defaultValue": "https://reveata.com", "help": "The address you open Reveata at, or your managed proxy (for example https://stats.yoursite.com). The \"Injects scripts\" permission must allow it: the template downloaded from your website's Settings → General → Managed proxy already allows https://*.yoursite.com/js/*; otherwise add that pattern to the permission yourself.", "valueValidators": [ { "type": "NON_EMPTY" }, { "type": "REGEX", "args": [ "^https://[a-zA-Z0-9.-]+(:[0-9]+)?/?$" ] } ], "enablingConditions": [ { "paramName": "action", "paramValue": "load", "type": "EQUALS" } ] }, { "type": "TEXT", "name": "websiteId", "displayName": "Website tracking id", "simpleValueType": true, "help": "Starts with ws_ (Reveata → Settings → General).", "valueValidators": [ { "type": "NON_EMPTY" }, { "type": "REGEX", "args": [ "^ws_[a-z0-9]{6,32}$" ] } ], "enablingConditions": [ { "paramName": "action", "paramValue": "load", "type": "EQUALS" } ] }, { "type": "GROUP", "name": "options", "displayName": "Options", "groupStyle": "ZIPPY_CLOSED", "subParams": [ { "type": "CHECKBOX", "name": "cookieless", "checkboxText": "Cookieless mode (store nothing in visitors' browsers)", "simpleValueType": true }, { "type": "CHECKBOX", "name": "hash", "checkboxText": "Track #/route changes as pages", "simpleValueType": true }, { "type": "CHECKBOX", "name": "respectDnt", "checkboxText": "Respect Do Not Track / Global Privacy Control", "simpleValueType": true }, { "type": "TEXT", "name": "domains", "displayName": "Other domains of this website (comma-separated)", "simpleValueType": true }, { "type": "TEXT", "name": "excludePaths", "displayName": "Paths not to track (comma-separated, * wildcard)", "simpleValueType": true } ], "enablingConditions": [ { "paramName": "action", "paramValue": "load", "type": "EQUALS" } ] }, { "type": "TEXT", "name": "goalName", "displayName": "Goal name", "simpleValueType": true, "help": "Lowercase letters, digits, _ and -, e.g. signup.", "valueValidators": [ { "type": "NON_EMPTY" }, { "type": "REGEX", "args": [ "^[a-z0-9][a-z0-9_-]{0,63}$" ] } ], "enablingConditions": [ { "paramName": "action", "paramValue": "goal", "type": "EQUALS" } ] }, { "type": "SIMPLE_TABLE", "name": "goalProps", "displayName": "Goal properties", "simpleTableColumns": [ { "defaultValue": "", "displayName": "Name", "name": "key", "type": "TEXT" }, { "defaultValue": "", "displayName": "Value", "name": "value", "type": "TEXT" } ], "enablingConditions": [ { "paramName": "action", "paramValue": "goal", "type": "EQUALS" } ] }, { "type": "TEXT", "name": "userId", "displayName": "User id", "simpleValueType": true, "valueValidators": [ { "type": "NON_EMPTY" } ], "enablingConditions": [ { "paramName": "action", "paramValue": "identify", "type": "EQUALS" } ] }, { "type": "TEXT", "name": "email", "displayName": "Email (optional)", "simpleValueType": true, "enablingConditions": [ { "paramName": "action", "paramValue": "identify", "type": "EQUALS" } ] }, { "type": "TEXT", "name": "userName", "displayName": "Name (optional)", "simpleValueType": true, "enablingConditions": [ { "paramName": "action", "paramValue": "identify", "type": "EQUALS" } ] } ] ___SANDBOXED_JS_FOR_WEB_TEMPLATE___ const createArgumentsQueue = require('createArgumentsQueue'); const encodeUriComponent = require('encodeUriComponent'); const injectScript = require('injectScript'); const makeTableMap = require('makeTableMap'); const queryPermission = require('queryPermission'); // window.reveata: the tracker itself once loaded, otherwise a queue it replays on load. const reveata = createArgumentsQueue('reveata', 'reveata.q'); if (data.action === 'goal') { const props = data.goalProps ? makeTableMap(data.goalProps, 'key', 'value') : undefined; reveata('goal', data.goalName, props); data.gtmOnSuccess(); } else if (data.action === 'identify') { const visitor = { userId: data.userId }; if (data.email) visitor.email = data.email; if (data.userName) visitor.name = data.userName; reveata('identify', visitor); data.gtmOnSuccess(); } else { // Tag Manager can't set data-* attributes on injected scripts, so the tracker reads its // settings from the script URL's query. let host = data.host; if (host.charAt(host.length - 1) === '/') host = host.substring(0, host.length - 1); let url = host + '/js/' + (data.cookieless ? 'script.cookieless.js' : 'script.js'); url = url + '?website-id=' + encodeUriComponent(data.websiteId); if (data.cookieless) url = url + '&cookieless=true'; if (data.hash) url = url + '&hash=true'; if (data.respectDnt) url = url + '&respect-dnt=true'; if (data.domains) url = url + '&domains=' + encodeUriComponent(data.domains); if (data.excludePaths) url = url + '&exclude-paths=' + encodeUriComponent(data.excludePaths); // A managed proxy host (stats.yoursite.com) must be allowed by the "Injects scripts" // permission (https://*.yoursite.com/js/*); fail the tag clearly instead of throwing. if (queryPermission('inject_script', url)) { injectScript(url, data.gtmOnSuccess, data.gtmOnFailure, 'reveata'); } else { data.gtmOnFailure(); } } ___WEB_PERMISSIONS___ [ { "instance": { "key": { "publicId": "inject_script", "versionId": "1" }, "param": [ { "key": "urls", "value": { "type": 2, "listItem": [ { "type": 1, "string": "https://reveata.com/js/*" } ] } } ] }, "clientAnnotations": { "isEditedByUser": true }, "isRequired": true }, { "instance": { "key": { "publicId": "access_globals", "versionId": "1" }, "param": [ { "key": "keys", "value": { "type": 2, "listItem": [ { "type": 3, "mapKey": [ { "type": 1, "string": "key" }, { "type": 1, "string": "read" }, { "type": 1, "string": "write" }, { "type": 1, "string": "execute" } ], "mapValue": [ { "type": 1, "string": "reveata" }, { "type": 8, "boolean": true }, { "type": 8, "boolean": true }, { "type": 8, "boolean": true } ] }, { "type": 3, "mapKey": [ { "type": 1, "string": "key" }, { "type": 1, "string": "read" }, { "type": 1, "string": "write" }, { "type": 1, "string": "execute" } ], "mapValue": [ { "type": 1, "string": "reveata.q" }, { "type": 8, "boolean": true }, { "type": 8, "boolean": true }, { "type": 8, "boolean": false } ] } ] } } ] }, "clientAnnotations": { "isEditedByUser": true }, "isRequired": true } ] ___TESTS___ scenarios: - name: Loads the tracker with settings in the URL code: |- mock('injectScript', (url, onSuccess, onFailure, cacheToken) => { assertThat(url).isEqualTo('https://reveata.com/js/script.cookieless.js?website-id=ws_k3j9x2m1p0qa&cookieless=true&exclude-paths=%2Fadmin%2F*'); assertThat(cacheToken).isEqualTo('reveata'); onSuccess(); }); runCode({ action: 'load', host: 'https://reveata.com/', websiteId: 'ws_k3j9x2m1p0qa', cookieless: true, excludePaths: '/admin/*' }); assertApi('gtmOnSuccess').wasCalled(); - name: Reports a failed script load code: |- mock('injectScript', (url, onSuccess, onFailure) => { onFailure(); }); runCode({ action: 'load', host: 'https://reveata.com', websiteId: 'ws_k3j9x2m1p0qa' }); assertApi('gtmOnFailure').wasCalled(); - name: Fails without injecting when the permission does not allow the address code: |- mock('queryPermission', () => false); runCode({ action: 'load', host: 'https://stats.shop.example', websiteId: 'ws_k3j9x2m1p0qa' }); assertApi('injectScript').wasNotCalled(); assertApi('gtmOnFailure').wasCalled(); - name: Queues a goal with properties code: |- let calls = []; mock('createArgumentsQueue', () => function () { calls.push(arguments); }); runCode({ action: 'goal', goalName: 'signup', goalProps: [{ key: 'plan', value: 'pro' }] }); assertThat(calls.length).isEqualTo(1); assertThat(calls[0][0]).isEqualTo('goal'); assertThat(calls[0][1]).isEqualTo('signup'); assertThat(calls[0][2]).isEqualTo({ plan: 'pro' }); assertApi('gtmOnSuccess').wasCalled(); - name: Identifies the visitor code: |- let calls = []; mock('createArgumentsQueue', () => function () { calls.push(arguments); }); runCode({ action: 'identify', userId: 'u_123', email: 'ada@example.com' }); assertThat(calls[0][0]).isEqualTo('identify'); assertThat(calls[0][1]).isEqualTo({ userId: 'u_123', email: 'ada@example.com' }); assertApi('gtmOnSuccess').wasCalled(); ___NOTES___ Reveata Analytics tag for reveata.com. Managed proxy: add https://*.yoursite.com/js/* to the inject_script permission.