Get the location of an ‘add_to_cart ‘ event in BigQuery.
For shop operators it is interesting where the user adds his products to the shopping cart. Does this happen on the search results page, in a category or in the classic product detail?
With good Google Analytics 4 (GA4) data and BigQuery connectivity, this is easy to determine.
- The event ‘add_to_cart’ must be captured in GA4.
- A ‘page_type’ is assigned to the event (or this can be identified differently, e.g. via the URL).
- The GA4 data is streamed to BigQuery.
Code in BigQuery
The procedure is simple:
- GA4 Query data
- extract the event values with UNNEST(event_params )
- to the ‘add_toCart’ event.
The result is a 2-column table with event_date and add_to_cart_location with the values (search_result, product, category …)
Display data in Google Datastudio.
We change the prescribed code so that event_date can be used as a date selector in Google Datastudio.
Decisive here is the line:
AND _table_suffix between @DS_START_DATE and @DS_END_DATE
Which narrows the date range.
The result of the query can then be displayed in Google Datastudio with a pie chart.