Piping Convert Data into GA or GTM

Summary

Convert provides different options to send data to GA. One of them is to send data as a string into GA (pipe) for the user to manipulate it and insert it into GA as you please.

Extracting the Data from your page and sending it to GA

The data will be sent in the following format as a string in the chose dimension to GA, depending on the number of experiments the user is bucketed on:

e:experimentid1=v:correspondingvariationid,e:experimentid2=v:correspondingvariationid,e:experimentid3=v:correspondingvariationid

First, you will need to place some code in the Convert app in Project > Configuration > Global Project Javascript.

To send the data to Google Analytics or GTM,  comment and uncomment the shown sections in the code and insert it in your Global Project Javascript section.

console.log("Global code started v1");

// Run the next code only one time even if called repeateadly

if (!window.globalExecutedTs) {
window.globalExecutedTs = true;

// First set the trackers for GA to send data in.

var dataToSend = '';

// Set the GA dimension you want to store the data in

var dimension = 1;

// Declare the function to collect the Convert experiment and variation current data to be sent to GA

function collectConvertData(_callback) {
var exp = convert.currentData.experiments;
var number_of_experiments = Object.keys(exp).length;
var loop_counter = 0;
var reporting_string = "";

if (number_of_experiments > 0) {
for (var expID in exp) {
//checking for experiments with >1 var
if(Object.keys(convert.data.experiments[expID].vars).length>1){
reporting_string = reporting_string + 'e:' + expID + '=' + 'v:' + exp[expID].variation_id;

if (loop_counter < number_of_experiments - 1) {
reporting_string = reporting_string + '|';
}
}
loop_counter++;
}
// console.log('Experiment data collected: '+reporting_string);
dataToSend = reporting_string;
_callback(reporting_string);
}
}

function sendtoGA(value_to_send,times_called) {
if (times_called < 4){
if (ga) {
// Enable if you want to send the data to GA as an event
ga('send', 'event' ,'Convert-Event', 'dimension:'+ dimension + '/' + value_to_send, true);
console.log('Experiment Data sent to GA4: ' + value_to_send);
}
else if (times_called < 4) {
setTimeout(function () {
times_called++;
sendStraightIntoGA4(value_to_send,times_called);
}, 50);
}
}
}

function sendtoGTM(value_to_send,times_called){
if (times_called < 4){
if (window.dataLayer) {
window.dataLayer.push({'ConvertExperiments':reporting_string});
console.log('Experiment Data sent to the dataLayer: ' + value_to_send);
}
else if (times_called < 4) {
setTimeout(function () {
times_called++;
sendtoGTM(value_to_send,times_called);
}, 50);
}
}
}

function sendDataToChannels(data) {
// Check if dataToSend is not undefined or an empty string
if (typeof data !== "undefined") {
if (!(data.length == 0)) {
// Comment the one the channel that you are not going to use
sendtoGA(data,1);
//sendtoGTM(data);

};
}
}


function collectAndSendConvertData(){
var data
collectConvertData(sendDataToChannels);
}


_conv_q = window._conv_q || [];
_conv_q.push({
what: 'addListener',
params: {
event: 'snippet.experiences_evaluated',
handler: (event) => collectAndSendConvertData()
}
})

}

From here, you can choose how to insert the data into GA. 

If using the GA option you will need to create the Custom Dimension in GA and address the index in the code as commented.

blobid0.png

blobid1.png

Name the dimension. Select Session as the Scope, and Save it.

blobid2.png

Lookup the dimension index, and use it in your code for setting it as instructed in the GA code comments.

blobid3.png

In this, we would use 'dimension18' in the code.

Now, you will be able to use the data in GA and GTM as you wish. 

Need assistance? Start a conversation with our Support Team.
CONVERT MORE

Reliably Convert More Site Visitors, Even If Everything Else is Changing in Your Business.

START 15-DAY FREE TRIAL
✓ No Credit Card  ✓ Easy Set-Up  ✓ Access All Features

Comments