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

Click Add a new tag and select 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
function zargetGAInteg(){  
  var runningABExps = window.zargetAPI.getAllRunningExperiments('ab');
    var currentAbExp = runningABExps[0];
    'zargetVarName': currentAbExp.appliedVariationName,
  if(window.zargetAPI && window.zargetAPI.expLoaded) {
  }else {
      document.body.addEventListener("experimentLoaded", zargetGAInteg, false);
      document.body.attachEvent("experimentLoaded", zargetGAInteg);

Your code should look like this:

Code Installation

Code Installation


Add the above code under Configure Tag section and click All Pages button under Fire on the 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.

Feeding The A/B Test 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.


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

"Variables" in GTM Panel

A new variable creation box appears. Give an appropriate title and select Data Layer Variable.

Variable Creation Box

Variable Creation Box

Add zargetExpId in the Configure Variable section and Click on Select Variable button.

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


Creation of Trigger in GTM

Select Triggers from the left side panel of your page.

"Triggers" in GTM Panel

"Triggers" in GTM Panel

In the trigger creation page, select Custom Event. Add the event name as zargetData.

Trigger Creation Page

Trigger Creation Page

Click Create Trigger button. Now, the data collected will be transferred to GA upon firing this custom event or trigger.


Creation of Tag For GA in GTM

This step sends all the information collected from the running A/B test experiment to GA.

Choose Google Analytics and Universal Analytics in tag type section.

Add the Tracking ID that is found in your GA admin Panel under Property settings.

Add the event name that you created previously in Category.

Add the correct dimension value and index from the drop-down menu.

Creating Tag For GA in GTM

Creating Tag For GA in GTM

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

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

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

Zarget GA and GTM Integrations

Freshmarketer GA and GTM Integrations

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