简体   繁体   中英

Problems with CWV data - GA4 + BigQuery + Data Studio

Following this guide https://web.dev/vitals-ga4 , in Google Cloud Platform I'm seeing this: https://i.stack.imgur.com/NSy5h.jpg

Using this query https://web.dev/vitals-ga4/#analyze I'm getting this https://i.stack.imgur.com/AV1iy.png

As the blog post mention "For Web Vitals events, the last value sent is always the most accurate one, so before performing any analysis, it's important to filter for just those values. The code snippet provided by the web-vitals JavaScript library to send data to Google Analytics 4 includes sending a unique ID per metric, so you can use the following query to limit your results to just the last-received value for each metric ID:"

I used this query https://web.dev/vitals-ga4/#query-web-vitals-data and I'm getting a syntax error https://i.stack.imgur.com/72ScT.png

(sry for no links, but I don't have enough reputation to use them - and I will post any screen shoot that will help in comm)

That WITH statement appears to only be the first half of the query. The error message is saying that you need a corresponding SELECT statement to make use of the web_vitals_events common table expression (CTE).

See the Example queries section further down for full, working query samples. Here's an example query to get the 75th percentiles for each CWV metric:

# Subquery all Web Vitals events from the last 28 days
WITH web_vitals_events AS (
  SELECT event_name as metric_name, * EXCEPT(event_name, is_last_received_value) FROM (
    SELECT *, IF (ROW_NUMBER() OVER (
      PARTITION BY (SELECT value.string_value FROM UNNEST(event_params) WHERE key = 'metric_id')
      ORDER BY (SELECT COALESCE(value.double_value, value.int_value) FROM UNNEST(event_params) WHERE key = 'metric_value') DESC
    ) = 1, true, false) AS is_last_received_value
    FROM `bigquery_project_id.analytics_XXXXX.events_*`
    WHERE event_name in ('CLS', 'FID', 'LCP') AND
      _TABLE_SUFFIX BETWEEN FORMAT_DATE('%Y%m%d', DATE_SUB(CURRENT_DATE, INTERVAL 28 DAY)) AND FORMAT_DATE('%Y%m%d', DATE_SUB(CURRENT_DATE, INTERVAL 1 DAY))
  ) WHERE is_last_received_value
)

# Main query logic
SELECT
  metric_name,
  APPROX_QUANTILES(metric_value, 100)[OFFSET(75)] AS p75,
  COUNT(1) as count
FROM (
  SELECT
    metric_name,
    ROUND((SELECT COALESCE(value.double_value, value.int_value) FROM UNNEST(event_params) WHERE key = "metric_value"), 3) AS metric_value,
  FROM web_vitals_events
)
GROUP BY 1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM