Google Analytics destination

Send your event data from RudderStack to Google Analytics.

Google Analytics is a popular analytics service that lets you track and report your website traffic across a variety of sources.

RudderStack supports Google Analytics as a destination and makes requests to its endpoints through the Google Analytics Measurement Protocol.

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 ModeWebMobileServer
Device ModeSupported--
Cloud ModeSupportedSupportedSupported
info
In a 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.

Once you have confirmed that the source platform supports sending events to Google Analytics, follow these steps:

  1. From your RudderStack dashboard, add the source. Then, from the list of destinations, select Google Analytics.
  2. 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.
  • Remarketing, Display Ads and Demographic Reports: Enable this setting to tag visitors for the remarketing campaign. See Enable Remarketing and Advertising Reporting Features for more information.
  • 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.
info
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.
  • 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. See Deleting a user for more information.

Identify

warning
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.

A sample identify call is shown below:

rudderanalytics.identify("user123", {
  name: "Alex Keener",
  email: "alex@example.com"
});

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

warning
This feature is available only for the RudderStack Enterprise plan users.

To delete a user in Google Analytics, first authenticate your Google account in the RudderStack dashboard by following the below steps:

  1. Click Create Account in the User Deletion section:
User deletion
  1. From the modal, click the Sign in with Google button.
  2. Choose the required account and grant RudderStack the required permissions.
info
If your account authentication fails, you can refer to these troubleshooting steps for identifying and fixing the root cause.
  1. Click Save to connect the specified account to delete users in Google Analytics:
User deletion

In case you have authenticated multiple accounts, you can click Edit Credentials to select or delete any other authenticated account:

User deletion
warning
RudderStack gives an error if you try to delete an account used by any other connection set up for the same destination.

After authenticating your account in the RudderStack dashboard, you can delete a user in Google Analytics using the Suppression with Delete regulation of the RudderStack User Suppression API.

info
To delete a user, you must specify their userId in the event. Additionally, you can specify a custom identifier (optional) in the event.

A sample regulation request body for deleting a user in Google Analytics is shown below:

{
  "regulationType": "suppress_with_delete",
  "destinationIds": [
    "2FIKkByqn37FhzczP23eZmURciA"
  ],
  "users": [{
    "userId": "1hKOmRA4GRlm",
    "<customKey>": "<customValue>"
  }]
}
info
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 associated properties.

A sample track call is shown below:

rudderanalytics.track("Track me", {
  category: "category",
  label: "label",
  value: "value"
});

For the above call, RudderStack sends the following properties to Google Analytics:

PropertyValue
Event Categorycategory
Event ActionTrack me
Event Labellabel
Event Valuevalue
info
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.

A sample page call is shown below:

rudderanalytics.page({
  path: "path",
  url: "url",
  title: "title",
  search: "search",
  referrer: "referrer"
});
warning
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",
})
info

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:

message.properties.categorymessage.namePage title
AbsentAbsentpageTitle = message.properties.title
AbsentPresentpageTitle = message.name
PresentAbsentpageTitle = message.properties.category
PresentPresentpageTitle = ${rudderElement.message.properties.category} ${rudderElement.message.name}

Page title in cloud mode

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:

MD5 disabled

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'
});

Measuring promotions

rudderanalytics.track('Promotion Viewed', {
  currency: 'USD',
  promotion_id: 'PROMO_12345',
  name: 'Winter Sale',
  creative: 'winter_banner2',
  position: 'banner_slot1',
  testDimension: true,
  testMetric: true
});
rudderanalytics.track('Promotion Clicked', {
  currency: 'USD',
  promotion_id: 'PROMO_12345',
  name: 'winter Sale',
  creative: 'winter_banner2',
  position: 'banner_slot1',
  testDimension: true,
  testMetric: true
});

Coupons

You can add the coupon property in your event to send your coupon data in the Order Completed event.

