https://www.growthbook.io/ logo
#ask-questions
Title
# ask-questions
c

cuddly-journalist-11507

04/13/2023, 4:13 PM
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

fresh-football-47124

04/13/2023, 7:01 PM
What is the reason for the value_param.key part?
are there more than one kind of purchase events?
c

cuddly-journalist-11507

04/14/2023, 3:51 PM
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

fresh-football-47124

04/14/2023, 11:31 PM
yes
c

cuddly-journalist-11507

04/17/2023, 3:39 PM
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?
25 Views