Google Analytics 4

If you have an older implementation of the Analytics module connected to Google Universal Analytics (UA), you must migrate it to Google Analytics 4.

Google Universal Analytics (UA) stopped collecting data in July 2023.

The major difference between the two is that GA4 lets you track analytics on websites and applications, while UA was limited to website tracking. Google recommends the migration be done manually as not all UA configurations have an obvious GA4 counterpart. If you don’t migrate manually, a new GA4 property is created for you automatically. See the related Google documentation.

To check if your property type is updated to GA4 or if you’re still on Universal Analytics, click the down arrow in the top left corner next to the Analytics logo. Universal Analytics property IDs start with UA and end with a number (UA-XXXXXXXXX-1), while GA4 property IDs have only numbers (XXXXXXXXX). If your property type hasn’t been upgraded to GA4, keep on reading.

Moving to GA4

First, create a GA4 property in your Google Analytics dashboard. You can use GA4 Property Setup Assistant for this.

Configuring GA4

Since GA4 uses a different authentication system (OAuth2) than its predecessor, it’s also necessary to generate Google Analytics data API key for authentication.

  1. Go to Quickstart, and click Enable the Google Analytics Data API v1. This will generate a .json file with client configuration. Save the file as credentials.json.

    It is very important to download and store this private key file correctly as you need it to authenticate Magnolia with Google. Also note the email that’s created in these instructions - you use it in step 4 to give this account access to GA4.
  2. In your organization’s Google Cloud Console, go to APIs and Services.

  3. In the Credentials section, register the new API key.

  4. Go to Property access management and add the client_email from the credentials.json file to it.

    Example:
    {
      "type": "service_account",
      "project_id": "fakeAnalyticsTestProject-234412",
      "private_key_id": "randomId",
      "private_key": "randomKey",
      "client_email": "abc@email.com",
      "client_id": "randomId",
      "auth_uri": "https://accounts.google.com/o/oauth2/auth",
      "token_uri": "https://oauth2.googleapis.com/token",
      "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
      "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/"
    }

    An example of configuration with an email

    The client email is linking GA4 to collect data.

  5. Back in the Analytics dashboard, go to Account Settings and select Property Access Management. Add the client_email to the list. Once the email has been added, the API key you generated in step 1 can be used.

  6. Switch to Magnolia, and go to the Resource Files app. In the action bar, click on Upload file and upload the credentials.json. Type “Google” in the Name search to make sure the newly generated json file and the supplier yaml files are both there.

    Resource file list with supplier yaml and json key files highlighted

  7. Select the json key file from the list and copy the path that appears in the bottom-left corner.

    Highlighted location of the path

  8. Now, open the google4supplier file and paste the path under serviceAccountJsonPath.

  9. In the same supplier file, modify the propertyId which can be found in your GA account, and click on Save changes.

Metrics, dimensions and dates

Another thing to pay attention to when configuring GA4 in Magnolia are metrics, dimensions, and dates. These can be modified in the same supplier file we’ve worked on in the steps above.

Metrics

In GA4, metrics and dimensions don’t contain the ga prefix as seen in previous versions. Read more about metrics and dimensions in the Google documentation.

Example of user dimensions

audienceId

The numeric identifier of an Audience. Users are reported in the audiences to which they belonged during the report’s date range. Current user behavior doesn’t affect historical audience membership in reports.

audienceName

The given name of an Audience. Users are reported in the audiences to which they belonged during the report’s date range. Current user behavior doesn’t affect historical audience membership in reports.

newVsReturning

New users have 0 previous sessions, and returning users have 1 or more previous sessions. This dimension returns two values: 'new' or 'returning'.

signedInWithUserId

The string 'yes' if the user signed in with the User-ID feature. To learn more about User-ID, see User-ID for cross-platform analysis.

Example of user metrics

active1DayUsers

The number of distinct active users on your site or app within a 1 day period. The 1 day period includes the last day in the report’s date range. Note: this is the same as Active Users.

active28DayUsers

The number of distinct active users on your site or app within a 28 day period. The 28 day period includes the last day in the report’s date range.

active7DayUsers

The number of distinct active users on your site or app within a 7 day period. The 7 day period includes the last day in the report’s date range.

activeUsers

The number of distinct users who visited your site or app.

activeUsers

The number of distinct users who visited your site or app.

The way you write the date slightly differs from the previous version (e.g. before with UA = 7DaysAgo, now with GA4= 7daysAgo.) Read more about dates over here.

Example of dates

startDate

The inclusive start date for the query in the format YYYY-MM-DD. Can’t be after endDate. The format NdaysAgo, yesterday, or today is also accepted, and in that case, the date is inferred based on the property’s reporting time zone.

endDate

The inclusive end date for the query in the format YYYY-MM-DD. Can’t be before startDate. The format NdaysAgo, yesterday, or today is also accepted, and in that case, the date is inferred based on the property’s reporting time zone.

name

Assigns a name to this date range. The dimension dateRange is valued to this name in a report response. If set, can’t begin with date_range_ or RESERVED_. If not set, date ranges are named by their zero based index in the request: date_range_0, date_range_1, etc.

Google site tags

Connected site tags work with an additional gtag(config, G-XXXXX) call (without any parameters), which downloads a Google Analytics 4 tag container and sends an automatic page_view` event to the Google Analytics 4 property.

Read more about connected site tags in Set up Analytics.

Feedback

DX Core

×

Location

This widget lets you know where you are on the docs site.

You are currently perusing through the DX Core docs.

Main doc sections

DX Core Headless PaaS Legacy Cloud Incubator modules