Tracking what a user purchases vs the Google Shopping product they clicked on
With GA4 and GTM, we want to put Google Shopping users in 3 buckets:
users who purchased the same product they landed on from Google
users who purchases a different product to the one they landed on
users who did not purchase
Anyone know the best way to do this? I think it would be a case of seeing if the Product ID of the first
view_item
event matches the Product ID of the purchase event, but I don’t know if that can be automated and not without having to focus on one Product ID at a time.
The short answer is:
The most effective and scalable way to bucket your Google Shopping users is by implementing a server-side Google Tag Manager (GTM) setup in Google Cloud Platform (GCP) and leveraging the Google Analytics Measurement Protocol to enrich your purchase event data in Google Analytics 4 (GA4).
The solution involves capturing the initial product ID
from the landing page URL parameter or view_item
event and persisting it as a user_property
or a custom_dimension
in GA4.
On the purchase event, you would compare this stored “initial product ID
” with the product ID
s in the purchase item array.
This server-side approach, potentially integrated with the BigQuery API for complex segment analysis, ensures data consistency, avoids client-side limitations, and provides the necessary logic to create three distinct audience segments: “Same Product Purchased,” “Different Product Purchased,” and “No Purchase
.
The long answer is:
To automate the comparison of the initial product ID
(from the Google Shopping click) with the final purchased product ID
, you’ll need to move beyond simple client-side tracking and adopt a robust, server-side architecture, utilizing Google Tag Manager (GTM) Server Container hosted on Google Cloud Platform (GCP).
The core mechanism is to capture the initial product data and persist it throughout the user’s session.
When a user lands from Google Shopping, the product ID
is typically available in the view_item
data layer event or potentially extracted from a URL parameter like gclid
in conjunction with your product feed data – but the view_item
product ID
is the most direct path.
You must capture this initial item_id
and store it as a First View Item ID in a server-side cookie or local storage, which GTM can access.
This stored value should then be sent to Google Analytics 4 (GA4) as a user_property
(if you want it to persist across sessions for a given user) or a custom_dimension
(if you want it tied only to the purchase event for analysis).
When the purchase event is triggered, the server-side GTM can execute a custom script to compare the stored First View Item ID with the item_id
of the products in the items array of the purchase event.
Based on the match logic, a new custom event parameter – such as product_purchase_match_type
with values like same_product
, different_product
, or no_purchase
– is calculated and appended to the purchase event before it is sent to GA4 via the Google Analytics Measurement Protocol from the server container.
The Google Analytics Measurement Protocol is crucial here as it allows you to send fully enriched event data directly and reliably from your server environment.
This server-side logic centralizes the complex comparison, making it a “set-and-forget” implementation, which is significantly more cost-effective than attempting to manage this logic client-side across multiple tag configurations and avoiding potential client-side blockers or failures.
For detailed analysis and complex audience building that goes beyond the standard GA4 interface, you should consider exporting the raw GA4 data to BigQuery and leveraging the BigQuery API to run SQL queries that efficiently segment users based on the product_purchase_match_type
dimension, providing the three buckets and enabling highly targeted Google Ads API remarketing lists.
This entire API and cloud-based integration is cost-effective because it uses native Google ecosystem tools (GTM, GCP, GA4) and automates a complex data process, yielding high-quality, actionable data for optimizing Google Shopping campaigns without requiring constant manual data manipulation.