Integration of Salesforce with Google Analytics

Integration of Salesforce with Google Analytics

What is Google Analytics?

Google Analytics is a web analytics service that provides statistics and basic analytical tools for search engine optimization (SEO) and marketing purposes. The service is part of the Google Marketing Platform and is available for free to anyone with a Google account.

Benefits of Google Analytics:

  • It can improve online ads with the use of marketing analytics.
  • It can understand your Target Customers.
  • It tracks your goals as well as online traffic.
  • It has in-built data reports and the option to customize reports according to your KPIs.
  • Suggestions for better performance improvisation.

What can Google Analytics and Salesforce Integration Do For You?

The aim of marketing is to drive revenue and Google Analytics is good for measuring sales that happened on the website, e.g. an e-commerce site, but most businesses don’t work this way. Sales are often closed by sales reps and only tracked in Salesforce or some other CRM software. If you capture specific things about what your customers do on your website, then you’re becoming limited, you may be missing how many of your website visitors actually became paying customers.

Why do integrate Salesforce with Google Analytics?

  • It offers a wealth of extra data to help enrich your marketing and lead generation. We found that 37% of marketers found generating high-quality leads to be one of their biggest challenges.
  • It can help you analyze the visitor’s behavior and how they are interacting with your business. If you have this kind of setup, it’s already pretty slick, and you can effortlessly get customer inquiries for your product or service. 
  • To get exactly which marketing channels are generating high-quality leads.
  • This integration gives you a 360 view of your marketing campaigns.
  • It will be useful to see any trends across a certain time frame. With the help of data collected in GA, you can also check which campaign has been most efficient and plan for future marketing campaigns. These answers are impossible to answer without connecting your Salesforce Lead & Opportunity data, with Google Ads.

Steps for Integration of Salesforce to Google Analytics:

Step-1 : Decide how to identify your users

Google Analytics offers you 2 ways to identify your users: Client ID and User-ID. To support Data Import for Salesforce Sales Cloud, you must implement Client ID. You may optionally choose to also implement User-ID.

Client ID:- identifies a browser instance. This is a cookie-based identifier created automatically by an Analytics-enabled site on a user’s first visit. Identifying users with Client ID is best suited for businesses focused on lead generation and new customer acquisition. Apps or sites for this type of business are typically having low rates of user authentication and retention.

User ID:- enables the analysis of groups of sessions, across devices, using a unique, persistent, and non-personally identifiable ID string representing a user. This option is best for businesses with high rates of logged-in users. Implementing User-ID requires some additional setup and code on your site:

Step-2 : Required Salesforce Sales Cloud objects and fields

For the setup of the Analytics Salesforce Sales Cloud integration, you should have full access to the following Salesforce objects and their fields.

ObjectsRequired Fields
OpportunityLineItemAll fields
Product2 (Products)All fields
Pricebook2 (Price Books)All fields
Step-3 : Create new custom fields in Salesforce Sales Cloud

You must have to create all the below 3 fields, no matter which tracking method you decided. Field names must be in uppercase. You can give any field names you want, and make these fields read-only to avoid unwanted changes. And these fields should be created on both the Lead and Opportunity objects.

Field NameAPI NameLength
Step-4 : Configure the Lead and Opportunity objects

For the both Lead and Opportunity object, enable Field History Tracking for the “Lead Status” and “Stage”. It will track the history if any update to these fields is happened.

Also, Map the Lead fields for the conversion to the respective fields in other objects:

  • Lead.GACLIENTID to Opportunity.GACLIENTID
  • Lead.GAUSERID to Opportunity.GAUSERID
  • Lead.GATRACKID to Opportunity.GATRACKID
Step-5 : Edit your lead form

Now you have to do changes in your lead form to capture and store the tracking information.

Also, you have to know your Analytics tracking ID.

Add the Custom Tracking Fields:-

Below is an example which shows how you can add custom fields to your lead form using JavaScript.

<form action="" name="myForm">
    Phone: <input type="text" name="phone_number">
    <input type="hidden" id="GACLIENTID" name="GACLIENTID" value="">
    <input type="hidden" id="GAUSERID" name="GAUSERID" value="">
    <input type="hidden" id="GATRACKID" name="GATRACKID" value="XX-XXXXX-XX">
    <input type="submit">

You can remove the GAUSERID line if you are only using a Client ID.

To set the tracking ID, replace XX-XXXXX-XX it with your Analytics tracking ID. Alternatively, you can retrieve the tracking ID dynamically using this code:

<script type=”text/javascript”> 
    ga(function() { 
      var tracker = ga.getAll()[0];
      var trackingId = tracker.get('trackingId');

Then replace the hard-coded tracking ID (XX-XXXXX-XX) with the trackingId variable.

Set the custom tracking field values:-
Add this code to your lead form to populate the Client ID and User-ID values.

<script type="text/javascript">
    'submit', function(event) {
      ga(function() { 
        var tracker = ga.getAll()[0];
        var clientId = tracker.get('clientId');
        document.getElementById('GACLIENTID').value = clientId;
        var userId = tracker.get('userId'); 
        document.getElementById('GAUSERID').value = userId; 
Step-6 : Link Analytics to your Salesforce Sales Cloud account

You need to link Analytics to your Salesforce Sales Cloud account by creating a new Data Import data set and then by authorizing access to your Salesforce Sales Cloud account.

Create a Salesforce Sales Cloud data set:-

  1. Sign in to Google Analytics.
  2. In the bottom left, click Admin, and navigate to the property to which you want to link. You must have the Editor role for this property.
  3. In the PROPERTY column, click Data Import.
  4. Click CREATE.
  5. For Data Set Type, under CRM Data, select Salesforce.
  6. Read and accept the Additional Terms for Analytics Salesforce Sales Cloud Data Import.
  7. Under Data Set details, name your data, then click Continue. The Data Source details panel appears.

Click the current credentials to see a list of all your successfully created Salesforce credentials. To remove unused credentials, on the right, click X. If the credentials are currently in use, you must disable those before you can remove them.

Authorize Salesforce Sales Cloud:-

  1. In the Data Source details panel, under Salesforce credentials, select Create new authorization.
  2. Enter a Credentials name to reuse.
  3. Click Access
  4. In the Salesforce pop-up, log in to your Salesforce Sales Cloud account. Once you’ve successfully logged in, the link to Analytics is complete. The new credentials name appears in the Salesforce credentials drop-down menu.

Tracking fields setup:-

In the Tracking fields setup panel, it lets you map your configured Salesforce fields to the corresponding Analytics Tracking IDs. For each Tracking ID in use, select the corresponding Salesforce custom fields.

Once the configuration of the tracking fields is completed, click Continue.

Step-7 : Configure the Salesforce milestones to import

Here you will select the Salesforce lead and opportunity milestones to import. You also need choose how often to import them.

  1. In the Data Source details panel, under Milestones Selection, use the drop-down menus to select the milestones you want to import.
  2. Click Continue.

Attribute and Product data setup (optional) :-

Attribute data import allows you to import user attributes from custom fields and selected standard fields from your Salesforce Lead and Opportunity objects. You select the Analytics custom dimensions and custom metrics that will store this data.

Product data import allows you to import product data from your Salesforce account. This data is imported as part of the same Measurement Protocol hit as your milestone data.

While optional, importing attribute and product data is recommended, as it enables a wide variety of new audience targeting and analysis use cases.

Standard supported fields:-

You can import attributes from the following standard Salesforce Lead and Opportunity fields:

Opportunity FieldsLead Fields
ExpectedRevenueScoreIntelligenceId (if available in your Salesforce Edition)

Example configuration:-

Below is an example of a supported standard Salesforce fields and Analytics custom fields mapping,

Analytics custom field: scopeSalesforce field name
Dimension: session OR userLead: Lead ID
Dimension: session OR userLead: Lead Score (Salesforce Einstein predicted score)
Dimension: userLead: Industry
Dimension: session OR userLead: Rating
Dimension: session OR userOpportunity: Opportunity ID
Metric: hitOpportunity: Amount
Dimension: session OR userOpportunity: Probability (%)
Metric: hitOpportunity: Expected Amount
Dimension: session OR userOpportunity: Order Number

Supported formats:-

You can import all custom attribute fields with the following Salesforce field formats:

booleandateTime (camelCase)

To import attributes:-

  • Select the Analytics custom dimensions and/or custom metrics that you want to contain the attribute data.
  • Make sure that the selected custom dimensions have the correct scope. In most cases, this will be user scope.
  • Use the drop-down menu in the Salesforce field name column to map the Analytics fields to your Salesforce fields.​
Step-8 : Enable product data import

To enable product data import, you should have following configuration:

  • Product data is configured in your Salesforce account.
  • At least one view in the current Analytics property has Enhanced ecommerce enabled.

And then you can enable product data import by following the steps:-

  1. Below the attribute import table, click Enable Product data import.
  2. You can then review the field mapping between Salesforce product data and your Analytics Enhanced E-commerce fields.

Data Source schedule:-

Use this option to set up the import frequency.

  1. Click Continue.
  2. Click Done.

Note:- Fetching the data every hour for the highest freshness, accuracy, and availability.

Step-9 : Test Your Setup

In the final step, you can test your configuration by importing some data and check it in an Analytics report.

Import data
  1. If necessary, return to the Data Set list page:
    1. Sign in to Google Analytics.
    2. In the bottom left, click Admin, and navigate to the property that contains your Salesforce Sales Cloud data source.
    3. In the PROPERTY column, click Data Import.
    4. The Data Set list page appears.
  2. Locate the data set you created in the previous steps.
  3. On the right, click Manage uploads.
  4. In the Uploads for Salesforce Offline Conversions page, click More > Fetch Now.

This will upload your Salesforce data to Analytics. If the upload is successful, the Status show as “Completed.” If an error occurs, the Status show as “Failed” with a link to display more details.

In the top right corner, you can also check whether your Salesforce Data Set is scheduled for automated imports.

View imported data in a report:-
To view imported milestones
  1. Navigate to the BEHAVIOR > Events > Top Events report.
  2. Adjust the time window to include your uploaded data.
  3. Apply a Secondary Dimension of Event Label

If your Salesforce milestones have been successfully imported, they should now appear in your report.

To view imported attributes:-

To check imported attributes in any Analytics report, add the custom dimensions you’ve mapped in the configuration steps as secondary dimensions.

To view imported product data:-

To see imported product data, use Conversions > Ecommerce > Sales Performance or Conversions > Ecommerce > Product Performance reports. Adjust the time frame to verify the imported product data. For example, if you started importing data today, make sure your report time frame includes “today.”

Product data is imported with Opportunity milestone events. It may take additional time before a lead is converted to an opportunity in your Salesforce account.