Configure the Google Analytics Salesforce Sales Cloud integration
You must have Edit permission 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.
- Decide how to identify your users
- Required Salesforce Sales Cloud objects and fields
- Create new custom fields in Salesforce Sales Cloud
- Edit your lead form
- Link Analytics to your Salesforce Sales Cloud account
- Configure the Salesforce milestones to import
- Attribute and Product data setup (optional)
- Data Source schedule
- Test your setup
- Notes and limits
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 anonymously 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:
- Activate the User ID feature in your Analytics property
Learn more about Cookies and User Identification in the Analytics Developers Guide.
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 permissionto the user who is linking your Salesforce and Analytics accounts.
Show me the list of required 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.
|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?
Add the custom tracking fields
<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"> </form>
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:
Then replace the hard-coded tracking ID (
UA-XXXXX-YY) with the
<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.
Link Analytics to your Salesforce Sales Cloud account
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
- Sign in to Google Analytics.
- In the bottom left, click Admin, and navigate to the property to which you want to link. You must have Edit permission for this property.
- In the PROPERTY column, click Data Import.
- Click CREATE.
- For Data Set Type, under CRM Data, select Salesforce.
- Read and accept the Additional Terms for Analytics Salesforce Sales Cloud Data Import.
- 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
- In the Data Source details panel, under Salesforce credentials, select Create new authorization.
- Enter a Credentials name to reuse.
- Click Access Salesforce.com.
- 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.
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 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.
- In the Data Source details panel, under Milestones Selection, use the drop-down menus to select the milestones you want to import.
- 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:
- ScoreIntelligenceId (if available in your Salesforce Edition)
You can also import the following standard Opportunity fields:
In addition to the standard fields listed above, you can import all custom attribute fields with the following Salesforce field formats:
- dateTime (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.
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?
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.
To enable product data import:
- Below the attribute import table, click Enable Product data import.
- 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.
- Click Continue.
- 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.
- If necessary, return to the Data Set list page:
- Locate the data set you created in the previous steps.
- On the right, click Manage uploads.
- 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
To view imported milestones
- Navigate to the BEHAVIOR > Events > Top Events report.
- Adjust the time window to include your uploaded data.
- 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 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
Don't import personally identifiable information (PII).
Multi-currency support is enabled for imported data if your Salesforce account is set up to use that option. Otherwise, all imported data uses the single currency 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.