rudderanalytics.track('Order Completed', {
  orderId: 'abc55',
  total: 999.9,
  shipping: 23.99,
  tax: 25.99,
  currency: 'USD',
  coupon: 'coupon',
  affiliation: 'affiliation',
  testDimension: true,
  testMetric: true,
  products: [{
      quantity: 1,
      price: 24.75,
      name: 'rudder product',
      category: 'cat 1',
      sku: 'p-298',
      productDimension: 'testing'
    },
    {
      quantity: 3,
      price: 24.75,
      name: 'other product',
      category: 'cat 2',
      sku: 'p-299',
      currency: 'EUR',
      productDimension: 'testing'
    }
  ]
});

Measuring product impressions

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:

rudderanalytics.track('Product List Viewed', {
  category: 'cat 1',
  list_id: '1234',
  products: [{
      product_id: '507f1f77bcf86cd799439011',
      productDimension: 'My Product Dimension1',
      productMetric: 'My Product Metric1',
      position: 10
    },
    {
      product_id: '507f1f77bcf86cd799439012',
      productDimension: 'My Product Dimension2',
      productMetric: 'My Product Metric2',
      position: 12
    },
    {
      product_id: '507f1f77bcf86cd799439015',
      productDimension: 'My Product Dimension3',
      productMetric: 'My Product Metric3',
      position: 8
    }
  ]
});
rudderanalytics.track('Product List Filtered', {
  category: 'cat 1',
  list_id: '1234',
  filters: [{
      type: 'department',
      value: 'beauty'
    },
    {
      type: 'price',
      value: 'under'
    }
  ],
  sorts: [{
    type: 'price',
    value: 'desc'
  }],
  products: [{
    product_id: '507f1f77bcf86cd799439011',
    productDimension: 'My Product Dimension',
    productMetric: 'My Product Metric'
  }],
  testDimension: true,
  testMetric: true
});

Refunds

For full refunds, you can use the Order Refunded event:

rudderanalytics.track('Order Refunded', {
  order_id: 'abc55',
  testDimension: true,
  testMetric: true
});

For partial refunds, a sample Order Refunded event is as follows:

rudderanalytics.track('Order Refunded', {
  order_id: 'abc55',
  products: [{
      quantity: 1,
      sku: 'p-1'
    },
    {
      quantity: 2,
      sku: 'p-2'
    }
  ],
  testDimension: true,
  testMetric: true
});

Additional features

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:

  1. From the integrations object while initializing the SDK:
"integrations": {
  "All": true,
  "Google Analytics": {
    "clientId": "clientId"
  }
},
  1. From gaExternalId by setting it as the client ID, if specified in the payload:
"externalId": [{
  "id": "externalClientId",
  "type": "gaExternalId"
}]
  1. From traits.cid.
  2. From anonymousId.

If none of the above is present, clientId is set as undefined.

info
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:

ParametersRudderStack trait/property
srcontext.screen.width x context.screen.height
vpcontext.screen.innerWidth x context.screen.innerHeight
cicontext.campaign.campaignId
gclidfrom externalID googleAdsId
dclidfrom externalID googleDisplayAdsId

The following snippet demonstrates how to send gclid and dclid using externalId:

"externalId": [{
    "type": "googleAdsId",
    "id": "gclid_value"
  },
  {
    "type": "googleDisplayAdsId",
    "id": "dclid_value"
  }
]

Custom dimensions

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:

rudderanalytics.identify({
  gender: 'Female'
});

rudderanalytics.track('Viewed History');

Non-interaction events

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:

{
  "action": "track",
  "event": "Track Page",
  "properties": {
    "nonInteraction": 1
  }
}

Named tracker

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.

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?

  1. In your Google Analytics dashboard, click the Admin tab in the bottom left corner and go to Tracking Info.
Google Analytics tracking ID
  1. Click Tracking Code to get your Google Analytics tracking ID:
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.


Questions? Contact us by email or on Slack