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
5.) NEW – Salesforce integrates with Google Analytics 360 and sends back Lead/Opportunity Changes

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.

Method #5: Integrate Google Analytics and Salesforce

Announced in 2018, Salesforce and Google Analytics 360 have teamed up to make this process even easier! In a nutshell, connect your Google Analytics 360 account to your Salesforce account and make a small number of changes on your website to enable this feature, included with the with your Google Analytics 360 license. Once that’s finished, Salesforce will send data back to Google Analytics, importing changes to Leads and Opportunities and connecting to the original user that submitted a lead/contact form.

Take a look at our Google Analytics 360 and Salesforce Integration post which describes this process in full detail.

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 former LunaMetrician and contributor to our blog.

  • 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!


  • Micqey

    I think I’m understanding this incorrectly, but it sounds to me like the first method (or something like it) would be kind of a prerequisite to the other three methods because some kind of GA readable identification is going to have to be passed in to salesforce if we want to get data about that Lead throughout the business process as records are manually updated. . .

    Setting up a salesforce trigger to notify GA about actions taken in salesforce doesn’t do any good without a UserID does it? Am I missing something here, or is the first method somehow subsumed into the others?

    • Dan Wilkerson

      Nope, you’re correct – all of these methods require some universal key, which necessitates sending the Client ID in with any form field to Salesforce.

      I left that part out intentionally as I wanted to stay out of the weeds for this post. I was worried I’d have to go into detail about Salesforce forms, hidden fields, and Client IDs, but your comment has prompted me to reconsider. I think I might add a warning about that above the rest of the post; I can see why missing that information, things could be confusing.

      Thanks for commenting!


  • Very nice and helpful insight.

  • Yanir Calisar

    Great article.
    Check out which automates this process of syncing Salesforce data with Google Analytics.
    It tracks more than 40 types of online & offline identifiers and leverages machine learning to resolve them back into people across devices and channels. Then, it syncs any new/updated lead data every few hours, even without using emails.
    It’s 100% hands-free and no coding or training are required.

  • Gnosis Media Group

    This is above my paygrade. @disqus_ZlOkX51Bk6:disqus , any chance I could call you and have you do this for our org? I’m amazed there’s not a simpler way to do this or that someone hasn’t built an API to do this already.

  • thanks for the article. you forgot to write new articles about the topic 🙂 it would be awsome if you could help further! thanks again for your great post!

Contact Us.

Follow Us



We'll get back to you
in ONE business day.
Our Locations
THE FOUNDRY [map] LunaMetrics

24 S. 18th Street
Suite 100

Pittsburgh, PA 15203


4115 N. Ravenswood
Suite 101
Chicago, IL 60613


2100 Manchester Rd.
Building C, Suite 1750
Wheaton, IL 60187