How to Set Up Event Tracking in Google Analytics 4
Google Analytics 4 (Google Analytics 4, GA4) is a new resource created by Google to replace Universal Analytics. Already, when installing Google Analytics, GA4 is used by default. Therefore, it is important for everyone who works with analytics to know what kind of data model it has now. In this article, we will look at the structure and operation of events in GA4. Let's use an example to show how to set up GA4 through Google Tag Manager (GTM).
- Event structure in Google Analytics 4
- Event Types in Google Analytics 4
- An example of setting up an event in Google Analytics 4 via Google Tag Manager
Event structure in Google Analytics 4
GA4 does not have Category, Action, Label, Value components. They have been replaced:
- an event is a user action on a site or in an application in a certain period of time. Old setting
in Universal Analytics correlates with in GA4;
- parameters are additional information describing the event: when and where it happened.
GA4 has "Automatically Logged Events" and "Enhanced Statistics" in which
You can also give events your own (special) names.
Page_view is the classic page view in GA4. It starts automatically after installing the counter on the site and cannot be disabled.
By default with
- page_referrer (URL of the previous page).
The following data collection restrictions are set:
And there are the following settings restrictions:
Event Types in Google Analytics 4
There are four types of events in GA4:
- automatically registered;
- Improved statistics.
Unlike Universal Analytics, where events had to be configured using a global tag
Automatically logged events
In Basic Data Collection, GA4 automatically tracks a specific set of events. It contains events for both applications and sites. Events from the "Improved Statistics" are also listed there.
List of automatic events not found in other event categories:
- first_visit - when the user visits the site or launches the application for the first time;
- session_start — when the user enters the site or launches the application and begins to interact with it;
- user_engagement - periodically fires when the user has launched and / or is in an open application.
You can see them in the Real Time report:
Statistics help marketers get more events in reports on their own without additional communication with developers or settings in GTM.
The “Enhanced Measurement” section is located in the window along the path: “Administrator” - “Data Streams” - “Web Stream Details” (Admin - Data Streams - Select the web data stream).
By default, "Enhanced Statistics" is enabled and tracks the following events:
- page view (event name: page_view);
- scroll(event name: scroll);
- following an outgoing link (event name: click with the outbound: true parameter);
- site search (event name: view_search_results);
- video engagement (event name: video_start, video_progress, video_complete);
- file download (event name: file_download).
More details - in Help from Google.
These events can be disabled and enabled individually. To do this, click on the gear icon in the "Enhanced Measurement" section:
Select the events you need:
Also, some events can be configured additionally. Let's consider in detail:
Sent to GA4 when a new page is loaded or the page URL changes without reloading the page:
Sent to GA4 once per page when the visitor scrolls below the 90% height threshold.
Used to track the transition on an outgoing link. Along with it, an additional outbound parameter is sent (with the value "true") and a number of such parameters: link_classes, link_domain, link_id, link_url.
If you have multiple domains, go to More Tagging Settings - Configure your domains in the same flow and enter them. All domains listed here will not trigger the event
Sent to GA4 when the URL of the page being loaded contains a query parameter. For example: q, s, search, query, keyword. There can be up to 10, separated by commas:
If the URL of the search results page looks like this: https://netpeak.net/en/blog/search/?q=ga4, then in "Settings" enter "q" (without quotes).
If the URL of the search results page looks like this: https://site.com/search/?key=search+term&results=50, then enter “key” (without quotes) in the first configuration field, and “results” in the second (without quotes). And GA4 will automatically track this parameter:
- video_start, video_progress, video_complete
"Enhanced Statistics" can track the interaction of embedded Youtube videos on your site and then send events
To do this, the URL of the built-in Youtube video player must contain the parameter ?enablejsapi=1. But this feature is not always available. There are other reasons why Youtube video tracking might not work. Therefore, it is better to configure this event separately through GTM.
Sent to GA4 when clicking on a link (open/download file) that contains one of the following file extensions: pdf, xls, xlsx, doc, docx, txt, rtf, csv, exe, key, pps, ppt, pptx, 7z, pkg, rar, gz, zip, avi, mov, mp4, mpe, mpeg, wmv, mid, midi, mp3, wav, wma. It is not yet possible to update the list with other extensions in the GA4 interface.
When the events to track are selected, click "Save" in the upper right corner. Then make sure "Enhanced Measurement" is enabled.
From now on, Google Analytics 4 will automatically track the events that will be displayed in the Real-time report:
You can view all events in the Engagement - Events section. Clicking on the event name will show all its parameters:
The list of "Enhanced Statistics" events can also be seen in the "Events" - "Existing events" section:
Before setting up, when choosing a name and parameters for an event, check if they are in the "Automatically registered events" (Automatically collected events) and in Enhanced Measurement. Only then go to the list of "Recommended events" (Recommended events).
We create "Recommended events" ourselves, using standard names and parameters. Then we will be able to work with existing and future reporting features that are not available for events with special names.
Google has created "Recommended Events" for the following activities:
Some of them already existed in Google Analytics for the gtag.js library by default with categories and labels set:
- to track when a user logs in, use an event
from the list "All Resources";
- to track when a user shares content from a site, use
from the All Resources list.
Using recommended names helps Google Analytics better understand the data and apply it to machine learning.
When the event we want to send is not mentioned in either "Auto Tracked", "Enhanced Statistics", or "Recommended Events", we create our own (special) events.
To create custom events:
- Sign in to your Google Analytics account.
- Select the required resource.
- Select "Events" on the left panel.
- Click "Create Event".
5. Select an existing special event or create a new one using the "Create" button:
6. Set the parameters of the special event as shown in the screenshot and click "Create":
You can access these settings in another way. Select "Administrator" - "Resource" column - "Data Streams" - "Sites" - "Web Stream" - "Additional Tagging Settings":
Event names can only contain letters, numbers and symbols. Underscores and spaces are not allowed. The name must begin with a letter, which is case sensitive. That is, events with names
Important: Google has restrictions, for example, the total number of characters for special titles. In addition, there is a limit of 500 unique event names per GA4 resource. When the maximum is used, the system will not track new events and delete unused ones. So don't create too many unique names.
Examples of an event name for tracking clicks on a button with a call to action:
An example of setting up an event in Google Analytics 4 via Google Tag Manager
There are two types of tags in GTM for collecting data in GA4:
- Google Analytics: GA4 configuration. Sets basic settings and is used as the base configuration for event tags.
- Google Analytics: event GA4. Used to send events to GA4.
Before setting up tracking, we set up the GA4 configuration.
Add Google Analytics 4 code to GTM:
1. In GTM, in the "Tags" tab, click "Create":
2. From the proposed ones, select the tag "Google Analytics: GA4 configuration":
3. We prescribe the "Data stream identifier" from GA4.
To do this, in the GA4 settings, go to "Administrator" - "Data Streams" - "Web Stream Details":
Copy it and paste it into the "Data Stream ID" line in the "Tag Configuration" window:
4. Select the trigger "All Pages" (All pages):
5. Enter the name of the tag and click the "Save" button:
Set up tracking:
In GTM, go to the "Tag Configuration" window. In the "Tag type" line, select the type "Google Analytics: GA4 event".
We select the previously created "Configuration Type" with the data flow identifier "GA4":
We enter the name. For example, we need to track how many people signed up for a course and clicked the "Done" button on the friendly site:
Remember that you can not use names from "Automatically tracked". We come up with the name "Enrollment":
Since we have chosen a one-page site, we specify the additional condition "Once per page" in the "Tag activation settings":
In the "Event Parameters" add the parameters that we want to send along with the event to GA4.
The parameters specified at the time of activation in the "Configurations" tag are included automatically.
Important: If you want to use parameters in reports, you must register them as custom parameters.
We write down which element was clicked:
Set the "Activation Trigger": "Click" - "All elements":
To track a click on this particular button, you must specify a condition:
- find the desired element on the page;
- inspect the element in the browser using the developer console: press F12, right-click on the desired button (in this case it is “Done”):
- in the "Menu" select "View Code":
In this example, "Form Classes" contains "ninja-forms-field nf-element":
Enter the name of the trigger and click "Save":
Enter the name of the tag in the upper right corner (in this example, "Event Button") and click "Save".
Checking the operation of events in GA4
You can check the operation of events in GA4 using:
- Real time report.
- Extensions for Google Chrome browser - Google Analytics Debugger or its equivalent.
Let's check the operation of our event through DebugView. To do this, install the Google Analytics Debugger extension - when enabled, the icon displays ON:
- We go to the monitored site. At the bottom, the Debugger login window appeared.
2. Enter the site address and click "Start".
3. The DebugView report will display the input and all committed events on the timeline. In our case, an event called "enrollment" was displayed, repeating 20 times:
By clicking on the name in the list of main events, we see all its parameters and properties:
1.Google Analytics 4 data model is based on events only.
2. Structure of an event in GA4 is different from Universal Analytics. Instead of four components (“Category”, “Action”, “Label”, “Value”), it has only two: “Events” and “Parameters”. The design of the event has also changed.
3. There are four types of events in Google Analytics 4:
- automatically registered;
- improved statistics.
GA4 is still in its infancy - we are waiting for the appearance of new features in the near future.
A source: Netpeak.net