Tracking the begin_checkout event is crucial for understanding when users initiate the purchase process.
This guide will show you how to implement robust, scalable, and reliable begin_checkout tracking using Google Tag Manager (GTM) and Google Analytics 4 (GA4), while addressing common pitfalls and highlighting practical examples from a real-world use case.
Why Track begin_checkout?
The begin_checkout event signals purchase intent and is the entry point for your ecommerce funnel in GA4. Tracking this accurately allows you to:
- Analyze which pricing options attract the most interest
- Compare performance between button positions (e.g., top vs table vs bottom)
- Measure the impact of discounts and variants
Overview of Our Setup
In our implementation for a WordPress site selling plugin licenses, we needed to:
- Track clicks on multiple “Get Started” buttons per pricing plan
- Support both the Pricing and Upgrade pages (which shared the same buttons via shortcode)
- Differentiate button context (top section vs comparison table)
- Include structured GA4 ecommerce data (item name, ID, price, discount, etc.)
Step 1: Add Unique Identifiers to Buttons Using data-plan
Instead of relying on class names (which can change), use data-plan attributes:
<!-- Example: Pro Plan -->
<button data-plan="pro" class="get-started comparison-top">Get Started</button>
Also add a position class such as:
maincomparison-topcomparison-bottomlifetime
This allows us to pass the clicked button’s position into GA4 as item_list_name.
Step 2: Add the begin_checkout Script
We added the script via the WPCode plugin. You can also include it directly in your theme footer.
<script>
document.addEventListener('DOMContentLoaded', function () {
const path = window.location.pathname;
if (!path.startsWith('/pricing') && !path.startsWith('/upgrade')) return;
window.dataLayer = window.dataLayer || [];
const planData = {
pro: {
coupon: 'PROSAVING150',
value: 149.00,
currency: 'USD',
affiliation: 'ExampleSite.com',
items: [{
item_name: 'Pro Plan',
item_id: 'pro',
coupon: 'PROSAVING150',
discount: 150.00,
item_category: 'Annual',
item_category2: 'Pro',
item_brand: 'ExampleBrand',
price: 299.00,
quantity: 1,
item_variant: '1 site',
index: 2,
link_text: 'Get Started'
}]
},
// Add other plans (basic, elite, lifetime) similarly...
};
const buttons = document.querySelectorAll('[data-plan]');
if (buttons.length === 0) {
console.warn('No [data-plan] buttons found.');
return;
}
buttons.forEach((btn) => {
const planKey = btn.getAttribute('data-plan');
if (!planData[planKey]) return;
btn.addEventListener('click', function () {
const ecommerceData = structuredClone(planData[planKey]);
const positionClass = Array.from(btn.classList).find(cls =>
['main', 'comparison-top', 'comparison-bottom', 'lifetime'].includes(cls)
);
if (positionClass) {
ecommerceData.items[0].item_list_name = positionClass;
}
window.dataLayer.push({ ecommerce: null });
window.dataLayer.push({
event: 'begin_checkout',
ecommerce: ecommerceData
});
console.log(`begin_checkout pushed for: ${planKey} (${positionClass})`);
});
});
});
</script>
Step 3: Set Up the GA4 Tag in GTM
1. Create a Trigger:
- Trigger Type: Custom Event
- Event Name:
begin_checkout - Trigger on: All Custom Events
👉 You can name the trigger something like GA4 - Pricing Begin Checkout
2. Create a Tag:
- Tag Type: GA4 Event Tag
- Configuration Tag: Your GA4 config
- Event Name:
begin_checkout - Event Parameters:
currency:{{DLV - ecommerce.currency}}value:{{DLV - ecommerce.value}}items:{{DLV - ecommerce.items}}
👉 Make sure to enable the Data Layer Variables (DLV) in GTM for each field.
Step 4: Debugging Tips
✅ Check Tag Assistant
- Open GTM preview mode
- Visit your Pricing or Upgrade page
- Click a “Get Started” button
- Look for the
begin_checkoutevent
✅ Check GA4 DebugView
- Open GA4 DebugView (enable debug mode via browser extension or GA debugger)
- Confirm
begin_checkoutappears in the event stream
✅ Check DevTools Console
console.log(window.dataLayer);
Or check the event using:
window.dataLayer.filter(e => e.event === 'begin_checkout');
Lessons Learned and Best Practices
| Issue | Solution |
|---|---|
| Same ID for multiple buttons | Use data-plan instead of IDs or shared classes |
| Classes changed by design team | Don’t rely on class names for logic, use attributes |
| Multiple pages with same buttons | Use pathname.startsWith() to limit tracking |
| Tag didn’t fire | Ensure GTM trigger and tag are properly configured |
ecommerce missing in Variables | That’s normal — check the Data Layer or DebugView |
Conclusion
Setting up begin_checkout tracking in GA4 doesn’t have to be complicated. With a clean data structure, reusable attributes like data-plan, and careful configuration in GTM, you can track user checkout behavior accurately across multiple pages.
This approach is reliable, maintainable, and easy to extend as your pricing evolves.
Need help setting up purchase tracking next? Or want to compare top vs bottom button conversion? Let us know in the comments below!

Leave a Reply