Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
// An example tag template that makes a request to
// and sends data about the weather to both GA4 and Universal Analytics.
const getAllEventData = require('getAllEventData');
const getEventData = require('getEventData');
const JSON = require('JSON');
const sendEventToGoogleAnalytics = require('sendEventToGoogleAnalytics');
const sendHttpRequest = require('sendHttpRequest');
const client_id = getEventData('client_id');
const events = getAllEventData();
sendHttpRequest('[enter_api_key_here]&units=metric&lang=nl', (statusCode, headers, response) => {
response = JSON.parse(response);
// GA4 =[0].description; // Add data from the OpenWeatherMap API to the request
sendEventToGoogleAnalytics(events, (response) => {
// Universal Analytics
const events_ga = {
'x-ga-measurement_id': 'UA-XXXXXX-1', // Replace with your own GA UA ID
'v': 1,
't': 'event',
'cid': client_id,
'ec': 'example event category',
'ea': 'example event action',
'el':[0].description, // Add data from the OpenWeatherMap API to the request
'ni': 1
sendEventToGoogleAnalytics(events_ga, (response) => {
}, {method: 'GET', timeout: 2000});
// Call data.gtmOnSuccess when the tag is finished.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment