Skip to content

Latest commit

 

History

History
148 lines (98 loc) · 7.45 KB

google-analytics-4.md

File metadata and controls

148 lines (98 loc) · 7.45 KB
description
Step-by-step guide to send event data from RudderStack to Google Analytics 4.

Google Analytics 4

Google Analytics 4 (formerly known as "App + Web") is a new Google Analytics property, with different instrumentation and reports than the Universal Analytics properties. Google Analytics 4 can be used for websites, apps, or both together - whereas Universal Analytics properties only support websites.

RudderStack supports the gtag way of tagging in websites.

Getting Started

To enable sending data to Google Analytics 4, you will first need to add it as a destination to the source from which you are sending your event data. Once the destination is enabled, events from RudderStack will start flowing to Google Analytics 4.

Before configuring your source and destination on the RudderStack, please verify if the source platform is supported by Google Analytics 4, by referring to the table below:

Connection Mode Web Mobile Server
Device Mode Supported - -
Cloud Mode - - -

{% hint style="info" %} To know more about the difference between Cloud mode and Device mode in RudderStack, read the RudderStack connection modes guide. {% endhint %}

Once you have confirmed that the platform supports sending events to Google Analytics 4, please perform the steps below:

  • Choose a source to which you would like to add Google Analytics 4 as a destination.

{% hint style="info" %} Please follow our Adding a Source and Destination guide to add a source in RudderStack. {% endhint %}

  • Select the destination as Google Analytics 4 to your source. Give your destination a name and then click on Next.
  • On the Connection Settings page, fill all the fields with the relevant information and click Next.

Google Analytics 4 Connection Settings in RudderStack

  • In the Connection Settings, please enter your Measurement Id as shown above.

Identify

User-ID is an advanced feature that lets GA4 present a cross-device, cross-platform view of your customers' behavior. Google Analytics 4 uses userId and deviceId (GA's cid value from Universal Analytics terminology) to identify users.

Google Analytics 4 also allows you to set a user ID to the identified visitors if Send User ID to GA is enabled in the destination settings page in the RudderStack app. RudderStack will send the identified userId according to this guide.

A sample identify call is as shown:

rudderanalytics.identify("sample_user_id", {
  name: "Test name",
  email: "[email protected]"
});

In the above snippet, the userId will be set to sample_user_id for Google Analytics and the name and email will be set as user_properties.

If Send User ID to GA is disabled then we do not set userId . Instead, we only send user traits to be set as user_properties in Google Analytics. The user properties are set on the gtag client according to this guide.

Page

Google Analytics 4 gtag sends a page_view event to Google Analytics by default every-time it is loaded. You can also send page_view event to google analytics whenever you make an explicit page() call to RudderStack SDK.

We send following properties by default:

  • path mapped to page_location
  • title mapped to page_title
  • referrer mapped to page_referrer

You can also make page() call with any custom and standard properties as shown below:

rudderanalytics.page({
  path: "/test_browser.html",
  url: "http://example.com/test_browser.html?param1=true",
  title: "Page Load",
  search: "?param1=true",
  referrer: "referrer"
});

Extend Page View Property

Google Analytics 4 has a limit on the number of unique properties per event name. The default page_view event supports the above properties as mentioned in this guide. If the Extend Page View Property config is enabled, then RudderStack sends the following properties along with any other custom property passed to page call of the RudderStack SDK:

  • url
  • search

Block Page View Event

When this config is enabled we disable sending Google Analytics 4 page_view events on load, instead you can explicitly send a page_view event by calling Rudder SDK page() API.

Track

The track call allows you to capture any action that the user might perform, along with the properties that are associated with that action. Each action is considered to be an event.

A sample track call looks like the following:

rudderanalytics.track("Track me");

RudderStack's SDK will send the track event name and any properties as custom properties to Google Analytics 4.

{% hint style="info" %} For properties that are nested and not a standard Google Analytics 4 property, RudderStack SDK will flatten them before sending to Google Analytics. {% endhint %}

{% hint style="info" %} There are limits on the number of custom properties per event that can be sent to Google Analytics 4. RudderStack SDK doesn't drop the payload based on these limits. If the events are not showing up in debug view or reports on Google Analytics dashboard, please refer this for collection limits. {% endhint %}

eCommerce

RudderStack supports eCommerce tracking for Google Analytics 4. Use the RudderStack eCommerce spec for sending events while instrumenting your site with the RudderStack SDK.

Below are some examples of the track event names that are passed to Google Analytics 4-specific eCommerce event name:

RudderStack event name Google Analytics 4 event name
Products Searched search
Product List Viewed view_item_list
Promotion Viewed view_promotion
Product Clicked select_item
Product Added To Wishlist add_to_wishlist
Product Added add_to_cart
Cart Shared share
Checkout Started begin_checkout
Order Completed purchase

{% hint style="info" %} For each product in the order, there must be an id and name associated. More info on Google Analytics 4 e-commerce event and corresponding properties can be found here. {% endhint %}

FAQs

How do you get the Google Analytics 4 Measurement Id?

  • Login to Google Analytics dashboard.
  • Go to the Admin section from the left sidebar.
  • Select the account and then property from the drop down for which you wish to get the id.
  • Now click on data streams and select the stream for which you wish to get the id.
  • Copy the measurement id by clicking on copy to clipboard icon.

Contact Us

If you come across any issues while configuring Google Analytics 4 with RudderStack, please feel free to contact us or start a conversation on our Slack channel. We will be happy to help you.