ActiveCampaign Forum

User content: Event Tracking with Google Tag Manager [video]

Google Tag Manager makes setting up event tracking like button clicking, form clicking or link clicking extremely easy. This video teaches you how to send dynamic event tracking data to ActiveCampaign with the help of GTM and a Google App Script.

Watch the video here.


Hey Brian! Saw it on Youtube, do you have the script available? Dead Link on the original page…

Thank you very much!

//built by Julian Juenemann @

var api_key = “”; //enter your Event Key found under Settings -> Tracking -> Event Tracking -> Event Key
var actid = 000000; //enter your Account ID found under Settings -> Tracking -> Event Tracking -> Click on the Link “Event Tracking API”

//read incoming data
function doGet(e) {
return handleResponse(e);

function doPost(e) {
return handleResponse(e);

//handle incoming data
function handleResponse(e){
var payloadData = [];

//push standard keys
[‘key’ , api_key], //api_key
[‘actid’ , actid] //ActiveCampaign ID

//parse response into array
var response = e.parameter;
for (var key in response){
if(key === “email”){
payloadData.push([“visit”, JSON.stringify({“email”:response[key]})])
else{payloadData.push([key, response[key]]);



//map data from array and build payload
var payload ={el[1] = encodeURIComponent(el[1]); return el.join(’=’)}).join(’&’); //joing payloadData into a query string

//send data to AC
var options =
‘contentType’: ‘application/x-www-form-urlencoded’,
‘method’ : ‘POST’,
‘payload’ : payload

var response = UrlFetchApp.fetch(‘’, options); //send data to AC

//print out response
return ContentService.createTextOutput(response.getContentText());

}; //end handleResponse function

//test GET request - call this function to test and see log commands in the script editor
function test() {
var payload =
{ “parameter”:
“email”: "",
“event”: “watched”,
“eventdata”: “test”

This looks very useful.

However, in the video, he picks up the email address from the datalayer, and just mentions that he has a plugin running that puts the email there.

I want to do this for logged in users, but I have no clue how to push the email address to the datalayer???

Any help would be appreciated!


1 Like