A no-nonsense guide to properly migrate your Google Analytics UA (GA3) property to Google Analytics 4 before it’s official sunset date in July 2023.
What’s New in Google Analytics 4
An important part of any migration from UA to GA4 is to throw your understanding of a Google Analytics session out the window. In a shift toward better user privacy, Google Analytics 4 sessions are no longer cookie-based. There is a strong focus on event tracking through the dataLayer with GA4 instead of a session tracked within a stored cookie.
The session dimensions/metrics are not completely gone however, due to backlash from the analytics community GA4 received a similar session dimension. Sessions are estimated through a machine-learned model (between the first event start and an assumed final event or timeout) with fairly accurate session durations. Data parity is not 1:1 with UA as the GA4 session count is calculated differently, so do not compare session metrics with the older UA installation. This means those that relied on Sessions dimensions in reporting will need to adjust the way they analyse user behaviour. Events are the new status quo, and we need to design our event tracking around that if you do not do this already.
The event structure itself has evolved since Universal Analytics, with the limitation of having only three parameters (Category, Action, Label) our Analytics events can have quite a sizeable number of parameters that can be customised to suit the business. The catch is the old 256-character limit of UA events has been lowered to 100 characters (not including the param name), however, we can store up to 25 unique event parameters per event.
So standard formatting for GA4 dataLayer events are as follows:
gtag('event', '<event_name>', {
<event_parameters>
});
Meaning for a dataLayer event we can name the event and list the parameters below. I recommend standardising the event parameter names for generic GA4 events, or if you need to migrate quickly you can add placeholders for the older event parameters as shown below:
gtag('event', 'dataLayerEvent', {
'eventCategory': 'WebPortal',
'eventAction': 'Login',
'eventLabel': 'SSO'
});
However, if you are preparing to update Google Analytics 4 long before the sunset date of July 2023 then this is a fantastic opportunity to reshape your event tracking structure and add more parameters. An updated event structure for the above login event could look like this:
gtag('event', 'app_login', {
'Product': 'WebPortal',
'Action': 'Login',
'Method': 'SSO',
'Screen': 'Login',
'API Response': 'Successfully, Logged In'
'Hit Timestamp': '2023-01-13T05:01:57+00:00'
});
In terms of what Google Analytics 4 offers to customers in return for the forced upgrade. There is a suite of features in GA4 that build on the older UA frameworks. One of the most remarkable additions is the explore tab in the Google Analytics web interface, which gives customisable exploratory metrics and analysis templates that you can use. There are trade-offs such as the loss of the User Explorer which was useful for understanding individual user behaviour, though in return we do get the ‘user snapshot’ that shows live actions of a small sample size of real-time users which is pretty neat.
7 Steps to a Complete GA4 Migration:
Step 1 – Compiling and Listing All Existing UA Events
Simply put we need to compile a list of current UA Google Analytics events that the brand or company is using. The quickest method for this is to export via Google Analytics to CSV/Excel.
You can expect the formatting of the events that exist in Google Analytics to appear as below:
Event Category | Event Action | Event Label |
User Account | Login | SSO_Facebook |
Banners | CTA click | Learn More |
And if your analytics setup included utilising dynamic event labels I would recommend creating a pivot table in Excel to group by Event Category and Event Action to get an accurate number of events for migration.
STEP 2: Remove legacy events and unnecessary data collection.
Understanding the existing UA events setup gives us the opportunity to see what is working and what events are outdated or legacy. This is also why I recommend exporting a list from the Google Analytics dashboard that includes the event hit count. We can view
Step 3: Assess the Fundamental Values and Necessary Reporting Requirements.
One if not the only benefit of upgrading to GA4 is the chance to have a complete view of analytics tracking that has been currently enabled and being able to assess the importance of
Step 4: Consolidate events and parameters for use in GA4
This involves: Consolidating any events that are similar or identical into a common event to save on redundant or duplicated event tracking. Persistent dimensions like userId and other identifiers are defined as persistent page load dimensions (you don’t need to include user information in any events). Consolidate naming conventions across multiple platforms and products. Sign-ups and logins can share naming conventions and instead have unique parameters to identify between the various options. It’s good practice to reuse a parameter name wherever it is possible or even build a schema or framework for all dataLayer events moving forward.
Step 5: Create the GA4 property.
Data Stream to generate tracking code.
Step 5: Implement Google Tag Manager for GA4
Set up the data layer variable
Once you have the key that you would like to work with, you can proceed to create a data layer variable:
Data Layer Variables:
1. Under User-Defined Variables, click New.
2. Click Variable Configuration and select Data Layer Variable as the variable type.
3. In the Data Layer Variable Name field, enter the key exactly as it was written in the code (e.g. bookTitle, not book title.) In most cases you should leave the Data Layer Version set to the default value of Version 2. Learn more.
4. Save the variable.
5. Repeat these steps for every data layer key that you would like to have available as a variable in Tag Manager.
Publish the container.
common mapping for the configuration includes event name, location, and client id. This is why the importance of shared event parameters and having an dataLayer event schema can save you time when setting up the GA4 property in Google Tag Manager.
Step 7: Test, Test and Test.
You have now successfully migrated to GA4 but the work doesn’t stop there! Now you must ensure that the setup is working correctly on all platforms. This is best conducted via manual testing of all events on each different platform and/or product.
The power of setting user_ID
User ID tracking in Google Analytics 4 has improved compared to UA. Whenever you can it is important to set or overwrite the user_id parameter. This parameter is so important in connecting the multiple devices, browsers, and sessions of your customers/users. Through tracking logged-in experiences, DOM scraping or Javascript variables your developer(s) can push the user_id of a customer into the dataLayer after they have logged in/signed up and this will allow GA4 to generate a better picture of a single user. The user ID can be auto-generated by google or you can overwrite it with a specific user identifier used within your brand/business (eg. Shopify has a customer id for any used that’s logged in and fires a purchase event).
dataLayer.push({
'user_id': 'USER_ID'
});
Analytics.setUserID("USER_ID")
Set the Timestamp as a parameter in all events!
Set param for Hit Timestamp as auto-generated timestamp is not accurate and will bundle multiple events in the one timestamp. A simple custom JavaScript variable to get the local time of browser window and set to parameter is shown below:
function() {
// Get local time as ISO string with offset at the end
var now = new Date();
var tzo = -now.getTimezoneOffset();
var dif = tzo >= 0 ? '+' : '-';
var pad = function(num) {
var norm = Math.abs(Math.floor(num));
return (norm < 10 ? '0' : '') + norm;
};
return now.getFullYear()
+ '-' + pad(now.getMonth()+1)
+ '-' + pad(now.getDate())
+ 'T' + pad(now.getHours())
+ ':' + pad(now.getMinutes())
+ ':' + pad(now.getSeconds())
+ '.' + pad(now.getMilliseconds())
+ dif + pad(tzo / 60)
+ ':' + pad(tzo % 60);
}