In the web device mode integration, that is, using JavaScript SDK as a source, RudderStack loads the Google Analytics native SDK from the https://www.google-analytics.com/ domain.
Based on your website’s content security policy, you might need to allowlist this domain to load the Google Analytics SDK successfully.
Get started
Once you have confirmed that the source platform supports sending events to Google Analytics, follow these steps:
From your RudderStack dashboard, add the source. Then, from the list of destinations, select Google Analytics.
Assign a name to the destination and click Continue.
Connection settings
To successfully set up Google Analytics as a destination, configure the following settings:
Tracking ID: Enter the Google Analytics tracking ID from your Google Analytics dashboard. See FAQ for more information on obtaining the tracking ID.
Client-side Events Filtering: This setting lets you specify which events should be blocked or allowed to flow through to Google Analytics. For more information, see Client-side Events Filtering.
Enable Enhanced Link Attribution: Enable this setting to retrieve the detailed report of links clicked on your website. See Enhanced Link Attribution for more information.
Include the Querystring in Page Views: Enable this setting to include the query string in your page views along with the URL to be sent to Google Analytics. For more information on this feature, see Site search.
Custom Dimensions & Metrics: Enter the event name, traits, or properties you want to map to the corresponding custom dimensions and metrics. See Custom dimensions for more information.
Property & Trait Mapping: Enter the property you want to map to the Google Analytics content grouping. See Content groupings for more information.
Enable Server Side Identify: Enable this setting to trigger the identify calls from the server side.
Server Side Identify Event Category: Specify the event category of the identify call triggered from the server side. If you specify a category, it is sent as ec; otherwise, the default value is set to All.
Server Side Identify Event Action: Specify the event action of the identify call triggered from the server side. If you specify an action, it is sent as ea; otherwise, the default value is set to User Enriched.
Disable Md5 encryption from Client ID: Use this setting to determine how RudderStack should map the client id. For more information on this setting, see How RudderStack takes the clientId.
Anonymize IP Addresses: Enable this setting to anonymize the IP address at the earliest possible stage of the collection network. See IP Anonymization.
Enable Enhanced Ecommerce: Enable this setting to derive detailed insights for ecommerce events. See Enhanced ecommerce for more information.
Add the non-interaction flag to all events: Enable this setting to consider all event hits as non-interaction event hits. For more information on this feature, see Non-Interaction events.
Send user-id to GA: Enable this setting to set a user ID for the identified visitors before sending it to Google Analytics.
Use device-mode to send events: Enable this setting to send events to Google Analytics via the web device mode.
Track Categorized Pages: This setting is enabled by default and lets you track only the pages having a category associated with them.
Track Named Pages: This setting is enabled by default and lets you track only those pages that contain a name.
Sample Rate: Enter the percentage of users that RudderStack should track. The default value is 100.
Site Speed Sample Rate: Enter the sample size for Site Speed data collection. The default value is 1.
Reset dimensions on Page calls: Specify the dimensions (set in the page call properties) that need to be reset and assigned a new value.
Set Custom Dimensions & Metrics to the Page: This setting is enabled by default and passes the custom dimensions and metrics as properties for all events on a given page. When disabled, RudderStack only passes the custom dimensions and metrics as part of the event payload with which they are explicitly associated.
Use Named Tracker: Enable this setting to push events to the rudderGATracker Google Analytics tracker instead of the default tracker. For more information on trackers, see Named tracker.
Cookie Domain Name: Specify the domain name on which the _ga cookie should set on. The default value is set to auto. See Cookies and User Identification for more information.
Optimize Container ID: Enter your Optimize container ID to integrate with the Google Analytics Optimize plugin.
If you specify the container ID and Optimize plugin is linked to your Google Analytics property, it will be enabled automatically the next time analytics.js is loaded. Note that this is applicable only if you are using Google Analytics in web device mode.
Use Google AMP Client ID: Enable this setting to uniquely identify users who engage with your content on AMP and non-AMP pages. See Google Analytics session unification for AMP for more information.
Consent management settings: Configure the consent management settings for the specified source by choosing the Consent management provider from the dropdown and entering the relevant consent category IDs. See Consent Management in RudderStack for more information on this feature.
User deletion: Use this setting to add and authenticate an account used to delete users in Google Analytics. See Deleting a user for more information.
Identify
RudderStack does not support sending Personally Identifiable Information (PII) to the Google Analytics reporting interface.
Google Analytics’ universal tracking lets you set a user ID to the identified visitors if you enable the Send User ID to GA dashboard setting. Also, you must enable the userid property in Google Analytics and create the corresponding view.
In the above snippet, RudderStack sets the userId to user123 in Google Analytics but does not share the name and email with Google. You can set the user traits along with custom dimensions, metrics, and content groupings via the SDK calls.
For sending server-side events, Google Analytics needs a customer identifier for each call. RudderStack passes an internally generated ID as the cid parameter for Google Analytics to identify every unique user. RudderStack does not map the user traits to custom dimensions, metrics and content grouping when sending server-side events.
You can call identify once in order to set the userId and the associated traits for all subsequent calls that you make for a particular user via RudderStack. If userId is not set, RudderStack sends an automatically-generated ID called anonymousId from its SDKs with every call. This id is used as the cid in Google Analytics. If Send User ID to GA dashboard setting is enabled, RudderStack sets the event’s userId as uid.
Deleting a user
This feature is available only for the RudderStack Enterprise plan users.
For the above call, RudderStack sends the following properties to Google Analytics:
Property
Value
Event Category
category
Event Action
Track me
Event Label
label
Event Value
value
RudderStack does not populate the Event Category field by default. If the event does not contain the category property, you can use the transformations feature to manually populate it in the payload.
Page
RudderStack sends a pageview hit to Google Analytics whenever you make a page call.
You must send a path or url property with every page call; otherwise, Google Analytics will reject the event.
The following snippets demonstrate variants of the page that involve sending your page name and category:
// Passing page category and name
rudderanalytics.page("category","name",{path:"path",url:"url",title:"title",search:"search",referrer:"referrer",})// "home" is the name of the page.
rudderanalytics.page("home",{path:"path",url:"url",title:"title",search:"search",referrer:"referrer",})
Note that:
For a server-side page call, you must pass the application name in context.app.name contextual property as an. Otherwise, Google Analytics will reject the event.
If the Include the Querystring in Page Views setting is enabled in the RudderStack dashboard, then RudderStack sends the entire URL to Google Analytics (including the querystring) as dp (Document Path). Otherwise, RudderStack removes the querystring from the URL.
Page title in device mode
When sending events in device mode, RudderStack sets the page title as one of the following, depending on the presence of message.properties.category and message.name in the event:
When sending events in cloud mode, RudderStack sets page title from the event’s properties.title or context.page.title.
Ecommerce
RudderStack supports ecommerce event tracking for Google Analytics. The prerequisites are listed below:
You must enable ecommerce tracking in Google Analytics; otherwise, it will not be shown in the reports.
For every Order Completed event, orderId is required. Also, for each product in the order, there must be an id and name. Other properties are optional.
Enhanced ecommerce
Enhanced ecommerce lets you derive insights from your ecommerce events by combining the data related to product impressions, promotions, and user actions.
To use this feature, enable the Enable Enhanced Ecommerce setting in the RudderStack dashboard and Google Analytics. Also, make sure that your events adhere to RudderStack’s Ecommerce events specification.
Some other prerequisites for enhanced ecommerce tracking are:
Similar to ecommerce tracking, for every Order Completed event, orderId is required. Also, for each product in the order, there must be an id and name.
order_id is required for refunded orders.
You must pass the product ID or name for all events that have the product details. product_id checks the presence of properties.product_id. Otherwise, properties.sku is preferred.
Measuring checkout steps
Checkout steps is a key feature of enhanced ecommerce tracking and a major differentiator between the regular ecommerce and enhanced ecommerce tracking.
You can configure the checkout funnel in the Google Analytics admin interface as shown below:
You can then implement the checkout flow by sending a track event named Checkout Step Viewed and Checkout Step Completed for the steps added in Google Analytics.
rudderanalytics.track('Checkout Step Viewed',{currency:'CAD',step:1});rudderanalytics.track('Checkout Step Completed',{currency:'CAD',step:1,//if this is the shipping step
shippingMethod:'FedEx',//if this is the payment step
paymentMethod:'Visa'});
You can use enhanced ecommerce tracking to collect impressions-related information like the users who have viewed or filtered through the product. RudderStack maps the product impressions to the Product List Viewed and Product List Filtered events:
The following sections highlight some other important features of this integration.
Passing cookies from Universal Analytics
RudderStack uses the client ID (cid) to keep a track of unique visitors to your website. A sample Google Analytics universal cookie with the client ID 476220681.159039102 looks like the following:
_ga=GA1.2.476220681.159039102;
You can verify the client ID by running the following snippet:
ga(function (tracker) {
var clientId = tracker.get('clientId');
console.log('My GA universal client ID is: ' + clientId);
});
For server-side events, if you set the client ID manually by sending anonymousId in your event and if the Send user ID to Google Analytics dashboard setting is enabled, then RudderStack passes the userId as the uid to Google Analytics along with the cid parameter. For more information, see Identify section above.
How RudderStack takes clientId
If Disable Md5 encryption from Client ID dashboard setting is enabled, RudderStack takes the client ID in the following priority order:
From the integrations object while initializing the SDK:
If none of the above is present, clientId is set as undefined.
If Disable Md5 encryption from Client ID dashboard setting is disabled and the integrations object, externalId, traits.cid, and anonymousId are all absent, RudderStack passes the event’s userId as the client ID in an MD5-hashed format.
User agent
During server-side tracking, RudderStack maps user_agent to the following parameters:
message.traits.ua for identify events.
context.userAgent for track and page events.
Visitor geolocation
During client-side tracking, RudderStack automatically sends the IP address of the HTTP request to determine the visitor’s location. However, for server-side tracking, you must include the visitor’s IP in the track call.
UTM parameters
RudderStack’s JavaScript SDK automatically maps the UTM parameters from the URL and send them to Google Analytics.
For the other SDKs, you must manually pass the UTM parameters in your event’s context object via the context.campaign, campaign.name, and campaign.mediums properties for them to show up in your Google Analytics report. Note that campaign.term and campaign.content are optional properties.
For the identify events, you can also pass the UTM parameters via the message.traits object.
Measurement protocol parameters
When sending events to Google Analytics via server-side tracking, you can send the following event traits or properties as measurement protocol parameters:
You can configure the custom dimensions in the Admin page of your Google Analytics dashboard.
There are multiple scopes for custom dimensions such as hits, session, user, and products (if Enhanced ecommerce setting is enabled). Once you set these up in Google Analytics, you can map the event traits and properties to the custom dimensions in the RudderStack dashboard.
A custom dimension should be set as dimension{index}. For example, in the above image, dimension1 is mapped to the first_name, dimension2 is mapped to gender, and so on. The following image highlights the custom dimensions as seen in the Google Analytics dashboard:
Note that an identify call containing the custom dimensions is recorded after the next track or page call. An example is shown below:
The non-interaction parameter (nonInteraction) in the events lets you specify the bounce rate for pages in your website that also include event measurement. Refer to the Non-Interaction Events guide for more information.
If you enable the Add the non-interaction flag to all events setting in the RudderStack dashboard, nonInteraction is set to 1. A sample payload is shown below:
If you enable the Use Named Tracker setting in RudderStack dashboard, RudderStack pushes the events to a Google Analytics tracker named rudderGATracker instead of the default tracker. For more information on creating trackers in Google Analytics, refer to the Creating Trackers guide.
If Use Named Tracker setting is disabled, RudderStack sets a default tracker with the name t0.
Setting multiple trackers
You can set a second tracker in the ready() callback function of the RudderStack SDK. The following snippets show an example of sending events to Google Analytics with another tracking ID:
// without any tracker name
window.rudderanalytics.ready(()=>{console.log("we are all set!!!")window.ga("create","UA-XXXXXXX-1","auto")window.ga("send","pageview")})
// with a tracker name
window.rudderanalytics.ready(()=>{console.log("we are all set!!!")window.ga("create","UA-XXXXXXX-1","auto",{name:"newTracker"})window.ga("newTracker.send","pageview")})
Cross-domain-tracking
You can implement cross-domain tracking by following either of the following approaches:
Tracking visitors with userId: If the Send user-id to GA dashboard setting is enabled, you can send userId to uniquely identify a given user. However, this only works for the identified users. RudderStack does not track or maintain the anonymous visitor sessions.
Tracking Anonymous Visitors: In this approach, RudderStack automatically enables allowLinker - an auto-linking plugin provided by Google Analytics to track cookies and anonymous visitors when users navigate from one page to the other.
Ignored referrers
For universal profiles, you can edit the ignored referrers in Google Analytics directly.
Site search
When sending page events to Google Analytics, you can enable the Include the Querystring in Page Views setting in the RudderStack dashboard to add the search term to the page URL.
Also, you need to enable the Site search Tracking in your Google Analytics account and enter the query parameter. If the query is abc.com/s=xyz, the setting should be as follows:
Content groupings
You can set the content grouping mappings in the RudderStack dashboard using the Property & Trait Mapping setting.
The below image shows the content grouping configuration settings in Google Analytics:
When you send a page call with custom properties, RudderStack uses the property value as the value of the specified content grouping.
FAQ
Where can I find the Google Analytics tracking ID?
In your Google Analytics dashboard, click the Admin tab in the bottom left corner and go to Tracking Info.
Click Tracking Code to get your Google Analytics tracking ID:
What are custom metrics and custom dimensions?
Custom metrics and custom dimensions are fields that let you track custom properties associated with your events using RudderStack.
Metrics are applicable for event properties having a numeric data type while dimensions are used for event properties having string data type. Both are used to track custom data properties in Google Analytics.
My website uses HTTPS. Do I need to change any settings for accurate Google Analytics tracking?
In the Property Setup, you need to change the website URL from HTTP (default) to HTTPS:
Can I view real-time reports of my event data?
Yes, you can. Check the Realtime reports in Google Analytics. A sample dashboard is shown below:
How do I view the already processed events for a particular day?
To view the processed events for a particular day, adjust the Google Analytics’ default reporting time frame to the required date.
Why are my page views in Google Analytics different when sent from device mode as against cloud mode?
There could be two reasons for this:
There can be adblockers enabled in the user’s browser while visiting your site. This blocks the browser from sending requests directly to Google Analytics.
For cloud mode, RudderStack is not blocked by adblockers presently. If you’re sending the events to Google Analytics via cloud mode, the actual number of events intended to be sent to Google Analytics are forwarded by the RudderStack server.
In this scenario, the number of requests in device mode is expected to be lower than in cloud mode.
RudderStack’s JavaScript SDK provides a way of detecting how many page view requests are potentially blocked by the adblockers through your site pages. See Detecting Ad-blocked Pages for more information.
This site uses cookies to improve your experience while you navigate through the website. Out of
these
cookies, the cookies that are categorized as necessary are stored on your browser as they are as
essential
for the working of basic functionalities of the website. We also use third-party cookies that
help
us
analyze and understand how you use this website. These cookies will be stored in your browser
only
with
your
consent. You also have the option to opt-out of these cookies. But opting out of some of these
cookies
may
have an effect on your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This
category only includes cookies that ensures basic functionalities and security
features of the website. These cookies do not store any personal information.
This site uses cookies to improve your experience. If you want to
learn more about cookies and why we use them, visit our cookie
policy. We'll assume you're ok with this, but you can opt-out if you wish Cookie Settings.