ActiveCampaign Forum

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


#1

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.


#2

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

Thank you very much!


#3

//built by Julian Juenemann @ Measureschool.com

var api_key = “”; //enter your Event Key found under Settings -> Tracking -> Event Tracking -> Event Key http://take.ms/OD0Vu
var actid = 000000; //enter your Account ID found under Settings -> Tracking -> Event Tracking -> Click on the Link “Event Tracking API” http://take.ms/LLXTU

//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
payloadData.push(
[‘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]]);
}

}

Logger.log(payloadData)

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

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

var response = UrlFetchApp.fetch(‘https://trackcmp.net/event’, options); //send data to AC
Logger.log(response.getContentText());

//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”: "test@example.com",
“event”: “watched”,
“eventdata”: “test”
}
};
doGet(payload);
}


#4

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!

Tristan