Note that this Google Analytics Integration is deprecated. Use the newer Google Universal Analytics Integration instead. For details, see:

Developer Help Centre > Google Analytics Integration

Integrating Maxymiser with Google Analytics

Integrating with Google Universal Analytics allows you to send campaign information so you can later filter your analytics by campaign experience.

This article explains how to:

  • Integrate a Maxymiser campaign with Google Universal Analytics
  • Validate and QA the integration for a campaign

How we send the data?

This integration populates a custom dimension with the relevant campaign experience information. For multiple campaigns, the data that is sent across is concatenated so that we do not overwrite any previous campaign data that was sent to the custom dimension.

We recommend setting the dimension scope to "User" level, and where possible to use different custom variables for each tested campaign.

<mode>_<campaignName>=<element1Name>:<variantName>|<element2Name>:<variantName>

The data is capped at 150 characters, as advised by Google Universal Analytics. If the collective campaign data surpasses the character limit then the first generated campaign gets taken out.

Prerequisites

The following information needs to be defined before you apply the integration:
  • Google Analytics Account ID
  • Google Analytics Custom Dimension
  • Google Analytics Dimension Name

Integration Implementation

The Maxymiser integration with Google Analytics is based on 3 separate scripts. Follow the steps described under "Configure sample integration for a campaign" heading in the Integrations Overview article to set up the integration.

  1. Integration Module (Site Script, take from Step 1);

  2. Google Analytics register (Site Script, use for Step 2);
    // Google Universal Analytics integration v1.0.5 !function(){var a={version:"1.0.5",campaignRequired:!0,validate:function(a){return a.dimension?b.isDimension(a.dimension)?!0:b.errors.invalidDimension(a.dimension):b.errors.missingDimension},check:function(a){var b=window[a.gaVariable]||window[window.GoogleAnalyticsObject]||window.ga;return b&&"function"==typeof b.getAll},timeout:7e3,exec:function(a){return b.send(a)}},b={errors:{missingAccount:"Missing Google Universal Account Number",invalidAccount:function(a){return"Invalid Google Universal Account Number provided ["+a.toString()+"]"},missingDimension:"Missing Google Universal Dimension",invalidDimension:function(a){return"Invalid Google Universal Dimension provided ["+a.toString()+"]"}},send:function(a){var c=a.isProduction?"MM_Prod":"MM_Sand",d=window[a.gaVariable]||window[window.GoogleAnalyticsObject]||window.ga,e="";if(a.campaignExperience=a.campaign.getName()+"="+a.campaignExperience,a.persist&&(a.campaignExperience=b.getPersist(a).campaignInfo),a.account)e="mm_"+a.account.replace(/\W/g,""),d("create",a.account,"auto",{name:e}),d(e+".set","dimension"+a.dimension,a.campaignExperience),d(e+".send","event",c,a.campaignExperience,a.campaignExperience,{nonInteraction:1});else{for(var f,g=d.getAll(),h=g.length;h--;)f=g[h].get("name"),/^gtm/.test(f)&&(e=g[h].get("name")+".");d(e+"set","dimension"+a.dimension,a.campaignExperience),d(e+"send","event",c,a.campaignExperience,a.campaignExperience,{nonInteraction:1})}return!0},getPersist:function(a){var b={maxDataSize:150,cookieName:"mm-if-site-persist-ua-"+a.dimension},c={campaign:a.campaign.getName(),campaignInfo:a.campaignExperience},d=function(a){var b;for(b=a.length;b--;)if(new RegExp("("+c.campaign+")=").test(a[b]))return b;return-1},e=function(){var a=f(b.cookieName),e=a?JSON.parse(a):[],g=d(e);return-1!==g?e[g]=c.campaignInfo:e.push(c.campaignInfo),e.join("&")},f=function(){return cookies.get(b.cookieName)},g=function(a){var c=a.split("&");cookies.set(b.cookieName,JSON.stringify(c),{expires:365})},h=function(a){for(var c=a.split("&");;){if(!(c.join("&").length>=b.maxDataSize))return c.join("&");c.shift()}},i=function(a){c.campaignInfo=a};return function(){var a=e();return a=h(a),i(a),g(a),c}()},isAccountNumber:function(a){return a&&/^UA\-\d{5,}\-\d{1,3}$/.test(a.toString())},isDimension:function(a){return a&&a>0&&200>=a}};"object"==typeof modules&&"function"==typeof modules.define&&modules.require("Integrations").register("Google Universal",a)}();
  3. Google Analytics initialize (Campaign Script, use for Step 3)
    Integrations.run("Google Universal", { campaign: campaign, // do not change this account: 'UA-1234567-8', // ga account id dimension: 'dimension index', // ga dimension persist: true // change to false if you want to pass individual experience data for a campaign instead of concatenating all the campaigns' experiences });

QA the Integration

Install the Google Analytics Debugger extension for Chrome and navigate to the page where the campaign is running.

Enable the plugin to capture the data sent to Universal Universal:

Google Analytics Debugger icon

Open Chrome Developer Tools Console:

Google Analytics Debugger output in console
Note: Check if multiple experiences are being correctly collected (concatenated in one string) and the ga* cookies are only set against one domain in campaigns that are running on sub-domains. It is also recommended to validate that both *Account ID* and *Visitor ID* are equal on pages with and without tested campaigns (these are exposed in the Debugger console output).