Skip to content

Instantly share code, notes, and snippets.

View ssgtm_tag_template_complete_example.js
// An example tag template that makes a request to OpenWeatherMap.org
// 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');
View ssgtm_tag_template_sendEventToGoogleAnalytics_UA.js
// Send data to Universal Analytics
const getEventData = require('getEventData');
const sendEventToGoogleAnalytics = require('sendEventToGoogleAnalytics');
const client_id = getEventData('client_id');
const events = {
'x-ga-measurement_id': 'UA-XXXXXX-1', // Replace with your own GA UA ID
'v': 1,
't': 'event',
View ssgtm_tag_template_sendEventToGoogleAnalytics_GA4_extra_data.js
// Send data to GA4
const getAllEventData = require('getAllEventData');
const sendEventToGoogleAnalytics = require('sendEventToGoogleAnalytics');
const events = getAllEventData();
// Add extra fields to the events object:
events.firstname = 'Wouter';
sendEventToGoogleAnalytics(events, (response) => {
View ssgtm_tag_template_sendEventToGoogleAnalytics_GA4.js
// Send data to GA4
const getAllEventData = require('getAllEventData');
const sendEventToGoogleAnalytics = require('sendEventToGoogleAnalytics');
const events = getAllEventData();
sendEventToGoogleAnalytics(events, (response) => {
data.gtmOnFailure();
});
@WouterNieuwerth
WouterNieuwerth / ssgtm_tag_template_sendHttpRequest.js
Created February 27, 2022 13:00
This Server-side GTM tag template makes a request to openweathermap.org and parses the JSON response.
View ssgtm_tag_template_sendHttpRequest.js
// An example tag template that makes a request to OpenWeatherMap.org
const JSON = require('JSON');
const sendHttpRequest = require('sendHttpRequest');
sendHttpRequest('https://api.openweathermap.org/data/2.5/weather?lat=52.3746027&lon=6.6810724&appid=[enter_api_key_here]&units=metric&lang=nl', (statusCode, headers, response) => {
response = JSON.parse(response);
// Do something with the response.
@WouterNieuwerth
WouterNieuwerth / ssgtm_variable_template.js
Created February 27, 2022 12:38
An example of a server-side GTM variable template that doesn't work ufortunately.
View ssgtm_variable_template.js
// A variable template that doesn't work, because it uses an asynchronous API.
const JSON = require('JSON');
const sendHttpRequest = require('sendHttpRequest');
sendHttpRequest('https://api.openweathermap.org/data/2.5/weather?lat=52.3746027&lon=6.6810724&appid=[enter_api_key_here]&units=metric&lang=nl', (statusCode, headers, response) => {
response = JSON.parse(response);
return response;
View somfy_nodejs_RPi_example.js
let Gpio
const express = require('express')
const router = express.Router()
// Onoff cannot be installed on devices without Gpio
try {
Gpio = require('onoff').Gpio
} catch (err) {
Gpio = {
accessible: false
View fuzzywuzzy_cloud_function.py
from fuzzywuzzy import fuzz
from fuzzywuzzy import process
def fuzzy_flask(request):
"""Responds to a HTTP request.
Args:
request (flask.Request): HTTP request object.
Returns:
The response text or any set of values that can be turned into a
Response object using
View request_cloud_function_from_google_ads_script.js
// Add your own Cloud Function URL here:
var CLOUDFUNCTIONSURL = 'https://europe-west1-cloud-functions-example.cloudfunctions.net/example';
var search_terms = ["buy nike shoes", "adidas online", "rebok cloths"]; // With some spelling errors
var brands = ["nike", "adidas", "reebok"];
function main() {
var json = {
"searchterms": search_terms,
View Google_Cloud_Function_Python_example.py
def hello_world(request):
"""Responds to any HTTP request.
Args:
request (flask.Request): HTTP request object.
Returns:
The response text or any set of values that can be turned into a
Response object using
`make_response <http://flask.pocoo.org/docs/1.0/api/#flask.Flask.make_response>`.
"""
request_json = request.get_json()