Sub topic 2
The items array for ecommerce
This chapter assumes that you can add a gtag snippet to a web page, read basic JavaScript, and that you know GA4 records interactions as events. It covers the items array, user identity, user properties, sessions, and engagement.
The items array for ecommerce
Ecommerce events such as add_to_cart carry an items array. Each object in the array describes one product.
gtag('event', 'add_to_cart', {
currency: 'USD',
value: 29.99,
items: [
{
item_id: 'SKU_123',
item_name: 'Trail Shoe',
price: 29.99,
quantity: 1
}
]
});How GA4 recognizes a user: client ID and User-ID
GA4 assigns each browser a client ID, stored in a first-party cookie named _ga. The client ID identifies a browser, not a person. To connect activity from several devices to one signed-in person, set a User-ID:
gtag('config', 'G-XXXXXXXXXX', {
user_id: 'u_12345'
});User properties: describing who did it
User properties describe the visitor, such as their plan type. GA4 applies them to later events from that user.
gtag('set', 'user_properties', {
plan_type: 'premium'
});Sessions are derived from events
You do not send sessions. GA4 creates them from events. The session_start event opens a session, and events in that session carry a ga_session_id parameter. By default, a session ends after 30 minutes of inactivity.
Engaged sessions and engagement rate
A session is engaged when it meets at least one condition: it lasts longer than 10 seconds, it has a key event, or it has at least two page or screen views.
Engagement rate equals engaged sessions divided by total sessions.
Exercise
A visitor views two pages in 6 seconds and buys nothing. Is the session engaged?
Show answer
Yes. Two page views make the session engaged, even though it lasted less than 10 seconds and had no key event.