Created
April 16, 2021 09:37
-
-
Save mbaersch/398e943ca9fb9e8a4bbb02563ee406f9 to your computer and use it in GitHub Desktop.
Google Tag Manager Custom Client Template to demonstrate processing incoming requests directly without using event data and / or tags
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
___INFO___ | |
{ | |
"type": "CLIENT", | |
"id": "cvt_temp_public_id", | |
"version": 1, | |
"securityGroups": [], | |
"displayName": "Tagless Logger Client [DEMO]", | |
"brand": { | |
"id": "brand_dummy", | |
"displayName": "" | |
}, | |
"description": "yet another demo client", | |
"containerContexts": [ | |
"SERVER" | |
] | |
} | |
___TEMPLATE_PARAMETERS___ | |
[ | |
{ | |
"type": "TEXT", | |
"name": "endpointUrl", | |
"displayName": "Tracking Endpoint (optional)", | |
"simpleValueType": true | |
} | |
] | |
___SANDBOXED_JS_FOR_SERVER___ | |
//DEMO: "complete client" that receives incoming tracking requests and | |
//forwards them to a specific endpoint, sets a "__GTMTEST" cookie with | |
//the processed url as example value and sends a response. Everything | |
//happens in the client without handing event data over to any tags. | |
const claimRequest = require('claimRequest'); | |
const returnResponse = require('returnResponse'); | |
const getRequestQueryParameter = require('getRequestQueryParameter'); | |
const sendHttpGet = require('sendHttpGet'); | |
const setPixelResponse = require('setPixelResponse'); | |
const getRequestHeader = require('getRequestHeader'); | |
const getRequestPath = require('getRequestPath'); | |
const setCookie = require("setCookie"); | |
const logToConsole = require("logToConsole"); | |
if (getRequestPath() === '/send2log') { | |
claimRequest(); | |
//get incoming tracking info from parameters or headers | |
const ref = getRequestQueryParameter('ref'); | |
const url = getRequestQueryParameter('url') || getRequestHeader('Referer'); | |
const cid = getRequestQueryParameter('cid') || 666; | |
//get endpoint URL from settings | |
const serviceUrl = data.endpointUrl; | |
//logging endpoint defined and at least URL present? send hit | |
if (serviceUrl && url) sendHttpGet(serviceUrl + '?cid='+cid+'&loc='+url+'&ref='+ref); | |
//send response; no matter what happened | |
setCookie('__GTMTEST', url); | |
setPixelResponse(); | |
returnResponse(); | |
} | |
___SERVER_PERMISSIONS___ | |
[ | |
{ | |
"instance": { | |
"key": { | |
"publicId": "read_request", | |
"versionId": "1" | |
}, | |
"param": [ | |
{ | |
"key": "requestAccess", | |
"value": { | |
"type": 1, | |
"string": "any" | |
} | |
}, | |
{ | |
"key": "headerAccess", | |
"value": { | |
"type": 1, | |
"string": "any" | |
} | |
}, | |
{ | |
"key": "queryParameterAccess", | |
"value": { | |
"type": 1, | |
"string": "any" | |
} | |
} | |
] | |
}, | |
"clientAnnotations": { | |
"isEditedByUser": true | |
}, | |
"isRequired": true | |
}, | |
{ | |
"instance": { | |
"key": { | |
"publicId": "return_response", | |
"versionId": "1" | |
}, | |
"param": [] | |
}, | |
"isRequired": true | |
}, | |
{ | |
"instance": { | |
"key": { | |
"publicId": "access_response", | |
"versionId": "1" | |
}, | |
"param": [ | |
{ | |
"key": "writeResponseAccess", | |
"value": { | |
"type": 1, | |
"string": "any" | |
} | |
}, | |
{ | |
"key": "writeHeaderAccess", | |
"value": { | |
"type": 1, | |
"string": "specific" | |
} | |
} | |
] | |
}, | |
"clientAnnotations": { | |
"isEditedByUser": true | |
}, | |
"isRequired": true | |
}, | |
{ | |
"instance": { | |
"key": { | |
"publicId": "set_cookies", | |
"versionId": "1" | |
}, | |
"param": [ | |
{ | |
"key": "allowedCookies", | |
"value": { | |
"type": 2, | |
"listItem": [ | |
{ | |
"type": 3, | |
"mapKey": [ | |
{ | |
"type": 1, | |
"string": "name" | |
}, | |
{ | |
"type": 1, | |
"string": "domain" | |
}, | |
{ | |
"type": 1, | |
"string": "path" | |
}, | |
{ | |
"type": 1, | |
"string": "secure" | |
}, | |
{ | |
"type": 1, | |
"string": "session" | |
} | |
], | |
"mapValue": [ | |
{ | |
"type": 1, | |
"string": "__GTMTEST" | |
}, | |
{ | |
"type": 1, | |
"string": "*" | |
}, | |
{ | |
"type": 1, | |
"string": "*" | |
}, | |
{ | |
"type": 1, | |
"string": "any" | |
}, | |
{ | |
"type": 1, | |
"string": "any" | |
} | |
] | |
} | |
] | |
} | |
} | |
] | |
}, | |
"clientAnnotations": { | |
"isEditedByUser": true | |
}, | |
"isRequired": true | |
}, | |
{ | |
"instance": { | |
"key": { | |
"publicId": "send_http", | |
"versionId": "1" | |
}, | |
"param": [ | |
{ | |
"key": "allowedUrls", | |
"value": { | |
"type": 1, | |
"string": "any" | |
} | |
} | |
] | |
}, | |
"clientAnnotations": { | |
"isEditedByUser": true | |
}, | |
"isRequired": true | |
}, | |
{ | |
"instance": { | |
"key": { | |
"publicId": "logging", | |
"versionId": "1" | |
}, | |
"param": [ | |
{ | |
"key": "environments", | |
"value": { | |
"type": 1, | |
"string": "debug" | |
} | |
} | |
] | |
}, | |
"isRequired": true | |
} | |
] | |
___TESTS___ | |
scenarios: [] | |
___NOTES___ | |
Created on 16.4.2021, 11:32:45 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment