An eCommerce tracking plan: what your shop should measure, and how to write it down
TL;DR
Difficulty: Beginner
A tracking plan is a short table that says which events your shop sends, when, with which details, who owns each one, which consent it needs and where it goes.
- Start from the weekly questions and the decisions they change, and track only what serves them.
- Use Google's thirteen recommended eCommerce events with their own names, fill the items array every time, and use the SKU as the one product identifier.
- Write naming rules once, budget the ten item scoped custom dimensions, and keep personal data out by rule and by test.
- Let consent decide what fires, push events from the server confirmed state, and test the data layer automatically before every release.
Most shops install a tag first and ask questions later, and end up with hundreds of events nobody can explain. This chapter works the other way round: from the questions an owner asks every week to a tracking plan that names every event, its trigger, its parameters, its owner, its consent and its destination. All of it is worked through on one invented homeware shop in Limerick, with Rails code and a browser test at the end.
Questions first, events second
Most shops start tracking the wrong way round. Someone installs a tag, ticks every box the plugin offers, and a year later the reports hold hundreds of events that nobody can explain. Revenue in one report does not match revenue in another, half the events have no product attached, and the one question the owner actually has still has no answer.
This chapter answers a simpler question: what exactly should my shop measure, and how do I write it down? The answer is a tracking plan. It is a short document that lists every event the shop sends, when it fires, what it carries, who owns it, which consent it needs and where it goes. Everything else in this series (the purchase event, server events, product analytics, reconciliation and attribution) builds on it.
A tracking plan starts with questions, not with events. An event is only worth sending if it helps answer a question that leads to a decision. So before any code, write down the five to ten questions the business asks every week, and the decision each answer would change. Then work out which events, and which details on those events, you need to answer them.
A few terms first, so nobody is left behind. An event is one thing a visitor did, recorded with a name, such as "viewed a product". A parameter is a detail attached to the event, such as which product and at what price. Google Analytics 4 (GA4) is Google's current analytics product, and the event names in this chapter come from its documentation. A tag is a small piece of code that sends events to a tool such as GA4 or Meta.
Example: the questions Niamh asks every week
Shannonside Home is the invented homeware shop I use throughout this series. It sells ceramics, kitchen textiles, lamps and small furniture from Limerick at shannonsidehome.example, about 1,400 products, and ships across Ireland and to a few neighbouring countries. Niamh owns it, Callum is her developer. The example's baseline: 110,000 sessions a month, a conversion rate of 1.8%, an average order value of €84, a 52% gross margin on product, €16,500 a month on Google and Meta ads and a newsletter of 38,000 subscribers.
Niamh writes down her weekly questions and the decision behind each one:
| Question | Decision it changes | What must be measured |
|---|---|---|
| Which homepage and category lists get products clicked? | Which lists to keep, reorder or drop | Each list shown, each product clicked in it, its position |
| Which products get viewed a lot and bought rarely? | Fix the page, the price or the photos, or delist | Product views and add to basket per product |
| Where in checkout do people give up? | Which checkout step to fix first | Each checkout step reached |
| Do the spring banners earn their place? | Keep, change or remove a banner | Banner shown, banner clicked |
| What does each channel bring in revenue? | Where the next euro of ad spend goes | Purchases with order value and the campaign |
Five questions, five decisions. Every event in Shannonside's plan will trace back to at least one of these rows. If Callum later proposes an event that serves none of them, it does not go in. That single rule keeps a tracking plan small enough to test, and a plan that is tested is one Niamh can believe.
An event, its parameters and the items array
Every event in an online shop has the same shape: a name, a few parameters about the event itself, and a list of the products involved. Google calls that list the items array. An array is simply a list, and each entry in it is one product with its own details.
Google's reference for the recommended events says that every item needs at least an item_id or an item_name, and that everything else is optional: price, quantity, discount, index, item_brand, item_category to item_category5, item_variant, item_list_id, item_list_name, location_id and affiliation among them. If quantity is not set, it counts as 1.1
At the event level, two parameters matter most for money. value is the monetary value of the event, and Google says it should be the sum of price times quantity for all items, without shipping or tax. currency is the three letter ISO 4217 code, such as EUR, and Google says it is required whenever you set a value, or revenue metrics will not be computed accurately.1
The reason to fill the items array properly, every time, is that product reports in GA4 are built from it. An add_to_cart event without items tells you somebody added something. With items, it tells you which lamp, in which colour, at which price, from which list.
Example: one product view at Shannonside
A visitor opens the page for the Ash table lamp in oat linen. It costs €74.90 on the page. Shannonside shows prices including VAT, because it sells to consumers, and the standard rate of VAT in Ireland is 23%.2
Google's reference asks for value without tax.1 So Callum sends prices without VAT, and writes that decision into the plan. Chapter two of this series, the purchase event done right, works through the VAT and shipping decision in full. Here it is enough to convert one price. The net price is the gross price divided by one plus the VAT rate (see Foundations: percentages if that step is new):
where is the price without VAT, is the price the customer sees, and is the VAT rate written as a decimal, so for 23%.
Worked through for the lamp:
So , and the event Shannonside sends when the page loads carries one item:
{
"event": "view_item",
"ecommerce": {
"currency": "EUR",
"value": 60.89,
"items": [
{
"item_id": "SH-LAMP-ASH-OAT",
"item_name": "Ash table lamp",
"item_brand": "Shannonside",
"item_category": "Lighting",
"item_category2": "Table lamps",
"item_variant": "Oat linen",
"price": 60.89,
"quantity": 1
}
]
}
}
The item_id is the SKU (stock keeping unit, the shop's own product code). Using the SKU rather than a database number matters, because the same SKU appears in the product feed for Google Shopping, in the Meta catalogue and in the order records. One identifier, everywhere, is what lets you join the data later.
The thirteen events Google recommends for a shop
Google publishes a list of recommended eCommerce events with fixed names and fixed parameters. Use them. They are the names GA4's built in reports understand, and a shop that invents its own (productView, basket_add) gets empty eCommerce reports in return.1
| Event | When it fires | Required by Google | Useful extras |
|---|---|---|---|
view_item_list | A list of products is shown: category page, search results, homepage row, related products | items | item_list_id, item_list_name, index per item |
select_item | A product in a list is clicked | items | the same list details |
view_item | A product page is shown | items, and currency with value | variant, category |
add_to_cart | A product is added to the basket | items, and currency with value | quantity |
remove_from_cart | A product is removed from the basket | items, and currency with value | quantity |
view_cart | The basket page is shown | items, and currency with value | |
begin_checkout | The first checkout step is shown | items, and currency with value | coupon |
add_shipping_info | The visitor chooses a delivery method | items, and currency with value | shipping_tier, coupon |
add_payment_info | The visitor chooses a payment method | items, and currency with value | payment_type, coupon |
purchase | The order is complete | transaction_id, items, and currency with value | tax, shipping, coupon, customer_type |
refund | Money goes back to the customer | transaction_id, and currency with value | items for item refunds |
view_promotion | An internal banner or promotion is shown | items | promotion_id, promotion_name, creative_name, creative_slot |
select_promotion | An internal promotion is clicked | none strictly, but leave out items and some reports drop it | the same promotion details |
"Required" here means what Google's reference marks as required. Where currency and value are listed together, the rule is the one above: if you send a value, the currency must come with it.1
Two words in that table need care. GA4 says "cart" and Shannonside's site says "basket". The event names stay exactly as Google writes them, because they are identifiers, not prose. The labels your customers see stay in the words they use.
Example: one visit at Shannonside, event by event
A visitor arrives from a Google Shopping ad on a Tuesday evening. Here is what they do and what the plan says should fire:
Counted up, a complete visit fires nine eCommerce events: view_item_list, select_item, view_item, add_to_cart, view_cart, begin_checkout, add_shipping_info, add_payment_info and purchase, on top of the page_view events GA4 records by itself. The visitor who leaves after the product page fires three. Each answers a different row of Niamh's question table: the list events answer the first, the product and basket events the second, the checkout steps the third, and the purchase the fifth.
Lists and promotions: the events most shops forget
Most shops send view_item and purchase and stop there. The list and promotion events are the ones that answer merchandising questions, and they are the ones most often missing.
view_item_list fires when a list of products is shown, and select_item when one of them is clicked. Both carry item_list_id and item_list_name, and Google says the item level values win over the event level ones when both are set.1 Each item can also carry index, its position in the list. With those three details you can compare lists with each other and positions within a list.
view_promotion and select_promotion do the same for internal banners: the spring sale tile on the homepage, the free delivery strip, the "new in" panel. They carry promotion_id, promotion_name, creative_name and creative_slot.1
The number these events unlock is the list click through rate: how often a list that was shown led to a product being clicked. The formula is a plain ratio (see Foundations: ratios and rates):
where is the click through rate of list , is the number of select_item events from that list, and is the number of view_item_list events for that list in the same period.
Example: two lists on the Shannonside homepage
In one invented month, the "Bestsellers" row on the homepage is shown 38,000 times and gets 2,660 clicks. The "Recently viewed" row is shown 21,000 times and gets 1,890 clicks. The "You may also like" row on product pages is shown 52,000 times and gets 1,560 clicks.
Worked through, one list at a time:
That gives . For the Recently viewed row:
That gives . And for the related products row:
That gives .
So 7.0% of Bestsellers impressions, 9.0% of Recently viewed impressions and 3.0% of related product impressions lead to a click. The related products row is shown most and clicked least. That is a merchandising decision Niamh can now make, and she could not make it without item_list_id on both events. Product and category analytics, chapter four of this series, takes these numbers much further.
One caution. Count an impression only when the list was actually seen, not when it was built off screen at the bottom of a long page. Callum fires view_item_list when at least half of the row has scrolled into view, and writes that trigger into the plan. Whatever rule you choose, write it down, or two developers will count it two ways.
The checkout steps show where people give up
Between the basket and the order there are usually three or four screens. Each one loses some people. The checkout events, begin_checkout, add_shipping_info and add_payment_info, mark the moments a visitor gets past each one.1 Without them, the checkout is a black box: people go in and fewer come out.
Two extra parameters make these events far more useful. shipping_tier on add_shipping_info records the delivery option chosen, such as "standard" or "next day". payment_type on add_payment_info records card, PayPal or another method.1 Both turn a step count into an answer: are people leaving because of the delivery price, or because their preferred way to pay is missing?
The number to compute is the step conversion rate: the share of visitors who reached one step that also reached the next.
where is the conversion rate from step to the next step, is the number of sessions that reached step , and is the number that reached the step after it. It is the same ratio as before, so the Foundations: ratios and rates section covers it.
Example: Shannonside's checkout in one month
Shannonside has 110,000 sessions a month and converts 1.8% of them, so it takes orders. The plan's events show where the other sessions stopped. The step counts below are invented for the example, chosen to fit that baseline:
The step conversion rates, worked through one by one:
| From | To | Calculation | Step rate |
|---|---|---|---|
| Sessions | Viewed a product | 55,000 / 110,000 | 50.0% |
| Viewed a product | Added to basket | 9,900 / 55,000 | 18.0% |
| Added to basket | Began checkout | 4,950 / 9,900 | 50.0% |
| Began checkout | Chose delivery | 3,600 / 4,950 | 72.7% |
| Chose delivery | Chose payment | 2,700 / 3,600 | 75.0% |
| Chose payment | Purchased | 1,980 / 2,700 | 73.3% |
Multiply the six step rates together and you get back the conversion rate: . That check is worth doing on your own numbers, because if it does not come back to the conversion rate in your shop database, an event is missing or firing twice.
Within checkout, the delivery step loses 27.3% of the people who reach it. Because add_shipping_info carries shipping_tier, Callum can see that almost nobody picks next day delivery at €7.95, and Niamh can test the price. The eCommerce funnel stage by stage shows how to read and fix each of these drops.
Purchase and refund: the two events that carry the money
The purchase event is the one everything else is judged against. Google lists transaction_id, items, currency and value for it, with tax, shipping, coupon and customer_type as optional extras.1 The transaction_id is the order number, and it is what lets every later system recognise the same order.
The refund event sends money back the other way. It needs the same transaction_id, and Google recommends adding the refunded items if you want refunds per product.1 A shop that never sends refunds will always show more revenue in analytics than in its bank account.
Both events carry so many traps (duplicate purchases on reloaded thank you pages, payment redirects that never come back, VAT in or out, partial refunds) that the next chapter is devoted to them. For the tracking plan, the decisions to record now are the ones below.
Example: Shannonside's purchase row in the plan
A customer buys the Ash table lamp (€74.90 including VAT) and two linen tea towels at €14.90 each including VAT. Delivery is €4.95. Callum's plan says: value is the net product total, VAT goes in tax, delivery goes in shipping.
Step by step:
- Gross product total: .
- Net product total: . This is
value. - VAT on the products: . This is
tax. - Delivery:
shippingis 4.95, sent as charged.
The customer pays . The event says value 85.04, tax 19.56 and shipping 4.95, and those three add up to the same 109.55. Nothing is lost, it is only sorted into the fields Google defines. Chapter two covers what happens to the VAT on delivery and how to fire the event from the order itself rather than the browser.
Naming conventions: write them once, then never argue again
When you need an event Google does not define, you name it yourself. Without a rule, three developers will produce newsletterSignup, Newsletter Sign Up and sign_up_newsletter for the same thing, and GA4 will count them as three different events.
Google sets the hard limits. Event names may contain letters, numbers and underscores, no spaces, and must start with a letter. They are case sensitive, so my_event and My_Event are two events. Some names are reserved, such as page_view, session_start, scroll and click, and parameter names may not start with _, firebase_, ga_, google_ or gtag..3 An event name can be at most 40 characters long, and so can a parameter name.4
On top of those limits, I keep five house rules in every plan:
- Google's name first. If a recommended event exists, use it, even when the wording feels American.
- All lower case with underscores (written as
snake_case), never camel case, never spaces. - Object, then action, in the order Google uses for its own:
newsletter_signup,size_guide_open,stock_alert_request. - No values in names. Never
add_to_cart_lamporpromo_spring_click. The lamp and the spring promotion belong in parameters. - Units in the plan, not in the value. Money is a number with a separate
currency, a weight is in grams, a lead time is in days, and the plan says so.
Example: tidying Shannonside's old events
Before the plan, Shannonside's old tag set sent these custom events:
AddToBasket
add-to-basket
newsletter
NewsletterSignup_footer
sizeguide_click_lamps
promo_spring_banner_click
Callum maps them, one by one:
| Old name | Problem | New name and parameters |
|---|---|---|
AddToBasket and add-to-basket | two names for one action, Google has a recommended one | add_to_cart with items |
newsletter and NewsletterSignup_footer | vague, and the placement baked into the name | newsletter_signup with form_location: "footer" |
sizeguide_click_lamps | a category inside the name | size_guide_open with the item in items |
promo_spring_banner_click | a promotion inside the name | select_promotion with promotion_id: "spring_2027" |
Six names become four, three of them Google's own. Every report that groups by event name now groups correctly, and the plan has one row per event instead of one row per accident.
Custom parameters and their limits
Google's recommended parameters will not cover everything a homeware shop cares about. Material, colour family, whether an item is made to order, the delivery lead time: all of these are useful, and all are custom parameters you add yourself.
The limits are real, and they are lower than people expect. GA4 accepts up to 25 parameters per event, parameter values of up to 100 characters, and up to 27 custom parameters inside the items array of an eCommerce event.4 To see a custom parameter in reports, you register it as a custom dimension. A standard GA4 property allows 50 event scoped custom dimensions, 25 user scoped ones, 10 item scoped ones and 50 custom metrics, and reporting on a new dimension starts 24 to 48 hours after you create it.5 Data sent before you register it does not appear in standard reports afterwards, so register first and send second.
The ten item scoped dimensions are the scarce ones. Spend them on the product details that drive decisions.
Example: Shannonside's item dimension budget
Niamh wants to know whether made to order furniture converts worse than stock items, whether ceramics in neutral colours outsell bright ones, and whether long delivery times scare buyers off. Callum proposes five item scoped custom parameters:
| Parameter | Example value | Question it serves |
|---|---|---|
material | "stoneware" | Which materials sell |
colour_family | "neutral" | Neutral against bright |
made_to_order | "yes" | Made to order against stock |
lead_time_days | "14" | Long delivery times |
stock_status | "in_stock" | Do low stock badges help |
Five of ten item scoped dimensions used, five held in reserve. Each item now carries the 8 standard details from the lamp example plus 5 custom ones, 13 in all, well under the 27 custom item parameters allowed. At event level, the busiest event, purchase, uses transaction_id, value, currency, tax, shipping, coupon, customer_type and items, 8 of the 25 parameters an event may carry. The plan records all of this, so the next person who wants a new dimension can see at a glance what is left.
The tracking plan document
Now the plan itself. It is a table, kept where the whole business can read it and where changes leave a history: a spreadsheet with version history works, a Markdown file in the shop's code repository works better, because the plan then changes in the same review as the code that implements it.
Each row is one event. The columns that matter:
- Event: the exact name, as sent.
- Trigger: the precise moment it fires, written so that two developers would implement it the same way.
- Parameters: every parameter, with its type and an example value.
- Owner: the one person who answers for the event being right. Not a team, a name.
- Consent category: which consent it needs before it may fire (more below).
- Destination: where it goes: GA4, Google Ads, Meta, the shop's own database.
- Question: which of the business questions it serves. This is the column that stops a plan from growing back into a tangle.
Example: Shannonside's tracking plan, version 1.0
| Event | Trigger | Key parameters | Owner | Consent | Destination | Question |
|---|---|---|---|---|---|---|
view_item_list | Half of a product list is in view, once per list per page view | item_list_id, item_list_name, items with index | Callum | Analytics | GA4 | Lists |
select_item | A product in a list is clicked | the list details, one item with index | Callum | Analytics | GA4 | Lists |
view_item | A product page has rendered | currency, value, one item | Callum | Analytics, Marketing | GA4, Meta | Products |
add_to_cart | The server has saved the line item | currency, value, the item with quantity | Callum | Analytics, Marketing | GA4, Meta | Products |
remove_from_cart | The server has removed or reduced the line item | currency, value, the item | Callum | Analytics | GA4 | Products |
view_cart | The basket page has rendered | currency, value, all items | Callum | Analytics | GA4 | Checkout |
begin_checkout | The first checkout screen has rendered | currency, value, coupon, all items | Callum | Analytics, Marketing | GA4, Meta | Checkout |
add_shipping_info | A delivery method is saved on the order | shipping_tier, currency, value, all items | Callum | Analytics | GA4 | Checkout |
add_payment_info | A payment method is chosen | payment_type, currency, value, all items | Callum | Analytics, Marketing | GA4, Meta | Checkout |
purchase | The order is complete in the shop | transaction_id, value, tax, shipping, currency, coupon, customer_type, all items | Niamh | Analytics, Marketing | GA4, Google Ads, Meta, shop database | Revenue |
refund | A refund is recorded in the shop | transaction_id, value, currency, refunded items | Niamh | Analytics | GA4, shop database | Revenue |
view_promotion | Half of a banner is in view | promotion_id, promotion_name, creative_slot | Callum | Analytics | GA4 | Banners |
select_promotion | A banner is clicked | the promotion details, featured items | Callum | Analytics | GA4 | Banners |
newsletter_signup | The signup is confirmed by the server | form_location | Niamh | Analytics | GA4 | Newsletter |
Fourteen rows, every one tied to a question. Notice two choices in the trigger column. add_to_cart fires when the server has saved the line item, not when the button is pressed, so a button press that fails on stock never counts. And purchase belongs to Niamh, not Callum, because it is the event the money is judged by, and the owner of the money should own its definition.
The plan also records the rules that hold for every row: prices without VAT, currency always EUR, item_id always the SKU, names in snake_case, version number and date at the top. When a row changes, the version goes up and the change log at the bottom says what changed and why.
What never goes into an event: personal data
The fastest way to turn a tracking plan into a legal problem is to let personal data into an event. Google's policy for Analytics is blunt: no data may be passed to Google that Google could use or recognise as personally identifiable information. It names email addresses, personal mobile numbers, and other details, and says the list is not exhaustive.6
The leaks are rarely deliberate. Google lists where they happen: URLs and page titles, data typed into search boxes and form fields, campaign parameters such as utm_term, and every custom dimension.6 A newsletter form that redirects to /thanks?email=priya@example.com sends the email address to GA4 in the page location. A visitor who types an order number and an email address into the site search sends both as a search term.
GA4 offers data redaction for web streams, which removes email addresses on a best effort basis and strips query parameters you name.6 Use it, but treat it as a safety net. The real fix is in the plan: a rule that no parameter ever carries a name, an email address, a phone number, a street address or a free text field, and a test that checks it.
Example: two leaks Callum closes
The first leak: Shannonside's old newsletter form redirected to /newsletter/thanks?email=.... Callum changes the redirect to /newsletter/thanks and keeps the address in the server session only. He also switches on data redaction for the query parameters email and phone in GA4 as a second line of defence.
The second leak: site search terms. Out of 1,000 search terms in one invented week, 6 contain an @ sign, because customers paste their email address into the search box when looking for their order. Callum adds one rule to the code that builds the search event, before anything is sent:
// Drop anything that looks like an email address or a long number
function safeSearchTerm(term) {
if (/@/.test(term)) return '(redacted)'
if (/\d{7,}/.test(term)) return '(redacted)'
return term.trim().toLowerCase().slice(0, 100)
}
Six terms a week now arrive as "(redacted)", and the other 994 still answer the question they were collected for: what people look for and fail to find. The 100 character cut matches GA4's limit for parameter values.4 Site search that sells covers what to do with those terms.
The user ID deserves one more line. If you send GA4 a user ID for logged in customers, it must be an internal, meaningless number, never an email address or a customer reference printed on invoices. Hashing an email address does not make it anonymous, a point chapter three of this series goes into.
Consent categories: what may run before a yes
Every row of the plan carries a consent category, because the law decides what may run before a visitor agrees. This is general information about how the rules apply to a tracking plan, not legal advice. The detail lives in two earlier articles, cookies, consent and tracking across my markets and event tracking and consent mode, so here is only what the plan needs.
In Ireland, Regulation 5 of S.I. No. 336 of 2011, the ePrivacy Regulations, forbids storing or accessing information on a visitor's device unless the visitor has consented after clear and comprehensive information. The only exceptions are storage that is purely technical, for carrying a communication, and storage that is strictly necessary to provide a service the visitor explicitly asked for.7 The Data Protection Commission's guidance asks "do analytics cookies require consent?" and answers with a plain yes. It adds that strictly first party, aggregated analytics, explained clearly and with an easy opt out, is unlikely to be an enforcement priority.8 Unlikely to be enforced is not the same as allowed, and GA4 is not first party analytics in that sense anyway. So in an Irish shop, analytics and advertising tags wait for a yes, and the basket, the login and the record of the consent choice itself may run without one.
For comparison, the rules in my other markets: Germany applies § 25 of the TDDDG9 and Austria § 165 of the TKG 2021,10 both in the same spirit as Ireland. The UK is the one that differs. Since February 2026 its Privacy and Electronic Communications Regulations carry a statistical purposes exception in Schedule A1, under narrow conditions: the sole purpose is statistics to improve the service, the information is shared with nobody except those helping with the improvements, and the visitor is told and can object simply and for free.1112 That exception is UK law. A shop trading from Limerick under Irish law cannot rely on it, so Shannonside's plan treats analytics as consent only.
In the plan, that becomes three categories:
| Category | What it covers | May run before consent? |
|---|---|---|
| Necessary | Basket, login, security, the consent record | Yes |
| Analytics | GA4 and any other measurement tool | No |
| Marketing | Google Ads, Meta and any advertising destination | No |
Google's consent mode carries those categories to its tags. A gtag('consent', 'default', ...) command sets ad_storage, ad_user_data, ad_personalization and analytics_storage to denied, and Google says it must run on every page before any command that sends measurement data. After the visitor's choice, a gtag('consent', 'update', ...) command grants what they agreed to.13
// Runs first on every page, before the Google tag loads
window.dataLayer = window.dataLayer || []
function gtag() { dataLayer.push(arguments) }
gtag('consent', 'default', {
ad_storage: 'denied',
ad_user_data: 'denied',
ad_personalization: 'denied',
analytics_storage: 'denied',
wait_for_update: 500
})
The wait_for_update value tells the Google tag how many milliseconds to wait for the banner's answer before it acts on the defaults.13
Example: which Shannonside events run before consent
Here is how one event in the plan reaches a decision:
Run Shannonside's fourteen rows through it. None of them is strictly necessary in the legal sense: the basket itself is, but an analytics event about the basket is not. So all fourteen wait for consent. view_item, add_to_cart, begin_checkout, add_payment_info and purchase go to Meta and Google Ads as well, so they need the marketing category on top of analytics. A visitor who accepts analytics and declines marketing still counts in GA4, and is invisible to Meta.
This is why the shop's own database matters so much. The order exists whether or not anybody clicked "accept", and chapter three, the shop database as the source of truth, shows how to use it without breaking the rules above.
One plan, several destinations
GA4 is rarely the only destination. Most shops also send events to Meta for its ads, and Meta has its own names. Its standard events include ViewContent, Search, AddToCart, AddToWishlist, InitiateCheckout, AddPaymentInfo and Purchase, and its Purchase event requires currency and value.14 Instead of an items array, Meta uses content_ids (product IDs such as SKUs), contents (a list with an id and a quantity per product), content_type and num_items.14
The plan should not grow a second set of rows for Meta. Keep one row per event, and add a mapping table: GA4 name, Meta name, and how each parameter translates. One source, two outputs, so the two can never drift apart.
Example: Shannonside's mapping from GA4 to Meta
| GA4 event | Meta event | Parameter translation |
|---|---|---|
view_item | ViewContent | item_id becomes content_ids, content_type: "product", same value and currency |
add_to_cart | AddToCart | items become contents with id and quantity |
begin_checkout | InitiateCheckout | contents, plus num_items as the sum of quantities |
add_payment_info | AddPaymentInfo | contents, value, currency |
purchase | Purchase | contents, value, currency (both required by Meta) |
Take the basket from the purchase example: one lamp and two tea towels. For InitiateCheckout, Meta's num_items is . The contents list is two entries, {"id": "SH-LAMP-ASH-OAT", "quantity": 1} and {"id": "SH-TOWEL-LIN-SAGE", "quantity": 2}, and value is the same 85.04 that GA4 receives. Because the same SKUs appear in Shannonside's Meta catalogue, the ads platform can match each event to a product. Meta and TikTok ads for online shops explains why those matches matter for catalogue ads.
From the plan to code: data layer pushes from a Rails view
A plan only matters once it is in the code. The usual bridge between a shop and its tags is the data layer: a JavaScript object that Google Tag Manager and the Google tag read to pass information to tags.15 The shop pushes events into it, and the tags, once consent allows, read from it. A push to the data layer sends nothing anywhere on its own. It is a list in the visitor's browser that the tags read.
Google's Tag Manager guide shows every eCommerce push in two steps: first dataLayer.push({ ecommerce: null }) to clear the previous eCommerce object, then the new event.16 Without the first step, details of the last product can leak into the next event.
Shannonside runs on Ruby on Rails and Solidus, the open source eCommerce framework, and that is how I build shops as well. The examples below follow Solidus's own code: current_pricing_options is a helper Solidus makes available to controllers and views,17 a product's master variant can return its price for those options with price_for_options, and order.contents.add(variant, quantity) returns the saved line item.18
First, a helper that builds one GA4 item from a variant and writes the push:
# app/helpers/analytics_helper.rb
module AnalyticsHelper
IE_VAT = BigDecimal("0.23") # one rate for this example, chapter two covers mixed rates
def ga4_item(variant, quantity: 1, list_id: nil, index: nil)
price = variant.price_for_options(current_pricing_options)
return nil unless price
{
item_id: variant.sku,
item_name: variant.name,
item_variant: variant.options_text.presence,
item_category: variant.product.taxons.first&.name,
price: (price.amount / (1 + IE_VAT)).round(2).to_f,
quantity: quantity,
item_list_id: list_id,
index: index
}.compact
end
def data_layer_push(event, ecommerce)
payload = { event: event, ecommerce: ecommerce }.to_json
javascript_tag(nonce: true) do
<<~JS.html_safe
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({ ecommerce: null });
window.dataLayer.push(#{json_escape(payload)});
JS
end
end
end
In plain words: ga4_item looks up the price the visitor sees, takes the VAT out, and returns a hash with the fields from the plan. compact drops the fields that are empty, so the event never carries a null. data_layer_push writes a small script tag. json_escape makes sure a product name with odd characters can never break out of the script, and nonce: true lets the script run under a strict content security policy.
The product page then pushes view_item as it renders:
<%# app/views/products/show.html.erb %>
<% item = ga4_item(@product.master) %>
<% if item %>
<%= data_layer_push("view_item",
currency: current_pricing_options.currency,
value: item[:price],
items: [item]) %>
<% end %>
For add_to_cart, the plan says the event fires only when the server has saved the line item. So the cart controller records the fact in the flash (the one request store Rails keeps for the next page), and the layout pushes the event on the page that follows:
# app/controllers/cart_items_controller.rb (the add action)
def create
variant = Spree::Variant.find(params[:variant_id])
quantity = params.fetch(:quantity, 1).to_i
line_item = current_order(create_order_if_necessary: true).contents.add(variant, quantity)
if line_item.persisted?
flash[:ga4_add_to_cart] = { "variant_id" => variant.id, "quantity" => quantity }
end
redirect_to cart_path
end
<%# app/views/layouts/application.html.erb, inside <body> %>
<% if (added = flash[:ga4_add_to_cart]) %>
<% item = ga4_item(Spree::Variant.find(added["variant_id"]), quantity: added["quantity"]) %>
<%= data_layer_push("add_to_cart",
currency: current_pricing_options.currency,
value: (item[:price] * item[:quantity]).round(2),
items: [item]) if item %>
<% end %>
Example: what the browser receives for two tea towels
A visitor adds two linen tea towels in sage to the basket. The towel costs €14.90 including VAT. The server saves the line item, the flash holds the variant and the quantity 2, and the basket page renders with this in its source:
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({ ecommerce: null });
window.dataLayer.push({"event":"add_to_cart","ecommerce":{"currency":"EUR","value":24.22,"items":[{"item_id":"SH-TOWEL-LIN-SAGE","item_name":"Linen tea towel","item_variant":"Sage","item_category":"Kitchen textiles","price":12.11,"quantity":2}]}});
The numbers, step by step: the net price is , the quantity is 2, so value is . Notice the order: the unit price is rounded first and then multiplied, which is the same order the shop uses on the invoice, so the two never differ by a cent. If the towel had been out of stock, contents.add would not have saved the line item, the flash would be empty, and no event would fire. That is exactly what the plan's trigger column asked for.
Testing the plan: DebugView and an automated test
A tracking plan that is not tested drifts. A template changes, a field gets renamed, a new developer moves the script, and three months later a report quietly shows nothing. Two kinds of test catch that.
The first is by hand, with GA4's DebugView. You switch on debug mode, either through Tag Assistant or Tag Manager's preview mode, or by adding debug_mode: true to the Google tag, and DebugView shows the events from your own device as they arrive, with every parameter.19 Google adds two warnings worth knowing. Events do not show in debug mode if the visitor has not consented to analytics, so accept the banner on your test device first. And to switch debug mode off, you remove the parameter: setting it to false does not switch it off.19
The second is automated, and it is the one that keeps the plan true over time. A browser test opens a page the way a customer would and checks what landed in the data layer. Playwright, an open source browser testing tool, can run JavaScript inside the page and wait until a condition is true.2021 Because the test reads the data layer rather than the network, it works whether or not the tags are allowed to send.
// spec/e2e/tracking_plan.spec.js
import { test, expect } from '@playwright/test'
const findEvent = (name) => (window.dataLayer || []).find((e) => e.event === name)
test('product page pushes view_item as the plan says', async ({ page }) => {
await page.goto('/products/ash-table-lamp')
const handle = await page.waitForFunction(findEvent, 'view_item')
const push = await handle.jsonValue()
expect(push.ecommerce.currency).toBe('EUR')
expect(push.ecommerce.value).toBeCloseTo(60.89, 2)
expect(push.ecommerce.items[0]).toMatchObject({ item_id: 'SH-LAMP-ASH-OAT', quantity: 1 })
})
test('no event carries an email address', async ({ page }) => {
await page.goto('/products/ash-table-lamp')
const pushes = await page.evaluate(() => JSON.stringify(window.dataLayer || []))
expect(pushes).not.toMatch(/[\w.+]+@[\w]+\.[\w.]+/)
})
waitForFunction keeps running findEvent in the page until it returns something, then hands the result back to the test, and jsonValue turns it into a plain object.21 The second test is the personal data rule from the plan, written as a check that fails loudly.
Example: the test that caught a missing currency
Callum refactors the product page template in March and moves the price lookup into a partial. The page looks identical. The Playwright run before the release fails with one line: expected undefined to be "EUR". The new partial built the item but forgot the event level currency.
Without the test, the change would have gone live. GA4 would have received view_item events with a value and no currency, and Google says revenue metrics are then not computed accurately.1 Niamh's product report would have shown views with no value for weeks before anyone noticed. With the test, the fix takes one line and five minutes. I work this way on every shop I build: test first, and no release goes out unless it has passed the test gate and been written into the release register.
Keeping the plan alive
A tracking plan is never finished. New products need new parameters, a new payment method needs a new payment_type value, a new banner slot needs a creative_slot. The plan survives those changes if it has three habits.
One owner per row. The owner column is not decoration. When a number in a report looks wrong, the owner is the person who finds out why.
Versions and a change log. Every change gets a new version number, a date and one line on why. When a report shows a jump on a certain day, the change log is the first place to look, and very often the jump is a tracking change, not a change in customer behaviour. Is your dashboard lying to you? lists the other usual suspects.
Change the plan and the code together. The plan lives next to the code, a change to an event is reviewed with the change to the plan, and the automated test is updated in the same step. If the plan says one thing and the code another, the test fails.
Example: adding gift wrapping in version 1.1
In April, Niamh adds gift wrapping at €3.50. She wants to know how many orders take it and whether it changes the order value. Callum writes the change:
purchasegains a custom parametergift_wrapwith values"yes"or"no".- It is registered as an event scoped custom dimension: 1 of the 50 allowed, now 1 in use.5
- The gift wrap fee goes into neither
valuenorshipping: the plan saysvalueis products only, so the fee is recorded in the shop database and as its own parametergift_wrap_fee: 2.85, the net of €3.50 at 23% VAT (). - The Playwright test gains one assertion that a test order with gift wrap pushes
gift_wrap: "yes". - The change log reads: "1.1, 6 April 2027: gift wrap on purchase, owner Niamh, question: does gift wrap raise order value."
Five lines of plan, one parameter, one test. A month later Niamh's question has an answer, and anyone who joins the shop in a year can read why the parameter exists.
Conclusion
A tracking plan is a short document with a long life. Start from the questions the business asks and the decisions they change, and track only what serves them. Use Google's thirteen recommended eCommerce events with their own names and parameters, fill the items array every time, and use the SKU as the one identifier that joins every system. Add list and promotion events, because they answer the merchandising questions most shops cannot. Write naming rules once, budget the scarce custom dimensions, and keep every row with a trigger, parameters, an owner, a consent category, a destination and a question. Keep personal data out by rule and by test. Let consent decide what fires, and let the shop's own database hold what consent hides. Then test the plan automatically, so it stays true after every release. The next chapter takes the one event that carries the money, the purchase, and gets it exactly right.