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.
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 @ 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);
}
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