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

jolly-raincoat-49731

11/16/2023, 2:45 PM
Hi, I'm wondering how we can query GA4 to get the
purchase
event AND get what experiment it was tied to. So far, I have this query which pulls the
experiment_viewed
and what experiment it is along with what variation. What I can't figure out is how to tie that to the
purchase
event.
Copy code
SELECT
  user_id,
  user_pseudo_id AS anonymous_id,
  TIMESTAMP_MICROS(event_timestamp) AS timestamp,
  (SELECT value.string_value FROM UNNEST(event_params) WHERE key = 'experiment_id') AS experiment_id
FROM
  `events_*`
WHERE
  event_name = 'experiment_viewed'
  AND
  (SELECT value.string_value FROM UNNEST(event_params) WHERE key = 'experiment_id') = 'products-aa'
  AND
  (SELECT value.int_value FROM UNNEST(event_params) WHERE key = 'variation_id') = 0
;
I can just get the purchase event by itself too using
event_name = 'purchase'
. I feel I'm close, thanks for any help you can offer!
b

brief-honey-45610

11/16/2023, 3:05 PM
Hi Erik, your request is in our support queue and we'll send an update as soon as we can
👍 1
r

rhythmic-agent-34208

11/17/2023, 12:16 AM
Hi Erik, we are still working through our support queue and haven't forgotten about this! We'll likely have an update for you tomorrow.
f

fresh-football-47124

11/17/2023, 12:51 AM
Hi Erik - the purchase would be added as a metric
the way GrowthBook works is by using that generic query to select all the users who saw the experiment, then we join to the metrics that you care about (purchases, page views, whatever)
so you would define a ‘purchase’ metric generically for reuse
j

jolly-raincoat-49731

11/17/2023, 2:04 PM
@fresh-football-47124 Thanks for the info. So we can't get that info directly from BigQuery then with 1 query?
f

fresh-football-47124

11/18/2023, 7:23 AM
you can get it in one query
we do this automatically for you when getting the experiment data
what is the use case for wanting it in one query?
you could add it as a dimension if you want
j

jolly-raincoat-49731

11/20/2023, 2:20 PM
@fresh-football-47124 Our marketing director likes to run his own queries against our data in our actual site database and would benefit from running this type of query in BigQuery as well outside of GrowthBook.
f

fresh-football-47124

11/25/2023, 3:50 AM
we give you the raw queries we use for any data shown
j

jolly-raincoat-49731

11/27/2023, 2:13 PM
Sorry for the ignorance. How can I find the query for what I am asking for above?
r

rhythmic-agent-34208

11/28/2023, 1:25 AM
Hi Erik, no worries at all! We're here to help. What Graham was describing is the process of combining the Experiment Assignment Query with the Metric Query. This creates a joined query that will derive the metric results from users who were assigned to the experiment. You can find all such queries by following these steps: 1. Go to a running experiment in GrowthBook. 2. Click on the '3 Dots' menu within the Analysis Settings. 3. Look for the ​`View Queries`​ option and select it. Your colleague should be able to copy this SQL code and run it directly on the database.
Here are some screenshots of sample data to help you find this, in the order of the steps listed above:
2 Views