Search code examples
google-bigquerygoogle-analyticsgoogle-analytics-4

How Create User ID for GA4 to BigQuery


Purpose

I want to create user_id in GA4 which was linked to BigQuery.

What I've tried

I followed this document:

  1. GTM to manage GA4.

  2. GA4 links to BigQuery.

    (Now I got data from my website, and data can collect in BigQuery.)

  3. Passed user_id to dataLayer:

    • I've added the following script in HEADER which above gtm.js.

    • I'm not sure whether using a string (USER_ID) as input at this step will affect the result or not.

    <script>
       dataLayer.push({
         'user_id': 'USER_ID'
       });
    </script>
    
  4. Create variable of dataLayer:

    enter image description here

  5. Adjust GTM code:

    enter image description here

Expected & Results

  • I expected that I build comparision like:

    enter image description here

    However, I cannot do that:

    enter image description here

  • I expected my BigQuery can get a new column user_id (no happen)

Questions

  • Did I mess up something in the process?
  • Could the user_id passed from the front-end and back-end be passed to BigQuery as I expected?

Solution

  • From your process 5

    The key should be user_id Not userId. It's different for GA4.

    Follow the document