{"id":1980,"date":"2021-10-05T15:34:59","date_gmt":"2021-10-05T13:34:59","guid":{"rendered":"https:\/\/webmasterei-prange.de\/page-location-for-add_to_cart-events-in-bigquery\/"},"modified":"2025-10-06T20:53:18","modified_gmt":"2025-10-06T18:53:18","slug":"page-location-for-add_to_cart-events-in-bigquery","status":"publish","type":"post","link":"https:\/\/webmasterei-prange.de\/en\/page-location-for-add_to_cart-events-in-bigquery\/","title":{"rendered":"Page Location for add_to_cart events in BigQuery"},"content":{"rendered":"\n<p>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?<\/p>\n\n<p>With good Google Analytics 4 (GA4) data and BigQuery connectivity, this is easy to determine.<\/p>\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"580\" height=\"300\" src=\"https:\/\/webmasterei-prange.de\/wp-content\/uploads\/2025\/09\/add_to_cart-location.png.webp\" alt=\"Add to cart location.png\" class=\"wp-image-1286\"\/><\/figure>\n\n<h2 class=\"wp-block-heading\" id=\"toc_Voraussetzungen\">Requirements<\/h2>\n\n<ol class=\"wp-block-list\">\n<li>The event &#8216;add_to_cart&#8217; must be recorded in GA4.<\/li>\n\n\n\n<li>The event is assigned a &#8216;page_type&#8217; (or this is different, e.g. recognizable via the URL).<\/li>\n\n\n\n<li>The GA4 data is streamed to BigQuery.<\/li>\n<\/ol>\n\n<h2 class=\"wp-block-heading\" id=\"toc_Code_in_BigQuery\">Code in BigQuery<\/h2>\n\n<p>The procedure is simple:<\/p>\n\n<ol class=\"wp-block-list\">\n<li>GA4 Query data<\/li>\n\n\n\n<li>extract the event values with UNNEST(event_params )<\/li>\n\n\n\n<li>reduce to the &#8216;add_toCart&#8217; event.<\/li>\n<\/ol>\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"sql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">WITH ga_events AS (\n SELECT\n  *  \n  FROM `MY_GA_INSTANCE`, UNNEST(event_params) as event_params  \n  WHERE event_name = 'add_to_cart'\n)\nSELECT  \n  event_date,\n  value.string_value as add_to_cart_location\nFROM ga_events\nWHERE key = 'page_type'\n<\/pre>\n\n<p>The result is a 2-column table with event_date and add_to_cart_location with the values (search_result, product, category \u2026)<\/p>\n\n<h2 class=\"wp-block-heading\" id=\"toc_Daten_in_Google_Datastudio_darstellen\">Display data in Google Datastudio.<\/h2>\n\n<p>We change the prescribed code so that event_date can be used as a date selector in Google Datastudio.<\/p>\n\n<p>Copy to ClipboardSyntax Highlighter<\/p>\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"sql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">WITH ga_events AS (\n SELECT\n  *  \n  FROM `MY_GA4_DATABASE`, UNNEST(event_params) as event_params  \n  WHERE event_name = 'add_to_cart'\n AND _table_suffix between @DS_START_DATE and @DS_END_DATE\n\n)\nSELECT  \n  event_date,\n  value.string_value as add_to_cart_location\nFROM ga_events\nWHERE key = 'page_type'\n<\/pre>\n\n<p>Decisive here is the line:<\/p>\n\n<p><em> AND _table_suffix between @DS_START_DATE and @DS_END_DATE<\/em><\/p>\n\n<p>Which narrows the date range.<\/p>\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"399\" src=\"https:\/\/webmasterei-prange.de\/wp-content\/uploads\/2025\/09\/add_to_cart-location-code-datastudio.png-1024x399.webp\" alt=\"Add to cart location code datastudio.png\" class=\"wp-image-1287\"\/><\/figure>\n\n<p>The result of the query can then be displayed in Google Datastudio with a pie chart.<\/p>\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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. Requirements Code&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_kad_blocks_custom_css":"","_kad_blocks_head_custom_js":"","_kad_blocks_body_custom_js":"","_kad_blocks_footer_custom_js":"","_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","slim_seo":{"title":"Using Page Location for Add_to_Cart Events in BigQuery","description":"How to track page location for Add_to_Cart events in BigQuery \u2013 explained step by step, including setup and query examples."},"footnotes":""},"categories":[25],"tags":[],"class_list":["post-1980","post","type-post","status-publish","format-standard","hentry","category-website-tracking"],"taxonomy_info":{"category":[{"value":25,"label":"Website tracking"}]},"featured_image_src_large":false,"author_info":{"display_name":"admin","author_link":"https:\/\/webmasterei-prange.de\/en\/author\/admin\/"},"comment_info":0,"category_info":[{"term_id":25,"name":"Website tracking","slug":"website-tracking","term_group":0,"term_taxonomy_id":25,"taxonomy":"category","description":"","parent":0,"count":12,"filter":"raw","cat_ID":25,"category_count":12,"category_description":"","cat_name":"Website tracking","category_nicename":"website-tracking","category_parent":0}],"tag_info":false,"_links":{"self":[{"href":"https:\/\/webmasterei-prange.de\/en\/wp-json\/wp\/v2\/posts\/1980","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webmasterei-prange.de\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webmasterei-prange.de\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webmasterei-prange.de\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/webmasterei-prange.de\/en\/wp-json\/wp\/v2\/comments?post=1980"}],"version-history":[{"count":1,"href":"https:\/\/webmasterei-prange.de\/en\/wp-json\/wp\/v2\/posts\/1980\/revisions"}],"predecessor-version":[{"id":1981,"href":"https:\/\/webmasterei-prange.de\/en\/wp-json\/wp\/v2\/posts\/1980\/revisions\/1981"}],"wp:attachment":[{"href":"https:\/\/webmasterei-prange.de\/en\/wp-json\/wp\/v2\/media?parent=1980"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webmasterei-prange.de\/en\/wp-json\/wp\/v2\/categories?post=1980"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webmasterei-prange.de\/en\/wp-json\/wp\/v2\/tags?post=1980"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}