> For the complete documentation index, see [llms.txt](https://learn.fueled.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://learn.fueled.io/learning-center/recipes-and-open-source/working-with-ga4-data-in-bigquery/debugging-user-ids-in-ga4-events.md).

# 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:

```sql
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
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://learn.fueled.io/learning-center/recipes-and-open-source/working-with-ga4-data-in-bigquery/debugging-user-ids-in-ga4-events.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
