Sub topic 9
Instrumenting Events to Follow Customers Through the Journey
This chapter assumes you can read the funnel counts and conversion percentages from the previous chapter. You should also know the four stages (awareness, consideration, decision, purchase) and have a list of touchpoints for each. You don't need to be a developer, but you should be able to read short JavaScript, Python and YAML snippets.
From map to measurement
A journey map says what customers do and feel. Funnel metrics need counts, and counts only exist if something records each step. That recording is called instrumentation. An event is a small record that says "this user did this thing at this time." Events are the raw material for every number in your funnel.
Each stage of the journey should have at least one event that marks entry into it. Without that marker, you can't say how many people reached the stage, so you can't compute its conversion rate.
Choosing events for each stage
Start from the map, not from the tool. For every stage, ask: what is the earliest observable action that shows a customer has moved into this stage? Pick an action that is reliable, hard to trigger by accident, and tied to intent.
| Stage | Example marker event | Why it works |
|---|---|---|
| Awareness | `session_start` with campaign details | Shows a visit and where it came from |
| Consideration | `view_item` | The visitor is looking at a specific product |
| Decision | `add_to_cart` or `begin_checkout` | The visitor is committing to a price |
| Purchase | `purchase` | Payment succeeded |
Avoid markers that are too weak. A homepage view alone doesn't show consideration. Avoid markers that are too late, too. If you only track purchase, you can see the end of the funnel but not where people leave.
Add a few secondary events for friction analysis, such as view_shipping_cost, apply_coupon, form_error and payment_failed. These don't mark stages. They explain why customers stall, which the friction chapter uses.
Anatomy of a good event
Every event should have three parts:
- A name. Short, in
snake_case, and consistent. Use the same name for the same action on every page and platform. - Parameters. The details that describe this occurrence, such as price, product ID or error message.
- Context. Information added automatically, such as timestamp, page URL, device type and a user or session identifier.
Where a standard exists, use it. Google Analytics 4 defines recommended names such as view_item, add_to_cart, begin_checkout and purchase, along with expected parameters. Reports and integrations understand these names without extra setup.
Pushing events to the data layer
A data layer is a JavaScript array on the page where your site publishes events. A tag manager, such as Google Tag Manager, listens to it and forwards the events to your analytics tool. This keeps your site code separate from vendor tags.
This example marks the 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 doesn't exist yet, so the code works whether or not the tag manager has loaded. The ecommerce object holds the details. The value is the price times the quantity, in the stated currency.
The purchase event needs one more field, a unique transaction ID. Without it, a customer who reloads the confirmation page creates a second purchase in your data. This sketch sends the event once per order:
function trackPurchase(order) {
const key = 'tracked_order_' + order.id;
if (window.sessionStorage.getItem(key)) {
return; // already sent for this order in this browser session
}
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
event: 'purchase',
ecommerce: {
transaction_id: order.id,
currency: order.currency,
value: order.total,
items: order.items
}
});
window.sessionStorage.setItem(key, '1');
}The sessionStorage check stops duplicates from reloads in the same session. The transaction_id also lets the analytics tool drop duplicates that get through, so keep both safeguards.
Write a tracking plan first
A tracking plan is a shared document that lists every event, its trigger, its parameters and its owner. Writing it before coding prevents the most common failure: three teams naming the same action three different ways. A plan can be a spreadsheet or a file in your repository. This YAML fragment shows the idea:
events:
- name: view_item
stage: consideration
trigger: Product detail page finishes loading
required_params: [item_id, item_name, price, currency]
owner: web-team
- name: add_to_cart
stage: decision
trigger: Customer clicks "Add to cart" and the cart accepts the item
required_params: [item_id, price, quantity, currency]
owner: web-team
- name: purchase
stage: purchase
trigger: Payment confirmed by the server
required_params: [transaction_id, value, currency, items]
owner: payments-teamNote the trigger wording. "Cart accepts the item" is better than "button clicked," because a click can fail while the item is out of stock. For purchase, the trigger is a server-side confirmation. Firing it from the confirmation page alone misses customers who close the tab before the page loads.
Identity: stitching steps into one journey
A funnel only makes sense if all events from one person are linked. Two identifiers do this:
- Anonymous ID. A random value stored in a cookie or on the device. It links events from the same browser before the person signs in.
- User ID. Your internal customer ID, available after login or checkout.
When a visitor signs in, send an event that carries both IDs. The analytics tool can then connect the earlier anonymous activity to the known customer. If you skip this step, a customer who browses on a phone and buys on a laptop looks like two people, and one of them never converts.
Expect gaps even with good identity handling. Consent banners, blockers and cleared cookies all remove people from your data. Treat event counts as a close estimate, not an exact census.
How an event travels
If a number looks wrong in a report, this chain tells you where to look: the page code, the data layer, the tag manager rule, or the analytics tool's filters.
From events to funnel counts
Once events are flowing, the funnel is a counting problem. Count each unique user who fired the marker event for each stage, then reuse the conversion arithmetic from the funnel chapter. The sketch below does this on a small event log:
stage_events = {
"awareness": "session_start",
"consideration": "view_item",
"decision": "add_to_cart",
"purchase": "purchase",
}
log = [
("u1", "session_start"), ("u1", "view_item"),
("u1", "add_to_cart"), ("u1", "purchase"),
("u2", "session_start"), ("u2", "view_item"),
("u3", "session_start"),
("u4", "session_start"), ("u4", "view_item"),
("u4", "add_to_cart"),
("u4", "add_to_cart"), # duplicate fire, must not double count
]
users_by_event = {}
for user, event in log:
users_by_event.setdefault(event, set()).add(user)
counts = [
(stage, len(users_by_event.get(event, set())))
for stage, event in stage_events.items()
]
for (name, n), (next_name, next_n) in zip(counts, counts[1:]):
print(f"{name} -> {next_name}: {next_n}/{n} = {next_n / n:.0%}")Running it prints:
awareness -> consideration: 3/4 = 75%
consideration -> decision: 2/3 = 67%
decision -> purchase: 1/2 = 50%Using a set of user IDs per event counts people, not firings. That is why user u4's repeated add_to_cart has no effect. Counting raw events instead would inflate the decision stage and understate the drop to purchase.
Common errors
- Double firing. A tag fires twice on a single-page app route change, or on reload. Symptom: stage counts higher than the stage before it. Fix: deduplicate with IDs and test in the browser.
- Missing events on some paths. Mobile web, an express-checkout button or a different payment provider skips your code. Symptom: purchases in the payment system exceed
purchaseevents. Reconcile the two weekly. - Inconsistent names.
addToCart,add_to_cartandAddToCartcount as three events. Fix: enforce the tracking plan. - Client-only purchase tracking. Blockers and closed tabs drop the event. Fix: send
purchasefrom the server as well, with the sametransaction_id. - Tracking everything. Hundreds of events nobody uses make the data hard to trust. Add events only when a map question needs them.
- Changing definitions silently. If you alter a trigger, mark the date. Otherwise a conversion jump may be a measurement change, not a real improvement.
Checklist before you rely on the data
- Every stage on the map has one marker event.
- Every event is in the tracking plan with a trigger and an owner.
- Purchases carry a unique
transaction_idand reconcile with the order system. - Anonymous and user IDs are linked at sign-in.
- No personal data appears in parameters.
- Each event was tested on desktop and mobile.
Exercise
A funnel report shows 5,200 users with add_to_cart but only 4,900 with view_item, and the product team says every cart addition requires a product page visit. Name two likely instrumentation causes and one check for each.
Show answer
Likely cause 1: view_item is missing on some paths, such as quick-add buttons on category pages or a mobile layout that doesn't load the tag. Check by comparing the paths of users who have add_to_cart without view_item and testing those pages in the debug view. Likely cause 2: add_to_cart fires more than once per user and the report counts events instead of unique users, or the event fires on page load or a route change. Check by counting distinct user IDs versus raw events and watching dataLayer while adding one item. Another valid cause is an identity break: the user ID changed between the two events, so one person appears as two. Check by looking for anonymous IDs that appear with only one of the events.
Exercise
Write the tracking-plan entry (name, stage, trigger, required parameters) for an event that marks a customer starting checkout, and explain why the trigger should be worded as it is.
Show answer
Name: begin_checkout. Stage: decision. Trigger: the checkout page loads with at least one item in the cart. Required parameters: currency, value, items. The trigger says "loads with at least one item" because a click on a "Checkout" button can fail or be repeated, while a loaded checkout page with a non-empty cart is a reliable sign the customer is committing. A precise trigger keeps the count consistent across teams and devices.