Do your website or app users have the ability to create an account and log in? Then you can collect a
userId (or a custom identity id stored in a user property) in Google Analytics 4. If implemented correctly, this value will not only be used by GA4 to stitch users on different devices, but the user id will also be available in the BigQuery data export for you to utilise. One of our premium subscribers noticed this and asked:
'Is it possible to stitch userId retroactively to clientId? Scenario: Visitor made 10 events. Then logged in. We want to be able to recognize the user for the previous 10 events when the user was anonymous and not yet logged in.'
Is it possible? Yes, this tutorial will guide you show you exactly how to accomplish this.
By default - when no custom user id is collected - the 'best' identifier available in the GA4 data export is the
user_pseudo_id, also known as
clientId. This is an id GA4 uses to identify a browser on a specific device, based on a cookie that is stored client side. Using this identifier - in combination with
event_timestamp - we can list all events (and sessions) in the order they happened for every anonymous user.
We can do the same, but then cross-browser and cross-device, for users that logged in at least once in every browser, as long as there is a user id sent to GA4 at login. This is called user (back)stitching. Possible use cases include:
- creating a frequently updated
user_pseudo_idmapping table to query for later use
- connect online user behaviour with data from you CRM
- creating an advanced path explorer (using
- usage as input in (attribution) models
Although the outcomes of this tutorial will provide you a better view on the behaviour of users than when there is no
user_id available, it is good to remember the limitations of this approach. Users that don't want to be tracked and block the GA4 tracking script, will still not show up in your reports. Furthermore, this tutorial assumes that a
user_id is always unique for a customer account.
For this tutorial I will use the - anonymous -
user_id that GA4 collects for logged in subscribers on this website. These ids can and will not be tied to actual persons and are only used for analytical purposes.