Integrating Google Analytics and Salesforce – A 30,000 ft View


Salesforce is one of the most popular CRMs available today. Many teams use Salesforce heavily for reporting and analysis. The ability to model the data in Salesforce to fit any organization’s needs is particularly powerful. Many of our clients and Google Analytics training attendees use Salesforce and want to merge data it contains with their Google Analytics data. Thankfully, Salesforce offers a robust set of features to let us integrate the two. The requests I hear most often are:

  • Can I see Salesforce data in Google Analytics, e.g. Industry, Customer Type?
  • Can I see Google Analytics data in Salesforce, e.g. Source/Medium, Campaign Information, or Goal Completion data?

The good news is, you can! Here are four approaches we might take to do this:
1.) Adding hidden fields to carry in data to Salesforce
2.) Creating a custom Salesforce Trigger and sending the data to Google Analytics
3.) Periodically querying the Google Analytics API and sending that data into Salesforce
4.) Periodically querying the Salesforce API and sending that data into Google Analytics

Today, I’m going to cover four different models for sharing data between these services, as well as why you might like to do each.

Method #1: Adding Hidden Fields

This is the oldest-school way of bringing Google Analytics data into Salesforce: you add Custom Fields to one of your Objects, create a Web Form for that Object, and then populate those hidden fields using data about the user. When the form is submitted, the data is stored in Salesforce.

One of the most common ideas – use the data stored in the __utmz cookie to see the current user’s Source/Medium and Campaign information. If you’re using Universal Analytics, there are some hoops you’ll have to jump through: E-Nor has one method that may work for you, and I’ll discuss our method in a future post.

The hidden form field method is the simplest way to get Google Analytics attribution data into Salesforce, and also provides the simplest type of insights – essentially, last non-direct click attribution. For companies with longer sales cycles, this might not be the most useful data in the world, but for more demand-generation based folks, this can be super helpful. Again, with some customization, this pattern can be extended to provide more useful information for you to leverage. We’ll cover that in a later post.

Method #2: Creating A Custom Salesforce Trigger

Triggers are a feature in Salesforce that mimic triggers you might have used with a database software. Essentially, triggers are conditional rules that you can set up to fire when certain actions take place. This includes, in Salesforce, sending data to outside services. In this way, you can configure Salesforce to do really awesome things like:

  • Manage User IDs for your clients
  • Update user data in GA when important actions occur, e.g. a big sale closes
  • Fill in extra dimensions about users from your CRM into GA, like Industry or CLV

There are some limitations in terms of what Triggers can do – you can only use 10 @future calls (required for sending data to services outside Salesforce) per transaction, and you have a limit of 200 @future calls per Salesforce license, so you may need to be choosy about what you send into Google Analytics with these methods. There are great resources available on how to optimize your code to work within these limits.

This approach is great because you can get near-realtime updates to your Google Analytics data, which can help avoid any data quality headaches.

Method #3: Periodically querying the Google Analytics API and sending that data into Salesforce

Google Analytics has a robust and well-documented API for accessing data from your account. You can take advantage of this and create scripts or services that periodically poll Google Analytics for specific pieces of data, and then submit that data to Salesforce via the REST or Bulk APIs.

Salesforce has a handful of really interesting APIs for all different application needs, which you can check out here. In order to take advantage of these APIs, you’ll need to create a Custom App in Salesforce and build a service on your own server somewhere to orchestrate things.

This approach is how we can bring data from Google Analytics into Salesforce that maybe isn’t available when a form is submitted. For example, we may want to know the first source/medium of a particular visitor’s visit history. With a client- or user-specific key in Google Analytics, we could retrieve that data on a periodic basis and upload it to SalesForce for use in our CRM.

Method #4: Periodically querying the Salesforce API and sending that data into Google Analytics

Similar to Method #3, we can also pull data out of Salesforce using its APIs in order to upload that data to Google Analytics, either using the Measurement Protocol or programmatic Data Import. This method still requires a Salesforce app for authentication and a service on a server to orchestrate things.

This approach is how we can bring data into Google Analytics from Salesforce without using Triggers.

Interested in getting started? We can help. Get in touch with us about integrating your Salesforce and Google Analytics data today.

Is your organization sharing data between Salesforce and Google Analytics? Are you doing things differently? Share your models in the comments below.

Dan Wilkerson is a Software Engineer at LunaMetrics. He is passionate about web technology, measurement, and analysis. Dan is the winner of the 1999 Forge Road Elementary School Science Fair for his groundbreaking report on how magnets work. (ICP, take note.) Dan has worked at LunaMetrics in social media, as our marketing manager, and now in our analytics department.

  • Brian

    We are using Universal Analytics with Google Tag Manager. Can you discuss the hoops we have to jump through in order to set this up correctly? You mentioned E-Nor has one method that may work, but I’m curious to what your method is, if different.


    • Dan Wilkerson

      Hi Brian,

      It depends on the resources you have available and the data you’d like to collect. Ideally, you take option number #2, #3, or #4; any of those would allow you to query the actual source/medium stored in Google Analytics.

      Any other method (E-nor’s and our own included) is going to approximate what you’d see in the interface. Depending on the complexity of your deployment, the approximation may or may not be close to the reality of the data in Google Analytics. Even basic things about GA that will confuse the issue – for example, a Direct visit after a visit with a valid source/medium isn’t attributed to (direct) / (none), but the preceding source/medium, instead.

      Both methods boil down to moving the source/medium processing logic into the front end and appending that data to your Salesforce form. E-nor prescribes loading in the old ga.js library (last I checked) and sending a hit to a fake UA number in order to generate the UTMZ cookie. We prefer to use a script written in-house to generate a UTMZ-like cookie on our own, so as to avoid adding extra page weight and unforeseen side effects from ga.js. We don’t currently make that public, but we might at some point.

      For the processing flow chart, you can consult this help doc:

      Hope this helps!


Contact Us.


24 S. 18th Street, Suite 100,
Pittsburgh, PA 15203

Follow Us



We'll get back to you
in ONE business day.