« »
Jun 28
2013

*****UPDATED ARTICLE 10/15/2014: Integrate Universal Analytics with SalesForce!

salesforce google analytics integrationYou have several tools and channels: Paid Campaigns (Google Adwords), Google Analytics and Salesforce.  All are robust and tell you different details about the behavior of your leads/prospects.  Google Analytics has an overall view about your visitors (qualified and unqualified leads), while Salesforce has detail about each individual lead.

Until now, these views are looked at separately.  Wouldn’t it be powerful to be able to combine them into one comprehensive full 360 view of your leads?  To be able to find out where they went, how they converted, then optimize for that conversion to get more leads???

The only code for Salesforce integration that existed used to be for Google AdWords.   Even that has since been retired as of May 1, 2013 (read more about it here).

In this post, we hope to provide code that integrates Salesforce and Google Analytics, which not only replaces the Adwords integration, but will work with any of your marketing channels and campaigns.

Why Integrate Salesforce with Google Analytics?

Google Analytics has very rich reporting capabilities for conversion tracking. For example, you can define a goal by simply identifying a unique URL of the thank you page for any form on your website. And if one doesn’t exist, you can even “fake it” by creating virtual pageviews or events. This will allow you to analyze the number of conversions you receive, where they came from, and other user behaviors about visitors who convert.

Salesforce is “the name” in sales funnel reporting. Each time a lead submits information through forms on your website, through integration with Salesforce (or through manual entry from your sales representatives) other information about the leads can be entered and tracked.

But both tools alone might have missing pieces. In Google Analytics, how many of my conversions are spam or unqualified leads? In Salesforce, what information or pages were my leads looking at that got them to convert? Are search engines a primary source of converting traffic? Etc.

Google Analytics and Salesforce each have a place in helping analyze how to improve your sales funnels and the quality and quantity of your leads. Combining the two can really give you powerful insights to act upon.

In this post, we’ll show you how to pass Google Analytics information to Salesforce, then cover advanced integrations, such as passing unique keys that will allow you to tie visitors between Google Analytics and Salesforce. From there, you can get “first touch” campaign information.

Implementation (The Code)

The code below will allow you to improve your reporting by passing the traffic source information into Salesforce every time a form is submitted.

  1. Setup the following 5 fields in Salesforce:
    • Medium
    • Source
    • Campaign
    • Content
    • Term

    Here’s sample code (“xxxxxxx” represents the database id/api name of the custom field, depending on your salesforce mapping):

    <input type="hidden" name="txt_medium" id="xxxxxxx" value="" />
    <input type="hidden" name="txt_source" id="xxxxxxx" value="" />
    <input type="hidden" name="txt_campaign_name" id="xxxxxxx" value="" />
    <input type="hidden" name="txt_term" id="xxxxxxx" value="" />
    <input type="hidden" name="txt_content" id="xxxxxxx" value="" />
    
  2. Update all forms to contain the same 5 fields created in step 1 (they should be hidden so they aren’t shown to the user).
  3. Values for the hidden fields can be read from the GA cookie __utmz. The code below will parse out the campaign variables from the GA cookies and make them available in 5 variables.
  4. Logic should be put in place within the form to pass the values of the hidden fields to their corresponding fields within Salesforce when the form is submitted.
  5. Place the following code on every page on your website that has a Salesforce form before the closing </body> tag.
<script type="text/javascript">
var z = _uGC(document.cookie, '__utmz=', ';');
var source = _uGC(z, 'utmcsr=', '|');
var medium = _uGC(z, 'utmcmd=', '|');
var term = _uGC(z, 'utmctr=', '|');
var content = _uGC(z, 'utmcct=', '|');
var campaign = _uGC(z, 'utmccn=', '|');
var gclid = _uGC(z, 'utmgclid=', '|');
if (gclid !="-") {
 source = 'google';
 medium = 'cpc';
}

var csegment = _uGC(document.cookie, '__utmv=', ';');
if (csegment != '-') {
 var csegmentex = /[1-9]*?\.(.*)/;
 csegment = csegment.match(csegmentex);
 csegment = csegment[1];

} else {
 csegment = '';
}

function _uGC(l,n,s)
{
if (!l || l=="" || !n || n=="" || !s || s=="") return "-";
var i,i2,i3,c="-";
i=l.indexOf(n);
i3=n.indexOf("=")+1;
if (i > -1) {
i2=l.indexOf(s,i); if (i2 < 0){ i2=l.length; }
c=l.substring((i+i3),i2);
}
return c;
}

document.getElementById("txt_medium").value =medium; /* Campaign_Medium */
document.getElementById("txt_source").value =source; /* Campaign_Source */
document.getElementById("txt_campaign_name").value =campaign; /* Campaign_CampaignName */
document.getElementById("txt_term").value =term; /* Campaign_Term */
document.getElementById("txt_content").value =content; /* Campaign_Content */

</script>

After implementing this code you can test one of the forms on your site and this is what you should see in Salesforce:

Salesforce Google Analytics Fields

Success

Congratulations! You are now pulling reports in Salesforce and accurately determine what traffic sources are resulting in opportunities, qualified leads, and customers.  Now you have a more accurate understanding of the true ROI of your marketing activities.

(Keep in mind that when testing to clear your cache, cause any previous cookies or tags associated with your site will reflect in the form submission.)

The following is a report we have helped many of our customers work towards, which is mapping their Salesforce lead/customer data to their advertising spend.  This report shows the ROI and cost per qualified lead for each of their marketing channels.

salesforce google analytics marketing dashboard

A Note About Autotagging/AdWords

