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.

Add to cart location.png

Requirements

  1. The event ‘add_to_cart’ must be recorded in GA4.
  2. The event is assigned a ‘page_type’ (or this is different, e.g. recognizable via the URL).
  3. The GA4 data is streamed to BigQuery.

Code in BigQuery

The procedure is simple:

  1. GA4 Query data
  2. extract the event values with UNNEST(event_params )
  3. reduce to the ‘add_toCart’ event.
WITH ga_events AS (
 SELECT
  *  
  FROM `MY_GA_INSTANCE`, UNNEST(event_params) as event_params  
  WHERE event_name = 'add_to_cart'
)
SELECT  
  event_date,
  value.string_value as add_to_cart_location
FROM ga_events
WHERE key = 'page_type'

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.

Copy to ClipboardSyntax Highlighter

WITH ga_events AS (
 SELECT
  *  
  FROM `MY_GA4_DATABASE`, UNNEST(event_params) as event_params  
  WHERE event_name = 'add_to_cart'
 AND _table_suffix between @DS_START_DATE and @DS_END_DATE

)
SELECT  
  event_date,
  value.string_value as add_to_cart_location
FROM ga_events
WHERE key = 'page_type'

Decisive here is the line:

AND _table_suffix between @DS_START_DATE and @DS_END_DATE

Which narrows the date range.

Add to cart location code datastudio.png

The result of the query can then be displayed in Google Datastudio with a pie chart.

Bernhard prange webmeisterei

SEA-Experte: Bernhard Prange

Bernhard Prange ist Google Ads Freelancer und Tracking-Spezialist mit über 10 Jahren Erfahrung im Performance-Marketing. Sein Fokus liegt auf datengetriebenem Arbeiten: von Google Shopping über Conversion-Tracking bis hin zu serverseitigen Lösungen mit Matomo und BigQuery.

Als Ansprechpartner für Agenturen, E-Commerce-Unternehmen und B2B-Dienstleister verbindet er technisches Know-how mit strategischem Blick auf Marketing und Geschäftsmodelle.

Beiträge, die dich auch interessieren könnten…

  • Better data, better decisions: Data enrichment in Server-Side Tracking

    Lesen
  • Google Ads DemandGen: The Complete Practical Guide

    Lesen
  • Claude MCP: 30+ Integrations for WordPress, Google Ads & SEO

    Lesen
  • Track User Reading Behavior with Google Tag Manager

    Lesen