Integrating Google Analytics to the Freshmarketer data would provide many valuable insights. By finding visitors bucketed to the Freshmarketer experiment, one can get many useful metrics from GA as well.


With GTM, you can get the same wealth of metrics from your GA at ease.


On a side note, to integrate Freshmarketer or Google Analytics through Google Tag Manager, you must fire the GA code using Tag Manager and at least one Freshmarketer A/B testing experiment should be running.

 

This article discusses integrating Freshmarketer with GA through GTM. Walk through this guide to know more about it.


Gaining Freshmarketer Data

To use GTM for integration, an account with a container needs to be created. Please set up the account by providing a name to the account, also create a container by providing the URL of the website and choose a platform where the container needs to be used.


Click Add a new tag and choose tag type Custom HTML Tag. This tag will collect the relevant data from the Freshmarketer javascript object.



Freshmarketer GTM Integration


Fire the below Freshmarketer snippet to all the pages:


  • JavaScript
<script> 
function zargetGAInteg(){  
  var runningABExps = window.zargetAPI.getAllRunningExperiments('ab');
  if(runningABExps.length){
    var currentAbExp = runningABExps[0];
   dataLayer.push({
    'zargetExpId': currentAbExp.id,
    'zargetVarName': currentAbExp.appliedVariationName,
    'event':'zargetData'
  }); 
  }
}  
  if(window.zargetAPI && window.zargetAPI.expLoaded) {
     zargetGAInteg();
  }else {
    if(document.body.addEventListener){
      document.body.addEventListener("experimentLoaded", zargetGAInteg, false);
    }else{
      document.body.attachEvent("experimentLoaded", zargetGAInteg);
}
  }
</script> 


Your code should look like this:


Code Installation

Code Installation

 

Add the above code under Configure Tag section and click All Pages option under trigger section. On clicking the Create tag button, the tag will be created.




The variables zargetExpId and zargetVarName will fetch the data from the running Freshmarketer experiment. Hence, the next step is to create data layer variables for the specified variables.


Passing the A/B Test data to Google Universal Analytics

To feed the data of a running A/B test experiment, it involves three steps:

  • Create two variables to transfer the data layer information to the tag
  • A trigger to fire when the Freshmarketer data is added to the data layer variables.
  • A tag to send the collected data to the Google Analytics.


STEP 1:

Creation of Data Variables in GTM


Now, the data variables need to be added to the GTM. Create two data layer variables in GTM to transfer the information to the tag. Select Variables from the left side panel.


"Variables" in GTM Panel


A new variable creation box appears. Give ZargetExpId as the name of the variable. Now you need to choose the type of the variable. Select 'Data Layer Variable' as the variable type. Give the same name ZargetExpId under the ‘Data Layer Variable name’ text field. Click save and proceed.



NOTE: Similarly, create another data layer variable for zargetVarName.


STEP 2:


Creation of Trigger in GTM


Select Triggers from the left side panel of your page.


To transfer the Freshmarketer data to Google Analytics, a custom event triggering needs to be done.


"Triggers" in GTM Panel



Name the Trigger as ZargetData. Choose the Trigger Type as Custom Event. The All Custom Events option will be selected by default.


Trigger Creation Page



Click save to proceed.


STEP 3:

Tag creation for GA in GTM


Create a new tag. Click on New. Provide an appropriate name for the Tag. Choose Tag type as Google Analytics - Universal Analytics. This step sends all the information collected from the running A/B test experiment to GA.



Once done, please choose a new variable from the dropdown option under Google Analytics Settings. Enter the Google Analytics ID in the Tracking ID which you will find in the GA page admin page, under Property Settings.



Go to more settings after entering the tracking ID. Expand the custom dimension. Under Index, click 'add custom dimension'. Please choose both the data variables created named ZargetExpId and ZargetVarName. Add the correct dimension value and index from the drop-down menu.



Creating Tag For GA in GTM



NOTE: It is important to create a custom dimension in UA to ensure Freshmarketer data is accurately mapped in UA.


Upon adding all the values, it should appear as below:





In case the custom dimension is not found, follow the below steps:

  • Log in to your UA account. Navigate to the ‘Admin’ tab and select "Custom Dimensions".


Custom Definitions in UA

Custom Definitions in UA


Create a new ‘Custom Dimension’.


Creating a New Custom Dimensions

Creating a New Custom Dimensions


Now that you have successfully integrated Freshmarketer with GA through GTM. You can view metrics for the A/B test data in GA seamlessly.


Technical Support

Don't see what you're looking for? Just drop us a mail