Skip to content

Instantly share code, notes, and snippets.

@sahava
Created May 6, 2021 18:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sahava/86e5f98ee29c7c432727bc577feef2e7 to your computer and use it in GitHub Desktop.
Save sahava/86e5f98ee29c7c432727bc577feef2e7 to your computer and use it in GitHub Desktop.
Simmer Client - Custom Client Template for Google Tag Manager Server containers. This is a "minimum viable Client" template, designed as an example for the Simmer course on server-side tagging.
___INFO___
{
"type": "CLIENT",
"id": "cvt_temp_public_id",
"version": 1,
"securityGroups": [],
"displayName": "Simmer Client",
"brand": {
"id": "brand_dummy",
"displayName": ""
},
"description": "",
"containerContexts": [
"SERVER"
]
}
___TEMPLATE_PARAMETERS___
[]
___SANDBOXED_JS_FOR_SERVER___
const claimRequest = require('claimRequest');
const getRequestPath = require('getRequestPath');
const getRequestQueryParameters = require('getRequestQueryParameters');
const returnResponse = require('returnResponse');
const runContainer = require('runContainer');
const setResponseBody = require('setResponseBody');
const setResponseStatus = require('setResponseStatus');
// Pull in all the query parameters from the request
const params = getRequestQueryParameters();
// Assume request looks like this:
// https://<your endpoint>/testing?en=some_event&uid=123456789&size=xtralarge&et=1620215159958
// If request is to /testing and has the &en parameter (for event name),
// claim it.
if (getRequestPath() === '/testing' && params.en) {
// Absolute minimum viable Client would do just this and nothing else:
claimRequest();
// Build event object, use syntax from
// https://developers.google.com/tag-manager/serverside/common-event-data
const event = {
event_name: params.en,
user_id: params.uid,
'x-st-event_timestamp': params.et,
'x-st-custom_parameters': {
size: params.size
}
};
// Run the container with this event data object
runContainer(event, () => {
// Set 200 status, success message
setResponseStatus(200);
setResponseBody('Request to /testing processed successfully...');
returnResponse();
});
}
___SERVER_PERMISSIONS___
[
{
"instance": {
"key": {
"publicId": "read_request",
"versionId": "1"
},
"param": [
{
"key": "queryParametersAllowed",
"value": {
"type": 8,
"boolean": true
}
},
{
"key": "pathAllowed",
"value": {
"type": 8,
"boolean": true
}
},
{
"key": "queryParameterAccess",
"value": {
"type": 1,
"string": "any"
}
},
{
"key": "requestAccess",
"value": {
"type": 1,
"string": "specific"
}
},
{
"key": "headerAccess",
"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": "specific"
}
},
{
"key": "writeStatusAllowed",
"value": {
"type": 8,
"boolean": true
}
},
{
"key": "writeBodyAllowed",
"value": {
"type": 8,
"boolean": true
}
},
{
"key": "writeHeaderAccess",
"value": {
"type": 1,
"string": "specific"
}
}
]
},
"clientAnnotations": {
"isEditedByUser": true
},
"isRequired": true
},
{
"instance": {
"key": {
"publicId": "run_container",
"versionId": "1"
},
"param": []
},
"isRequired": true
}
]
___TESTS___
scenarios: []
___NOTES___
Created on 06/05/2021, 21:07:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment