[UA] Configure the Google Analytics Salesforce Sales Cloud integration

Learn how to set up Data Import for Salesforce Sales Cloud data.
This feature is only available in Analytics 360, part of Google Marketing Platform.
Learn more about Google Marketing Platform.

You must have the Editor role for the Analytics property you'll use for this integration.

The code samples in this article are provided as reference. Your specific implementation details may require additional code or different approaches.

In this article:

Decide how to identify your users

Analytics offers 2 ways to programmatically 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 pseudonymously identifies a browser instance. This is a non-authenticated, cookie-based identifier created automatically by a 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 customers acquisition. Apps or sites for this kind of business typically have 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:

  1. Activate the User-ID feature in your Analytics property
  2. Add the User-ID to your lead form page and any other pages you want to track. You can do this via Google Tag Manager or a JavaScript variable.

Learn more about Cookies and User Identification in the Analytics Developers Guide.

Use of the User-ID feature is subject to the Measurement Protocol / SDK / User-ID Policy.

Required Salesforce Sales Cloud objects and fields

To setup the Analytics Salesforce Sales Cloud integration, you must have full access to the following Salesforce objects and fields. A Salesforce user account with System Administrator access may already have access to these fields.

In addition, be sure to grant Modify All Data permission to the user who is linking your Salesforce and Analytics accounts. This is required by the Salesforce Metadata API to enable Google to fetch Lead conversion settings data. This integration does not modify your Salesforce account and the Metadata API is used in a read-only capacity.

User accounts with limited access to leads or opportunities may not have sufficient access to the data you want to import. For example, a Sales Representative account may only be able to see data for limited geographies or opportunities, and so should not be used to link Analytics and Salesforce.

Show me the list of required fields

Object Required Fields






























OpportunityLineItem All fields
Product2 (Products) All fields
Pricebook2 (Price Books) All fields

* Custom fields created in step 3 below.

If you use Salesforce Group Edition or Professional Edition, field access is granted by adding the necessary fields to your Lead and Opportunity page layouts. Learn more about setting page layouts and field-level security in Salesforce.

Create new custom fields in Salesforce Sales Cloud

Following these instructions , create 3 custom fields in Salesforce to store the Analytics tracking codes.

You can name your fields as you like. The ones below are just examples.
Field Name API Name Field Length


You MUST create all 3 fields, no matter which tracking method you decided on in step 1.

Field names MUST be uppercase. Field labels can be whatever you want.

Make these fields read-only to prevent unwanted changes.

These fields MUST be created in both the Lead and Opportunity objects.

Configure the Lead and Opportunity objects

For the Lead object, enable Field History Tracking for the Lead status field. For the Opportunity object, enable Field History Tracking for the Stage field. This will ensure that any update to these fields will generate a hit event.

Map the fields in each object to their counterpart in the other object:

  • Lead.GACLIENTID to Opportunity.GACLIENTID
  • Lead.GAUSERID to Opportunity.GAUSERID
  • Lead.GATRACKID to Opportunity.GATRACKID

Edit your lead form

In this step, you'll modify your lead form to capture and store the required tracking information. You'll need to know your Analytics tracking ID.

Why is my tracking ID required?

Including your Analytics tracking ID allows you to distinguish data imported from multiple lead forms, across various sites tracked with different Analytics accounts, all passed to a single Salesforce Sales Cloud account. This wouldn't be possible using only Client ID and/or User-ID.

Add the custom tracking fields

The following examples show how you might add the custom fields you created above 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="UA-XXXXX-YY">
    <input type="submit">

The sample code above adds both Client ID and User-ID to your form. You can remove the GAUSERID line if you are only using Client ID.

To statically set the tracking ID, replace UA-XXXXX-YY 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 (UA-XXXXX-YY) with the trackingId variable:

    <input type="hidden" id="GATRACKID" name="GATRACKID" value=trackingID>

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; 

In this step, you'll 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 them 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 Salesforce.com.
  4. In the Salesforce pop-up, login 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.
To import data from different Salesforce accounts, repeat the steps above to create multiple credentials sets.

Tracking fields setup

The Tracking fields setup panel 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.

If you don't see an expected custom field in the list, check to make sure it has been properly configured and mapped across both Lead and Opportunity objects in your Salesforce account.

If the selected Salesforce fields already include some data, you can click Preview values to make sure that data looks right. This allows you to check the accuracy of your configuration. For example, you can see whether or not the Tracking IDs are in the proper format.

After configuring the tracking fields, click Continue.

Configure the Salesforce milestones to import

In this step, you'll select the Salesforce lead and opportunity milestones to import. You'll also choose how often to import them.

Milestones are imported as Analytics events. You can import both default and custom lead statuses and opportunity stages.
  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 fields:

  • Id
  • Industry
  • NumberOfEmployees
  • Rating
  • ScoreIntelligenceId (if available in your Salesforce Edition)

You can also import the following standard Opportunity fields:

  • Amount
  • CampaignId
  • ContractId
  • ExpectedRevenue
  • Id
  • LeadSource
  • Name
  • Probability
  • TotalOpportunityQuantity

Supported formats

In addition to the standard fields listed above, you can import all custom attribute fields with the following Salesforce field formats:

  • boolean
  • currency
  • date
  • datetime
  • dateTime (camelCase)
  • double
  • int
  • percent
  • picklist
  • string
  • textarea
  • time

To import attributes:

  1. Select the Analytics custom dimensions and/or custom metrics that you want to contain the attribute data.
  2. Make sure that the selected custom dimensions have the correct scope. In most cases, this will be user scope.
  3. Use the drop-down menu in the Salesforce field name column to map the Analytics fields to your Salesforce fields.​
If the selected Salesforce field already includes some data, you can click Preview values to make sure that data looks right. This allows you to check the accuracy of your configuration.

Example configuration

Here is an example of a supported standard Salesforce fields and Analytics custom fields mapping.

Analytics custom field: scope Salesforce field name
Dimension: session OR user Lead: Lead ID
Dimension: session OR user Lead: Lead Score (Salesforce Einstein predicted score)
Dimension: user Lead: Industry
Dimension: session OR user Lead: Rating
Dimension: session OR user Opportunity: Opportunity ID
Metric: hit Opportunity: Amount
Dimension: session OR user Opportunity: Probability (%)
Metric: hit Opportunity: Expected Amount
Dimension: session OR user Opportunity: Order Number

Which scope should I use?

Whether you use session or user scope for your custom dimensions depends on your business model. For example, if you sell multiple types of products, and are gathering multiple lead forms per user, a session scoped custom dimension works better than a user scoped dimension, because a user scoped dimension will be overwritten by subsequent leads for that user.
You should apply this same consideration to all of the Salesforce fields listed in the example above, as well as any other custom fields you wish to import.
Also, keep in mind that custom metric values are aggregated as new hits for a given user identifier are received.

Enable product data import

To enable product data import, both of the following must be true:

  • Product data is configured in your Salesforce account.
  • At least one view in the current Analytics property has Enhanced Ecommerce enabled.
You should only enable Salesforce product data import in Analytics if you're sure that the product setup in your Salesforce account is correct. There are no configuration options in Salesforce product data import. If product data import fails, please double check your product setup in Salesforce.

To enable product data import:

  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 Ecommerce fields.

Data Source schedule

Use this option to set up the import frequency.

Fetching the data every hour ensures the highest freshness, accuracy, and availability.
  1. Click Continue.
  2. Click Done.

Test your setup

In this final step, you'll test your configuration by importing some data and view 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 attempt to upload your Salesforce data to Analytics. If the upload is successful, the Status column will show "Completed." If an error occurs, the Status column shows "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

Importing offline hits can take up to 26 hours before they are available in reporting.

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.

Use the Data Source dimension to distinguish imported hits from standard hits collected by Analytics. Hits imported from Salesforce Sales Cloud appear as sfsc.

To view imported attributes

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

To view imported product data

To see imported product data, use the 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.

Notes and limits

  • Make sure you abide by the Analytics Terms of Service and Privacy Policy.
  • Don't import personally identifiable information (PII).
  • Imported data uses the currency (or currencies, if you have multi-currency enabled) set up in your Salesforce account.
  • Salesforce product data is imported to the Opportunity object, not Lead data.
  • Empty fields are removed from the Measurement Protocol hit at the time of import. Those fields won't be imported to that particular custom dimension or metric in that hit.
  • Measurement Protocol hits can't exceed 8192 bytes (the standard Analytics hit size limit).
  • Your imported data must not contain commas. That's because the Measurement Protocol event hits are imported as a comma-separated values (CSV) file, so commas in your imported values will be seen as separators, causing unpredictable results.
  • Enhanced Ecommerce is limited to 200 unique product indexes.
  • Roll-up properties are supported to the same extent that Measurement Protocol hits are supported.

Was this helpful?

How can we improve it?
Choose your own learning path

Check out google.com/analytics/learn, a new resource to help you get the most out of Google Analytics 4. The new website includes videos, articles, and guided flows, and provides links to the Google Analytics Discord, Blog, YouTube channel, and GitHub repository.

Start learning today!

Clear search
Close search
Google apps
Main menu