To improve the performance of your ML model and attribution, it’s necessary to implement the tracking of several event parameters and user properties in Google Analytics.
General Steps
- Pass the Parameter to dataLayer: For each event or user property, pass the relevant parameter (e.g.,
user_id
,ip_address
,ever_paid
,is_first_purchase
etc.) to yourdataLayer
.
- Send the parameter to Google Analytics via Google Tag Manager (GTM) or gtag.js:
- For GA4 via Tag Manager:
- Tracking user properties:
- If you don’t already use a Google Tag: Event Settings variable, create one.
- Under the User Properties section of your Google Tag, add a new row with the Parameter and the corresponding Value (the Data Layer variable you created).
- Select the created Event Settings Variable in each GA4 configuration and event tag.
- Tracking event parameters:
- Open your GA4 event tag that tracks conversions.
- In the Event Parameter section, add a new row with the Parameter and the corresponding Value (the Data Layer variable you created).
- For GA4 using gtag.js: Add the parameter to the appropriate command in your measurement code:
- Tracking user properties:
- Tracking event parameters:
javascriptgtag('config', '<TAG_ID>', { '<parameter_name>': '<parameter_value>' });
javascriptgtag('event', '<event_name>', { '<parameter_name>': '<parameter_value>' });
Parameters to Implement
- Config parameter - User ID (
user_id
) - Example for
gtag.js
:
Pass a unique user ID after login to track users across sessions on different devices.
javascriptgtag('config', 'STREAM_ID', { 'user_id': 'USER_ID' });
- User property - IP Address (
ip_address
) - Example for
gtag.js
:
Collect the user's IP address. Please note that collecting a user's IP address should only be done after obtaining their explicit consent.
javascriptgtag('config', 'STREAM_ID', { 'user_properties': { 'ip_address': 'IP_ADDRESS' } });
- User property - Ever Paid (
ever_paid
) - Example for
gtag.js
:
Track whether a user has ever converted with a
true
or false
flag.This parameter is necessary freemium subscription based businesses where users can login to the platform on the same website where they can convert, it’s necessary to be able to differentiate all actions of converted customers.
javascriptgtag('config', 'STREAM_ID', { 'user_properties': { 'ever_paid': '<true or false>' } });
- Event parameter - First-Time Purchase (
is_first_purchase
) - Example for
gtag.js
:
Indicate whether the event is a first-time or repeat conversion.
javascriptgtag('event', '<event_name>', { 'is_first_purchase': '<true or false>' });
Creating user scoped custom dimensions
It’s recommended to create user level custom dimensions inside your GA4 admin panel for the user properties
ever_paid
and ip_address
.Follow these steps in your GA4 admin panel:
- Go your GA4 property’s Admin settings.
- In the Data display section, select Custom definitions.
- Click on Create custom dimension.
- Set the Scope to
User
.
- In the User property field, enter the name of the user property exactly as it’s sent to GA4 (e.g.,
ever_paid
,ip_address
).
- Click Save.