If you are trying to analyze the impact of your AdWords campaigns, you may notice that in Salesforce all of the Keywords, Content, and Campaign information is missing. This will happen if you have AdWords set to use autotagging. If this is the case, the default implementation provided above will not be able to pass anything more detailed, because the AdWords information is hidden in the GCLID, which is not decoded until later in Google Analytics.

If this information is important you have two options:

  • You can disable autotagging and use manual tagging
  • You can customize our code to accept customer parameters, which you can append to all of your destination URLS.

Advanced Implementations

Qualified Lead Behavior in Google Analytics
Marketers, get ready to have your mind blown! The number one question every business has is, “How can we get more business?” One of the keys to answering this question is to understand the common traits of your buyers. “How did we close you?” so we can do more of that.

With this integration, by associating a unique identifier with visitors in Google Analytics and passing that info to Salesforce, you can easily filter for this unique identifier (if you have goals set up) by using their built-in advanced segment of converting visits. What does that mean? That’s right, you’ll be able to see what your qualified leads did on your site!

But if your conversion is a form submission or contact email for example, what you cannot do though is create a segment of only your qualified leads or actual customers, as it will likely be filled with spam leads and non-qualified leads. We can solve this with a bit of code.

Our friend Justin Cutroni details in his blog post here how to store the unique ID that Google Analytics generates into a custom variable.  By reading the __utma cookie, we can extract this ID and send it to Google Analytics and also send this key into Salesforce. By placing this code on all Salesforce form pages on your site and passing it into both Google Analytics and Salesforce we will now have a key between the two systems to tie visitors together!

Now, in Salesforce you can create reports of qualified leads, customers, or any other customer grouping and extract these unique ID’s, then take these unique ID’s and create advanced segments for each of these groupings like so:

salesforce leads field custom variable

google analytics advanced segment custom variables

First Touch Attribution
Almost every Google Analytics report (except for Multichannel Funnels) is built on a last touch attribution model. Meaning, when you create reports or segments for converting elements, only the last traffic source is being tied to it. This is the same for our Salesforce / Google Analytics implementation that is provided above.

If you need insight on first touch campaigns and marketing channels, with some minor modifications, you can pass this along. Conceptually, this works best when you pass and store this information from the Google Analytics cookies into your database. Every time, that user re-authenticates and fills out a form, you can read this information from your backend and pass it into Salesforce using hidden fields.

Conclusion: 360 Customer View

The integrations mentioned above allow you to get closer to a 360 view of all of your customers and leads. By passing your visitors campaign and marketing channel information from Google Analytics into Salesforce, you will be able to report on the ROI and Cost Per Qualified Lead, which are two metrics every lead oriented business should have. By using the advanced implementations you can pass more information into Salesforce and create segments of your visitors based on information that is learned from them in Salesforce.

We have done many custom implementations of Salesforce and Google Analytics and with marrying both systems to other data sources.  The true power in it is architecting a solution that meets your needs. Feel free to contact me at: charles@e-nor.com if you have any questions or would like help working out a solution for your environment.

Tags:

5 Responses to “Integrate SalesForce and Google Analytics”

  1. John J. says:

    This is a great post, Charles. Thanks for the great insights!

    - John

  2. Stony Grunow says:

    Hi Charles

    Thanks for the great post! We looked into doing something like this, and I also wrote up a blog post on how to integrate Piwik Analytics with Salesforce.

    While both Piwik and Google Analytics can do a lot, eventually (responding to the End of Life of Salesforce’s SFGA that you mentioned) we wrote Daddy Analytics, which provides rich, detailed information about your Leads in Salesforce, allowing you to calculate marketing ROI. Would love to show you a demo sometime if you are interested.

    daddyanalytics.com

    thanks, Stony

  3. Claire says:

    Hi Charles

    We have recently managed to successfully integrate Google Analytics and Salesforce, your post was particularly useful, thanks. We don’t wish to disable auto tagging for adwords as we use the extra data that it provides in Google Analytics over and above the utm tagging. However, we would like to get the campaign and keyword data into salesforce. You mention customising your code to accept customer parameters to get around this. Are you able to expand on this at all?

    Thanks, Claire

  4. Lela says:

    Hey,

    Thanks for this article! It seems very useful further down the line but i have a question regarding the setup of the 5 fields. Now i made the fields on the lead object so i can use them when creating a web to lead form. But you mentioning output on the campaign object (send back via analytics) , should i make these fields on the campaign object as well?

    And how about the web to lead forms, i i have old campaigns can i just crate these 5 fields on a separate web to lead for and add the code to the old campaign, or is it needed to create a whole new web to lead form as a whole?

    Kind Regards,

  5. Bronwyn says:

    Thank you for this post, have found it so very useful.

    Does this script also work for Universal Analytics?
    If not, will you be doing a follow up post with an update
    of the script that is compatible with Universal Analytics?

    Cheers

Trackbacks

  1. Richer Insights For B2B Marketing With Google Analytics | Analytics Expert Blog
  2. Richer Insights For B2B Marketing With Google Analytics »
  3. Kilobuzz | Richer Insights For B2B Marketing With Google Analytics « KiloBuzz
  4. Richer Insights For B2B Marketing With Google Analytics « « EsheleDEsheleD
  5. Richer Insights For B2B Marketing With Google Analytics
  6. Richer Insights For B2B Marketing With Google Analytics | Bugdaddy
  7. Integrate Salesforce and Google Analytics &laqu...
  8. Integrating Google Analytics & HubSpot
  9. Integrating Google Analytics & HubSpot - Seo Company Reviews
  10. Integrating Google Analytics & HubSpot | Posts
  11. Integrating Google Analytics & HubSpot - insurance news online insurance news online

Leave a Reply