Hello, Somebody had a problem with the metric when...
# ask-questions
c
Hello, Somebody had a problem with the metric when you added
purchase
with GA4 as the data source? I added SQL below, and I got an error and I don't know how to fix. What I'm doing wrong?
Copy code
SELECT
  user_id,
  user_pseudo_id as anonymous_id,
  TIMESTAMP_MICROS(event_timestamp) as timestamp,
  event_value_in_usd as value
FROM
  `azos-data`.`analytics_262365471`.`events_*`
WHERE
  event_name = 'purchase'  
  AND value_param.key = 'value'
  AND _TABLE_SUFFIX BETWEEN '{{startYear}}{{startMonth}}{{startDay}}' AND '{{endYear}}{{endMonth}}{{endDay}}'
f
What is the reason for the value_param.key part?
are there more than one kind of purchase events?
c
I fixed the erro, thanks. Other question, about the metric when user is visited a page location. The return should be as 1 ? Do you have some example for page_view metric ?
f
yes
c
Copy code
SELECT
  user_id,
  user_pseudo_id as anonymous_id,
  TIMESTAMP_MICROS(event_timestamp) as timestamp,
  event_params.value.string_value AS page_location,
  1 as value
FROM
  `azos-data`.`analytics_262365471`.`events_*`,
  UNNEST(event_params) AS event_params
WHERE
  event_name = 'page_view'
  AND event_params.key = 'page_location'
  AND event_params.value.string_value LIKE '%GOOGLE.com%'
  AND _TABLE_SUFFIX BETWEEN '{{startYear}}{{startMonth}}{{startDay}}' AND '{{endYear}}{{endMonth}}{{endDay}}'
This code is the best way to create page_view metric?
This SQL code will keep counting the view while browsing, right? How do I set it up to collect once?