Real-World Example: VIP Enrollment
Imagine you’ve added a VIP program enrollment option to your checkout. When customers opt-in, you want to track this decision in your analytics to measure program adoption and correlate it with purchase behavior. Here’s how a custom component can send avip_enrollment event when a customer joins:
VipEnrollmentButton.tsx
vip_enrollment event is pushed to the dataLayer, where GTM captures it and forwards it to GA4 or any other analytics platform you’ve configured.
How It Works
Custom events are sent to Google Tag Manager via thedataLayer object—a JavaScript array that GTM uses as a communication layer between your website and tags.
Learn more about the dataLayer in the GTM dataLayer documentation.
Prerequisites
- Ollie Shop SDK installed
- Google Tag Manager configured in your store
- A custom component to add the event tracking
Implementation Details
Add this type declaration at the top of your custom component to get type safety and IDE autocompletion for thedataLayer:
Full Component Example
Full Component Example
VipEnrollmentButton.tsx
Event Naming Best Practices
Follow these conventions to keep your analytics data clean and actionable:| Convention | Example | Description |
|---|---|---|
| Use snake_case | vip_enrollment | Consistent with GA4 standard events |
| Be descriptive | shipping_method_selected | Makes reports easier to understand |
| Include context | checkout_promo_applied | Helps segment by checkout stage |
| Avoid generic names | button_click | Too vague for meaningful analysis |
Configuring GTM to Capture Custom Events
After pushing events to thedataLayer, configure GTM to capture and forward them:
- Create a Custom Event Trigger in GTM matching your event name (e.g.,
vip_enrollment) - Create a GA4 Event Tag that fires on this trigger
- Map any custom parameters to GA4 event parameters
- Test using GTM’s Preview mode before publishing