A Server-Side Google Tag Manager (SSGTM) template that integrates with Trackingplan's analytics governance platform. This template captures tracking events from GTM and client-side requests, batches them efficiently, and sends them to Trackingplan's API for analysis and monitoring.
-
Event capture: Intercepts tracking events from:
- Server-Side GTM events
- Client-side events sent via message listeners
-
Event standardization: Creates standardized "raw track" objects with all necessary information
-
Batching mechanism:
- Collects events in a queue until reaching batch size or time threshold
- Handles concurrent request batching
-
Data transmission:
- Sends batches to Trackingplan's API
- Adds GTM container information as tags
This should be done on all the templates that want to be monitored by Trackingplan.
- Open the tag template (this works on any tag)
- Add Trackingplan Snippet to the top of the Template (see code below)
- Remove/Comment the original sendHttpRequest and sendHttpGet require statements.
- Enable the Send / Receive Message Permission
- Save
- And don't forget to publish your changes
/* Trackingplan snippet to be included in on top of templates to be monitored by Trackingplan */
const sendHttpRequest = (url, options, body) => {
require('addEventCallback')(() => {
require('sendMessage')('tp_request', { url: url, body: body });
});
return require('sendHttpRequest')(url, options, body);
};
const sendHttpGet = function (url, options) {
require('addEventCallback')(() => {
require('sendMessage')('tp_request', { url: url });
});
return require('sendHttpGet')(url, options);
};
/* End of Trackingplan snippet */-
Import the template to your SSGTM container (if not using gallery):
- Download this template
- In your SSGTM container, go to Templates → New → Import from file
- Select the downloaded template file
-
Create a new tag using the template:
- In your SSGTM container, go to Tags → New
- Select the Trackingplan template
- Configure the required settings (see Configuration section)
- Set appropriate trigger rules (typically "All Events")
-
Publish your container
| Option | Description | Default |
|---|---|---|
tpId |
Your Trackingplan ID (required) | None |
maxBatchSize |
Maximum number of events in a batch | 1 |
maxBatchAgeSeconds |
Maximum time to wait before sending a batch | 5 |
samplingRate |
Event sampling rate (1 = all events, 10 = 10% of events) | 1 |
environment |
Environment identifier ("PRODUCTION" or "TESTING") | "PRODUCTION" |
endpoint |
Trackingplan API endpoint | "https://tracks.trackingplan.com/v1/" |
tags |
Custom key-value pairs to send with all events | {} |
extraLog |
Enable detailed logging for debugging | false |
useSessions |
Enable session tracking with 30-minute timeout | false |
captureGTM |
Enable GTM event capture | true |
When troubleshooting, enable the extraLog option to get detailed information about:
- Event processing
- Batch creation and sending
- API responses
Logs can be viewed in the Server-Side GTM container's preview mode under the "Logs" tab.
This template is provided under the Apache 2.0 License.
For support, please contact support@trackingplan.com or visit the Trackingplan documentation.