Sub topic 3
Validating events with DebugView and Realtime reports
This chapter assumes you have a GA4 property with a web data stream, can edit your site or Google Tag Manager container, and understand the purchase event and items array from earlier chapters.
Validating events with DebugView and Realtime reports
DebugView shows each event from one device with its parameters. Realtime shows aggregate activity from the last 30 minutes. Use DebugView to check event structure and Realtime to confirm that events arrive at all.
Enable debug mode on your own browser with the debug_mode setting:
gtag('config', 'G-XXXXXXX', { debug_mode: true });Tracking refunds
Send a refund event with the same transaction_id as the original purchase. For a partial refund, list only the returned items and their value.
How revenue metrics are calculated
Purchase revenue comes from the value parameter of purchase events. Refund events reduce revenue in reports. GA4 documents the exact formulas in each report's help text, so check there when numbers differ from your expectations.
Reading Monetization reports and building explorations
The Monetization reports show purchases, item revenue, and item views. For detail, open Explore, choose a free-form table, put Item name in rows, and add Item revenue and Items purchased as values.
Promotion tracking: view_promotion and select_promotion
view_promotion fires when a promotion appears. select_promotion fires when a user clicks it. Include promotion_id, promotion_name, and creative_name.
Sending purchases and refunds server-side with the Measurement Protocol
The Measurement Protocol accepts events by HTTP POST to https://www.google-analytics.com/mp/collect, with measurement_id and api_secret as query parameters. Reuse the transaction_id from the browser purchase so you do not count the same sale twice.
Item-scoped custom dimensions
Register a custom dimension with item scope in Admin, then send that parameter inside each items entry. Reports only show the dimension for data collected after you register it.
Querying the items array in the BigQuery export
The items field is a repeated record. Use UNNEST to query it:
SELECT item.item_name, SUM(item.item_revenue) AS revenue
FROM `project.analytics_123.events_*`, UNNEST(items) AS item
WHERE event_name = 'purchase'
GROUP BY item.item_name;Common data-quality pitfalls and how to avoid them
- A reloaded thank-you page sends a second purchase. Fire the event once, or check for the
transaction_idbefore sending. - Sending
valuewithoutcurrencyleaves revenue unreadable. - Sending prices as strings with currency symbols breaks numeric totals.
- Skipping refund events overstates revenue.
Exercise
A purchase appears in Realtime but not in DebugView. What is the most likely cause?
Show answer
Debug mode is not enabled on the browser you are watching, so DebugView has no events from it. Realtime counts all traffic, so it still shows the purchase.