简体   繁体   中英

How to query Total Events based on Experiment Variant?

I'm looking to query some data from GA through BQ for use in A/B-test analysis.

What I'd like to pull out is how many users were placed into each variant, and what was the total amount of add-to-cart completions.

The following query doesn't quite match up with what I'm seeing in GA (I know there will/can be differences), so I guess I just want to make sure that I've gotten it completely correct.

The following query very closely matches the 'Unique Events' Metric in GA, but I want to make sure that it's showing me the 'Total Events' Metric:

SELECT
  exp_.experimentVariant AS variant,
  COUNT(DISTINCT fullVisitorId) AS users,
  COUNTIF(hits_.eventinfo.eventAction = "add to cart") AS add_to_cart
FROM
  `XXXXX.YYYYY.ga_sessions_*`,
  UNNEST(hits) AS hits_,
  UNNEST(hits_.experiment) AS exp_
WHERE
  exp_.experimentid = "XXXYYYZZZ"
  AND _TABLE_SUFFIX BETWEEN "20220315" AND "20220405"
GROUP BY 
  variant
ORDER BY 
  variant

The reason for why I'm not sure this is quite right is because when I use the following query, the output completely matches the 'Total Events' Metric in GA:

SELECT
  COUNT(DISTINCT fullVisitorId) AS users,
  COUNTIF(hits.eventinfo.eventAction = "add to cart") AS add_to_cart
FROM
  `XXXXX.YYYYY.ga_sessions_*`,
  UNNEST(hits) AS hits
WHERE
  _TABLE_SUFFIX BETWEEN "20220315" AND "20220405"

The query will return all users that had a hit with the specified experimentVariant and all add to cart events that had the specified variant sent together with the hit . In that way it looks correct.

A user segment in GA of users exposed to the experiment will work differently and return a different result. The experiment variant users can also have performed add to cart events that didn't have the experiment paramter sent together with them. For example, the add to cart event could have been sent before the user even became exposed to the experiment. If those events are within the timeframe they will be included if the user is qualified for the segment.

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