Google Analytics

Step-by-step guide with code to send your events data from RudderStack to Google Analytics

RudderStack supports sending events from RudderStack SDKs to the Google Analytics endpoints. We support the connection mode S2S (Server-to-Server) through our data plane, making requests to Google Analytics endpoints through Google Analytics' Measurement Protocol specification.

Getting Started

To enable sending data to Google Analytics, you will need to add it as a destination to the source from which you are sending the event data. Follow our Adding a Source and Destination tutorial guide to do this.

Once the destination is enabled, events from our servers will start flowing to Google Analytics. You will start seeing the events in Google Analytics' real-time view.

Adding Google Analytics destination configurations

RudderStack currently does not support the Pages and Screens configurations for Google Analytics.

Page

We send a pageview hit to Google Analytics whenever you make a page() call from our SDKs.

From our JavaScript libraries, we automatically collect the following page properties with the page() call just after the load() call:

  • path

  • url

  • title

  • search

  • referrer

For example, for a page loaded at a sample location http://localhost/test_browser.html?param1=true with title Page Load, we get the following properties:

Property

Value

path

/test_browser.html

referrer

""

search

?param1=true

title

Page Load

url

http://localhost/test_browser.html?param1=true

You can also override these values and call page() with properties as below:

rudderanalytics.page({
path: "path",
url: "url",
title: "title",
search: "search",
referrer: "referrer"
});

It is important to send a path or url property with page call, otherwise Google Analytics will silently 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"
});

We currently do not pass the page name and category values to Google Analytics. Depending on the use case, we can append the information to other fields of the page call.

Track

We send an event hit when a track() call is made from our SDKs.

A simple track call can be seen as:

rudderanalytics.track("Track me")

This will send the following Event Category and Event Action :

Property

Value

Event Category

Event Action

Track me

We do not populate the Event Category field by default. If you face such a requirement, use our custom transformations to populate the event payload with a category property.

A more verbose track call that you can make is as shown:

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

The following properties will be sent to Google Analytics event:

Property

Value

Event Category

category

Event Action

Track me

Event Label

label

Event Value

value

Custom Dimensions

You can add custom dimensions and custom metrics to your Google Analytics account to track custom properties attached to your events.

Add the mapping in the RudderStack destination configuration plane under Configure Custom Dimensions , as shows in the Getting Started section above. An example of a sample mapping is as shown below:

Property

Google Analytics Dimension/metric

prop_1

cd1

prop_2

cd2

prop_3

cm1

prop_4

cm2

We will check the properties in the track call to see if they are defined as dimensions and send their values to Google Analytics. For a trackcall like the following:

rudderanalytics.track("Logged in", {
label: "label",
value: "value",
prop_1: "prop_value",
prop_3: "prop_metric"
});

where prop_1 and prop_3 are dimensions defined in your Google Analytics account as well as configured in our config-plane , we will send the following to Google Analytics:

Property

Google Analytics parameters

Event Action

Logged in

Event Label

label

Event Value

value

cd1

prop_value

cm1

prop_metric

Identify

TheIdentify calls for Google Analytics are presently not supported for sending user-related information. Google Analytics also forbids passing any PII (Personally Identifiable Information) to their servers. You can set up any user information, if needed, for analytics as properties to our track call and as Custom Dimensions while configuring Google Analytics in the Destinations dashboard.

Google Analytics needs a customer identifier for each call made. We pass an internally generated id and pass it as cid parameter for Google Analytics to understand a unique user.

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 a userId is not set, we send a generated id (anonymousId) from our SDKs with every call to our servers. This id is used as the cid in Google Analytics.

The following are few ways to make an identify call:

rudderanalytics.identify("my-userID");
// here only the user-traits will get populated
rudderanalytics.identify({
name: "Tintin",
city: "Brussels",
country: "Belgium",
email: "tintin@herge.com"
});

If your database userId is yet to be populated before you make a call to RudderStack, but you wish to have your own uniform identification, please override anonymousId with your own id as shown:

rudderanalytics.track(
"Logged in",
{
category: "category",
label: "label",
value: "value",
prop_1: "prop_value",
prop_3: "prop_metric"
},
{
anonymousId: "my-anonID"
}
);

With S2S, Google won't be able to track user cookies that it needs for ads, re-targeting, profiling, advanced demographics, and map the same with your Google Analytics data.

For more information about the user demographics and using the Measurement Protocol, please check the following articles:

https://support.google.com/analytics/answer/2799357?hl=en https://developers.google.com/analytics/solutions/crm-mp-integration

We send the user identifier as a cid parameter to Google Analytics, depending on the use case if you want to have a user-view in your Google Analytics dashboard, we can also send it as a uidparameter.

For more information regarding setting up a user ID in Google Analytics and related help, please visit the following links: https://support.google.com/analytics/answer/3123666 https://support.google.com/analytics/answer/6205850#related-resources

FAQs

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. While custom metrics are properties with a numeric data type, custom dimensions are associated with a string data type.

Please refer to the Getting Started section above in this document to know how to specify these fields on the RudderStack platform.

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:

Real-time event data report

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.

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:

Changing the website URL from HTTP to HTTPS

Contact Us

If you come across any issues while configuring or using RudderStack with Google Analytics, please feel free to contact us. We will be happy to help you.