How To: Connect to Google Analytics


Google Analytics (GA) stores rich user behavior data. However, GAs Terms of Service require that no personally identifiable information be stored on their servers. In order to leverage GA data, we need to generate and store a random identifier with every GA event (random so that it complies with Google's TOS), and this identifier must also to be propagated into SF. This way, we can retrieve GA data, join it with leads/contacts to have a rich view of that lead/contact’s behavior on your website. The steps below will guide you through setting this up.

Step 1: Enable GA Tracking

Create a Custom Dimension to hold the identifier that Infer will generate. This identifier will enable Infer to join Google Analytics events with Salesforce records.

  • On in the Admin panel, choose the appropriate tracker and click on Custom Definitions
  • Select Custom Dimensions
  • Select the red button to create a new dimension
    • Name the new dimension podid
    • Set the scope to User
    • Check the Active box (if not already selected)


Figure 1. Creating a Custom Dimension


  • Once you press Create, you will see a page with example code to set the dimension. This page can be ignored, and you can select Done.
  • IMPORTANT: Send Infer the Index value (see example below where Index value = 1)

Figure 2. Index value associated with Custom Dimension

Step 2: Add Tracking Code to Webpages

There are 2 methods to add the tracking code to your webpages:

  • 2.1: Add Infer authored javascript to your webpage. Javascript will update if needed by Infer with no customer work required.
  • 2.2: Use the Google Tag Manager, however, any updates to the javascript must be updated by the customer within the Tag Manager.

2.1 - Infer’s javascript snippet

On your webpage, locate the javascript that creates the GA tracker. It will look like:

ga('create', 'UA-NNNNNNNN-N', '')

After the script block containing the line above, include the following snippet:

<script src=''></script>



IMPORTANT: The 1 value above should be replaced with the actual Index value for the Custom Dimension that you created in Step 1.

2.2 - Use Google Tag Manager

  • Create a new tag in GTM for Google Analytics


  • RECOMMENDED: Modify an existing tag to set the custom dimension to the value of our custom javascript as described below--an ideal tag to modify is a “Page View” tag

Figure 3. Using Google Tag Manager to enable tracking

  • Configuration settings if creating a new tag
    • Type = Event
    • Category = Infer (Recommended; this field is user defined so you can give it any value you prefer)
    • Action = Set Infer Tracking ID (Recommended; this field is user defined so you can give it any value you prefer)
    • Non-Interaction Hit = True (if False, bounce rate will drop to 0%)
  • Configuration settings for new and existing tags
    • Select More Settings > Custom Dimensions
    • Set Index equal to the value from Step 1
    • For Dimension Value, select + > New Variable > Custom Javascript
  • Custom javascript should be exactly as below, when asked to name the variable, use Infer Podid

function() {

 var infer = {};

 infer.getCookie = function(cname) {

   var name = cname + "=";

   var ca = document.cookie.split(';');

   for(var i=0; i<ca.length; i++) {

     var c = ca[i];

     while (c.charAt(0)==' ') c = c.substring(1);

     if (c.indexOf(name) == 0) return c.substring(name.length,c.length);


   return "";


 infer.setCookie = function(cname, cvalue, exdays) {

   var d = new Date();

   d.setTime(d.getTime() + (exdays*24*60*60*1000));

   var expires = "expires="+d.toUTCString();

   document.cookie = cname + "=" + cvalue + "; " + expires;


 infer.hex32 = function() {

   function hex4() {

     return Math.floor((1+Math.random()) * 0x10000).toString(16).substring(1);


   return hex4() + hex4() + hex4() + hex4() + hex4() + hex4() + hex4() + hex4();


 infer.podid = infer.getCookie('podid');

 if (infer.podid == '') {

   infer.podid = infer.hex32();

   infer.setCookie('podid', infer.podid, 365);


 return infer.podid;


Figure 4. Setting up custom tracking within Google Tag Manager


NOTE: If creating a new tag, set the Tag to fire on the desired pages. This likely will be “All Pages”, however, you will want to be careful here, as you will need to ensure that the Tag is only set on the domains and pages on which you want to track user behavior.

After ensuring that the Tag is going to be published only on relevant pages, you can press save and publish. Publishing will push the changes to the live website.

Step 3: Sync Custom Dimension Value into Salesforce

This step may vary depending on your environment:

  • If you are using Web-to-Lead functionality in Salesforce where form submits create leads in Salesforce, then you will need to create a field in Salesforce to hold "podid", and pass the value of the cookie named "podid" along with the form.
  • If you need to inject the value into an iframe, you can dynamically construct the iframe tag and pass in the value as a url parameter on the iframe's src, being careful to do this after the podid is generated.


Step 4: Grant GA API Access

The final step is to grant Infer API access to Google Analytics so we can pull event details and link them to leads in Salesforce.

4.1 - Provide Infer with View ID

When Infer pulls events from the Google Analytics’ API, it is pulling the events via a view/profile. Therefore, Infer needs there to be a profile without any filters defined on it -- we describe this as an “everything profile”.

Infer needs the ID of this "everything profile" to fetch events. The View ID for this profile can be found in the Admin panel of When you go to fetch it for the corresponding everything profile you should see the following:

Figure 5. Unfiltered View


Selecting the view settings will show a page with the ID required by Infer:

Figure 6. View ID required by Infer to fetch events


4.2 - Grant Infer OAuth Access

Infer will manually generate a URL for customers to authorize OAuth access. The OAuth page is a Google page which will alert the customer that Infer Profile Management wants read only access to your GA. Once you select Allow you will be redirected to an Infer server with a Success or Failure message.

NOTE: If for some reason the OAuth token must be refreshed, the first recommended course of troubleshooting is to go into your Google Accounts settings > Connected Apps and revoke access to the “Infer Profile Management” app.

NOTE: If you are using the Google Analytics API for any other high volume/high transaction use please let us know as we will be sharing the API quota with these other users. It will be helpful to know the use and volumes expected for the additional API users when contacting Infer.

Last Updated February 8th, 2016


Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request


Powered by Zendesk