Dynamic Email List Segmentation with OpenCart Events via GTM & GA4

Standard

Dynamic email segmentation allows marketers to tailor campaigns based on real-time user actions. By capturing OpenCart behavioral events via Google Tag Manager (GTM) and pushing them to GA4, you can build highly-relevant email segments using CRM tools like Klaviyo, Mailchimp, or HubSpot through GA4 audiences or server-side syncs.


๐Ÿงฐ Prerequisites

Requirement Details
OpenCart 3.x / 4.x Your eCommerce platform
Google Tag Manager Web container implemented on OpenCart
Google Analytics 4 Connected to GTM
Email Platform (CRM) e.g., Klaviyo, Mailchimp, HubSpot, etc.
Consent Framework Optional, for GDPR/CCPA compliance


๐ŸŽฏ Objective

Segment users for email campaigns like:

  • Viewed product but did not buy
  • Abandoned cart after 1+ item
  • Completed checkout for specific category
  • Returning users with no purchase in last 14 days


๐Ÿ“ฆ Step 1: Inject DataLayer Events in OpenCart

A. Product View

In product.twig:

<script>
window.dataLayer = window.dataLayer || [];
dataLayer.push({
event: 'view_item',
ecommerce: {
items: [{
item_id: '{{ product_id }}',
item_name: '{{ heading_title }}',
category: '{{ category }}',
price: {{ price }}
}]
}
});
</script>


B. Add to Cart

In cart button JS or via GTM click listener:

dataLayer.push({
event: 'add_to_cart',
ecommerce: {
items: [{
item_id: '123',
item_name: 'Demo Product',
price: 29.99
}]
}
});


C. Checkout Start

In checkout.twig:

<script>
dataLayer.push({
event: 'begin_checkout'
});
</script>


D. Purchase

In success.twig:

<script>
dataLayer.push({
event: 'purchase',
user_email: '{{ email | lower }}',
transaction_id: '{{ order_id }}',
ecommerce: {
transaction_id: '{{ order_id }}',
value: {{ order_total }},
currency: '{{ currency }}',
items: [{ item_id: '{{ product_id }}' }]
}
});
</script>


๐ŸŒ Step 2: Capture & Send Events to GA4

In GTM, create a tag for each of the following:

  • Tag Type: GA4 Event
  • Event Name: match view_item, add_to_cart, etc.
  • Event Parameters:
    • items: from ecommerce.items
    • user_email: from dataLayer

๐Ÿ” Add all event tags for:

  • view_item
  • add_to_cart
  • begin_checkout
  • purchase

Make sure your GA4 Config Tag is referenced.


๐Ÿงฒ Step 3: Build Email Segments from GA4 Audiences

In GA4 > Admin > Audiences:

A. Cart Abandoners

  • Include users who fired add_to_cart
  • Exclude users who completed purchase
  • Time limit: 3 days

B. Product Viewers (No Cart)

  • view_item event triggered
  • No add_to_cart in 7 days

C. Loyal Buyers (Email campaigns for upsell)

  • 2+ purchases in last 30 days
  • Include item category or price thresholds

These GA4 audiences can be pushed to:

  • Google Ads (for Gmail Ads)
  • Exported to BigQuery or CRM


๐Ÿ”€ Step 4: Sync to Email Platforms

Option 1: CRM Integration (Klaviyo, HubSpot, Mailchimp)

Use GA4 โ†’ BigQuery โ†’ API to:

  • Export user email + behavior
  • Create segments in your email tool dynamically

Example logic for API sync:

{
"email": "user@example.com",
"last_event": "add_to_cart",
"category": "Books",
"cart_value": 45.99
}

Alternatively, use Zapier or GCP Functions to automate nightly sync from GA4 audience exports.


๐Ÿ” Step 5: Respect User Consent

To delay event tags and email PII sync until consent:

if (window.consent_granted === true) {
dataLayer.push({
event: 'purchase',
user_email: '{{ email }}'
});
}

Or use GTMโ€™s Consent Initialization trigger + Consent Mode v2.


๐Ÿงช Step 6: Debugging

Tool Use
GTM Preview Mode Confirm tag firing and variable passing
GA4 DebugView Validate event stream + parameters
Email CRM Logs Check audience match + campaign trigger


๐Ÿ“ˆ Example Use Cases

Segment Name Trigger Logic
Abandoned Cart 24h add_to_cart but no purchase in 1 day
Repeat Visitors session_start 3+ times, no conversion
High-Value Buyers purchase with value > 100
Product Browsers view_item 2+ times on category = Electronics


Leave a Reply

Your email address will not be published. Required fields are marked *