Sub topic 9
Instrumenting events to follow customers through the journey
This chapter assumes you can read the funnel counts from the previous chapter and know the four stages: awareness, consideration, decision and purchase. It also assumes you have a basic idea of what a web page script does. You will learn to turn journey stages into analytics events, send one, and avoid the errors that make funnel data unreliable.
From stages to events
An event is a record that something happened, such as a page view or a click, with a name, a time and some details. A funnel metric is only as good as the events behind it. If no event marks the move into the decision stage, you cannot count how many customers reached it.
Start from the map, not from the tool. For each stage, pick one event that proves a customer entered it. Then add details (called parameters) that you will need for analysis later.
| Stage | Example event | Useful parameters |
|---|---|---|
| Awareness | `session_start` | source, medium, campaign |
| Consideration | `view_item` | item_id, item_name, price |
| Decision | `add_to_cart` | item_id, value, currency, quantity |
| Purchase | `purchase` | transaction_id, value, currency |
Keep names consistent. Use lowercase with underscores, and reuse the names your analytics tool already defines (Google Analytics 4 defines the ones above). A custom name such as AddedBottle forces extra work in every report.
The data layer
A data layer is a JavaScript array on the page that holds events in a structured form. Your page code pushes events into it, and a tag manager reads them and forwards them to analytics tools. This separates what happened from where it is reported, so you can change tools without rewriting page code.
The following code marks a customer's move into the decision stage.
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
event: 'add_to_cart',
ecommerce: {
currency: 'USD',
value: 29.99,
items: [
{
item_id: 'SKU_123',
item_name: 'Trail Water Bottle',
price: 29.99,
quantity: 1
}
]
}
});The first line creates the array if it does not exist yet, so the code works whether or not the tag manager has loaded. The event key names the event. The ecommerce object carries the details.
Linking events into one journey
Counting events is not enough. To follow one customer, events must share an identifier. Analytics tools usually assign an anonymous ID stored in a cookie, and some let you add a user ID after login. A customer who browses on a phone and buys on a laptop appears as two people unless a login joins them. Expect some undercounting of multi-device journeys and note it on the map.
Also decide when an event fires. Fire add_to_cart after the cart actually updates, not when the button is clicked, or failed requests will inflate the decision stage.
Common errors
- Duplicate events. A
purchaseevent that fires again when the customer reloads the confirmation page inflates revenue. Send a uniquetransaction_idand have the tool ignore repeats. - Missing parameters. An event without
valueoritem_idcannot answer questions about which products drop off. - Inconsistent names.
add_to_carton the web andAddToCartin the app split one stage into two rows. - Untested changes. A redesign can silently remove a tag. Check events after every release.
- Personal data in parameters. Do not send emails or names as event parameters. Follow your consent rules and your region's privacy law.
Checking the result
Once events flow, the funnel from the last chapter can be computed from real data instead of examples. Compare the event counts against another source, such as your order database. If the purchase event shows 480 orders and the database shows 510, something is not firing, and the funnel's final rate is wrong.
Exercise
A customer reloads the order confirmation page twice, and your analytics shows three purchases for one order. Which parameter and which rule would prevent the overcount?
Show answer
Send a unique transaction_id with the purchase event and configure the analytics tool to ignore repeats of the same ID. Alternatively, fire the event only once per order, for example by recording in the browser that it was already sent.
Exercise
Choose one event for each of the four stages for a store that sells water bottles, and name one parameter for each that you would want in later analysis.
Show answer
One valid answer: awareness session_start with source; consideration view_item with itemid; decision `addtocart with value; purchase purchase` with transactionid. Any event that proves entry into the stage and a parameter that supports a later question is acceptable.