Debugging User IDs in GA4 Events

Context

Be weary of Universal IDs for attribution tracking.

Some work great! But but they can easily break Google Analytics tracking and worsen Facebook signal if misconfigured.

Here's an example: GA4 is funky about setting User IDs on events. If you add User ID to an event in a website session, and then you send GA4 subsequent events in the same session without a User ID, the user will actually get double counted. Same if User IDs change in the session.

This bug can throw off your event data if the Universal ID is slow to load, or if you have multiple applications firing GA4 events.

I've literally seen many examples where the same Shopify shopper gets counted as 5 different users in the same session!!

Snippet

If you're curious about this issue for your own site, connect GA4 to BigQuery and run this SQL statement:

WITH ExtractedParams AS (
    SELECT DISTINCT
        event_bundle_sequence_id,
        (SELECT value.int_value FROM UNNEST(event_params) WHERE key = 'ga_session_id') AS ga_session_id,
        (SELECT value.int_value FROM UNNEST(event_params) WHERE key = 'ga_session_number') AS ga_session_number,
        (SELECT value.string_value FROM UNNEST(event_params) WHERE key = 'page_location') AS page_location,
        (SELECT value.string_value FROM UNNEST(event_params) WHERE key = 'transaction_id') AS transaction_id,
    FROM 
        `BQ_PROJECT.BQ_DATASET.EVENT_TABLE` -- EDIT ME
)

SELECT 
    FORMAT_TIMESTAMP('%Y-%m-%d %I:%M:%S %p', TIMESTAMP_MICROS(e.event_timestamp), "America/Denver") as formatted_date_in_denver_time, -- Or whatever you want.
    e.event_name,
    ep.ga_session_id,
    ep.ga_session_number,
    e.user_pseudo_id,
    e.user_id,
    --e.event_bundle_sequence_id,
    ep.transaction_id,
    --ep.page_location,
    geo.metro,
    device.operating_system_version,
    device.web_info.browser,
    ecommerce.purchase_revenue,
    ecommerce.tax_value,
    ecommerce.shipping_value,
    --e.*
FROM 
    `BQ_PROJECT.BQ_DATASET.EVENT_TABLE` e -- EDIT ME
LEFT JOIN
    ExtractedParams ep
ON 
    e.event_bundle_sequence_id = ep.event_bundle_sequence_id
    --WHERE e.event_name like "purchase"
    --WHERE ep.ga_session_id = 123456789
ORDER BY 
    ep.ga_session_id,
    e.event_timestamp DESC

Last updated