Find the open source code for this destination in the GitHub repository.
Getting started
RudderStack supports sending event data to Google Analytics via the following connection modes:
Connection Mode
Web
Mobile
Server
Device Mode
Supported
-
-
Cloud Mode
Supported
Supported
Supported
In a web device mode integration, that is, using JavaScript SDK as a source, the Google Analytics native SDK is loaded from 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.
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. Refer to the FAQ section 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 on this setting, refer to the Client-side Events Filtering guide.
Enable Enhanced Link Attribution: Enable this setting to retrieve the detailed report of links clicked on your website. Refer to the Enhanced Link Attribution guide 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, refer to the Site search section.
Custom Dimensions & Metrics: Enter the event name, traits, or properties you want to map to the corresponding custom dimensions and metrics. Refer to the Custom dimensions section for more information.
Property & Trait Mapping: Enter the property you want to map to the Google Analytics content grouping. Refer to the Content groupings section 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, refer to the How RudderStack takes the clientId section.
Anonymize IP Addresses: Enable this setting to anonymize the IP address at the earliest possible stage of the collection network. Refer to the IP Anonymization guide for more information.
Enable Enhanced Ecommerce: Enable this setting to derive detailed insights for ecommerce events. Refer to the Enhanced ecommerce section 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, refer to the Non-Interaction events section.
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 the pages having a category associated with them.
Track Named Pages: This setting is enabled by default and lets you track only the pages having 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, refer to the Named tracker section.
Cookie Domain Name: Specify the domain name on which the _ga cookie should set on. The default value is set to auto. Refer to the Cookies and User Identification guide 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. Refer to the Google Analytics session unification for AMP guide for more information.
OneTrust Cookie Categories: If Use device-mode to send events is enabled, this setting lets you associate OneTrust cookie consent groups to Google Analytics.
User deletion: Use this setting to add and authenticate an account used to delete users in Google Analytics. Refer to the Deleting a user section for more information.
Identify
Personally Identifiable Information (PII) cannot be sent to the Google Analytics reporting interface. Thus, nothing is passed to Google unless specifically directed.
Google Analytics’ universal tracking allows you to set a user ID to the identified visitors if Send User ID to GA is enabled in the destination settings by the user. Also, the userid property must be enabled in Google Analytics, and user-id view needs to be created.
In the above snippet, the userid will be set to user123 for Google Analytics, but the name and email will not be shared with Google. Traits along with custom dimensions, metrics, and content groupings can be set in the SDK.
For server-side, Google Analytics needs a customer identifier for each call to be made. RudderStack passes an internally generated ID as the cid parameter for Google Analytics to understand every unique user. Traits are not mapped to custom dimensions, metrics and content grouping yet from our side in server-side.
You can call identify once in order to set the userId and user traitsfor all subsequent calls that you make from our SDK for a particular user. If userId is not set, RudderStack sends a generated ID (called anonymousId) from its SDKs with every call made to the RudderStack servers. This id is used as the cid in Google Analytics. And if Send User ID to GA setting is enabled, the user ID property will be set as uid and will be sent as well.
Deleting a user
This feature is available only for the RudderStack Enterprise plan users.
Refer to the Limits and quotas documentation for more information about the specified quotas for the user deletion API requests.
Track
The track method lets you capture user events along with the properties associated with them.
A sample track call is as shown:
rudderanalytics.track("Track me")
This will send the following Event Category and Event Action :
Property
Value
Event Category
All
Event Action
Track me
RudderStack does not populate the Event Category field by default. To do so, you can use the transformations feature to populate the event payload with a category property.
It is important to send a path or url property with page call, otherwise Google Analytics will reject the event.
There are other variants of the page() call that you can send, which involve giving your page’s 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",})
For a server-side page call, the application name is passed from RudderStack’s context.app.name as an, otherwise the event will be rejected by GA.
If the Include the Querystring in Page Views setting is enabled in the RudderStack dashboard, then the entire URL with the querystring will be sent as dp (Document Path). Otherwise, the querystring will be removed from the URL.
Page title in device mode
Depending on the presence of message.properties.category and message.name properties, the page title is set as one of the following in device mode:
The page title is set as the properties.title or context.page.title in cloud mode.
Ecommerce
RudderStack supports ecommerce tracking for Google Analytics. The required steps are:
For every order completed, orderId is required. For each product in the order, there must be an id and name. Other properties are optional.
The ecommerce tracking should be enabled otherwise it will not be shown in the reports.
Enhanced ecommerce
Enhanced ecommerce allows you to derive insights on the ecommerce events by combining impression data, product data, promotion data and action data. This is a necessity for product-scoped custom dimensions.
To use this feature, the Enable Enhanced Ecommerce setting must be enabled in the RudderStack dashboard, Google Analytics, and should follow RudderStack’s Ecommerce Events Specification.
The required steps are:
Similar to ecommerce tracking, for every order completed the orderId is required. For each product, id and nameare required.
The product ID or name must be passed for all events that has the product details. product_id will check if properties.product_id is present or not. Else properties.sku will be picked.
order_id is required for refunded orders.
Measuring Checkout steps
The Checkout steps feature is a key difference between the regular ecommerce and Enhanced ecommerce tracking, and a major feature of the latter.
You can configure the checkout funnel in the Google Analytics admin interface as shown below:
User agent
On the server-side, user_agent is mapped from:
message.traits.ua: For identify call
context.userAgent: For track and page calls
Visitor geo location
On the client-side tracking, the IP address of the HTTP request is sent automatically to determine the location of the visitor. However, on the server-side, the visitor’s IP has to be included in the track call.
UTM parameters
The UTM parameters need to be passed manually to the server.
UTM parameters are passed in the context object in context.campaign. campaign.name and campaign.mediums must be sent together to show up in the report. Also, campaign.term and campaign.content are optional.
For identify call, you can also pass the UTM parameters via message.traits object.
Measurement protocol parameters
You can also send data to Google Analytics using the measurement protocol. It provides parameters which are automatically collected by the device mode Google Universal Analytics tracker. You can collect the value of the parameter as a RudderStack trait or property when sending server-side events to Universal Analytics.
RudderStack supports the following measurement protocol parameters:
There are multiple scopes for custom dimensions, such as hits, session, user, and products (if Enhanced ecommerce setting is enabled). Once these are set up in Google Analytics, the traits and properties can be mapped to the custom dimensions in the RudderStack dashboard.
A custom dimension should be set as dimension{index}. For example, dimension1 is mapped to the first_name when the user sets the dimension in Google Analytics settings, as shown below. Similarly, you can set up different metrics.
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 allow you to track custom properties associated with your events using RudderStack.
Metrics is for event properties having numeric data type while dimensions is for event properties having string data type. Both are used to track custom data properties in Google Analytics.
Please refer to the Getting Started section above in this document to know how to specify these fields on the RudderStack platform.
My website uses HTTPS. Do I need to change any settings for accurate Google Analytics tracking?
Yes. In the Property Setup, please change the website URL from HTTP (default) to HTTPS as shown:
Can I view real-time reports of my event data?
Yes, you can. Please check the Real-time reports in Google Analytics. A sample dashboard is as shown:
How do I view the already processed events for a particular day?
Please adjust the Google Analytics’ default reporting time frame from a month ago to the required date, in order to view the processed events of that day.
Why are my page views in Google Analytics different when sent from device mode as against cloud mode?
There could be 2 reasons for this:
There can be ad blockers enabled in the user’s browser while visiting your site. This blocks the Google Analytics requests from being sent directly from the browser.
For cloud mode, RudderStack is not blocked by ad blockers presently. If the events are sent to Google Analytics via cloud mode, the actual number of events intended to be sent to Google Analytics are forwarded by the RudderStack server. So, the number of requests from the native mode or device mode is expected to be lower than cloud mode.
The RudderStack JavaScript SDK provides a way of detecting how many page view requests are potentially being blocked by the ad blockers throughout your site pages. Please check the section on 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.