This is the query we are using> ```SELECT user_...
# ask-questions
w
This is the query we are using>
Copy code
SELECT
  user_pseudo_id as anonymous_id,
  TIMESTAMP_MICROS(event_timestamp) as timestamp,
  experiment_id_param.value.string_value AS experiment_id,
  variation_id_param.value.int_value AS variation_id,
  geo.country as country,
  traffic_source.source as source,
  traffic_source.medium as medium,
  device.category as device,
  device.web_info.browser as browser,
  device.operating_system as os
FROM
  `learning-heroes-bq`.`analytics_372696867`.`events_*`,
  UNNEST(event_params) AS experiment_id_param,
  UNNEST(event_params) AS variation_id_param
WHERE
  ((_TABLE_SUFFIX BETWEEN '{{date startDateISO "yyyyMMdd"}}' AND '{{date endDateISO "yyyyMMdd"}}') OR
   (_TABLE_SUFFIX BETWEEN 'intraday_{{date startDateISO "yyyyMMdd"}}' AND 'intraday_{{date endDateISO "yyyyMMdd"}}'))
  AND event_name = 'experiment_viewed'
  AND experiment_id_param.key = 'experiment_id'
  AND variation_id_param.key = 'variation_id'
Now I'm able to see the data for 1 user, this is the query I'm using:
Copy code
SELECT
  user_pseudo_id AS anonymous_id,
  TIMESTAMP_MICROS(event_timestamp) AS timestamp,
  -- experiment_id: string si viene como string; si viene como int, lo casteamos a string
  COALESCE(
    (SELECT ep.value.string_value FROM UNNEST(event_params) ep
     WHERE ep.key IN ('experiment_id','experimentid','experimentId') LIMIT 1),
    CAST((
      SELECT ep.value.int_value FROM UNNEST(event_params) ep
      WHERE ep.key IN ('experiment_id','experimentid','experimentId') LIMIT 1
    ) AS STRING)
  ) AS experiment_id,
  -- variation_id: INT64; prioriza int_value y si viniera como string, hace SAFE_CAST
  CAST(
    COALESCE(
      (SELECT ep.value.int_value FROM UNNEST(event_params) ep
       WHERE ep.key IN ('variation_id_int','variation_id','variationid','variationId') LIMIT 1),
      SAFE_CAST((
        SELECT ep.value.string_value FROM UNNEST(event_params) ep
        WHERE ep.key IN ('variation_id_int','variation_id','variationid','variationId') LIMIT 1
      ) AS INT64)
    ) AS INT64
  ) AS variation_id,
  geo.country AS country,
  traffic_source.source AS source,
  traffic_source.medium AS medium,
  device.category AS device,
  device.web_info.browser AS browser,
  device.operating_system AS os
FROM `learning-heroes-bq.analytics_372696867.events_*` t
WHERE
  ((_TABLE_SUFFIX BETWEEN '{{date startDateISO "yyyyMMdd"}}' AND '{{date endDateISO "yyyyMMdd"}}') OR
   (_TABLE_SUFFIX BETWEEN 'intraday_{{date startDateISO "yyyyMMdd"}}' AND 'intraday_{{date endDateISO "yyyyMMdd"}}'))
  AND event_name = 'experiment_viewed'
  AND user_pseudo_id IS NOT NULL
  -- Garantiza que ambos params existan
  AND EXISTS (
    SELECT 1 FROM UNNEST(event_params) ep
    WHERE ep.key IN ('experiment_id','experimentid','experimentId')
  )
  AND EXISTS (
    SELECT 1 FROM UNNEST(event_params) ep
    WHERE ep.key IN ('variation_id_int','variation_id','variationid','variationId')
  )
But I'm not sure if will work OK.
It's not working 😞 I suspect I need to add the tracking callback script even though I'm using the Script tag with GA4.