Using Google Analytics (GA4) with Cookie Consent
Google Analytics 4 has replaced Universal Analytics. You can now view event tracking data in GA4.
For more information, see Google's Universal Analytics deprecation announcement and UA→GA4.
Google Analytics automatically tracks certain events, such as page views and clicks on outbound links, but if there are custom events, you need to set them up by defining necessary variables and triggers.
OneTrust automatically provides Google Analytics users with event tracking data. You will need to enable a Google Analytics Tracking for the Banner and Preference Center while publishing test or production CDN scripts. This enables you to see how visitors interact with the software to help you with future decision making.
We have named a set of Event Categories, Actions and Labels which should be self-explanatory. Once the code is installed on your site, you will start to see the events appearing in your Google Analytics reports.
This guide is not an exhaustive guide for how to use Google Analytics for your website, but details how to get started sending events to Google Analytics.
You will need to create the following custom Data Layer Variables:
- eventModel.optanonCategory
- eventModel.optanonAction
- eventModel.optanonLabel
Next, you will need to set up the following custom Trigger:
- trackOptanonEvent
Last, you will need to create the following Tag and apply the Trigger.
- OneTrust Cookie Consent
Once you have set up the Data Layer Variables, Trigger, and Tag, you should be able to view events in Google Analytics.
To create a new Data Layer variable
To create the trackOptanonEvent trigger
This trigger will fire when the toggles are changed in the Preference Center.
To create the OneTrust Cookie Consent tag
To retrieve required scripts
To check events on a production site
optanonAction values can be one of the below based on interaction with Banner or Preference Center:
optanonAction Values
-
Banner Accept Cookies
-
Banner Reject All
-
Banner Close Button
-
Preference Center Opened From Banner
-
Preference Center Opened From Button
-
Preference Center Opened From Function
-
Preferences Save Settings
-
Floating Cookie Settings Open Button
-
Preferences Allow All
-
Preferences Reject All
-
Preferences Toggle On
-
Preferences Toggle Off
-
Preferences Close Button
To view events in real time
View events in real time to ensure that the events from the website are being sent to Google Analytics.
Method 1
Method 2
You can also click View user snapshot to see the data of one active user. Google Analytics 4 now picks one random active user and shows the activity.