Combining GA4βs behavioral segmentation with CleverTapβs real-time messaging engine unlocks powerful retargeting strategies. You can capture user behavior on your OpenCart store, build GA4 audiences (like cart abandoners, category viewers, etc.), and automatically sync them to CleverTap for
- Push Notifications
- In-app messages
- Emails & SMS
- WhatsApp campaigns
π§° Prerequisites
Tool / Platform | Purpose |
---|---|
OpenCart v3/v4 | Frontend event collection |
Google Tag Manager | Send events to GA4 |
Google Analytics 4 | Audience segmentation |
BigQuery | Query & export GA4 audiences |
CleverTap Account | Retargeting engine with API enabled |
Server/Cloud Func | To push users from BigQuery to CleverTap |
π¦ Step 1: Track Key Events in OpenCart with GTM
A. Add add_to_cart
in product.twig
:
<script>
document.querySelector('.btn-add-to-cart').addEventListener('click', function() {
window.dataLayer = window.dataLayer || [];
dataLayer.push({
event: "add_to_cart",
product_id: "{{ product.product_id }}",
product_name: "{{ product.name }}",
email: "{{ email if customer_logged_in else '' }}"
});
});
</script>
π·οΈ Step 2: Send Events to GA4 via GTM
Create a GA4 Event Tag:
- Event name:
add_to_cart
- Parameters:
product_id
:{{DLV - product_id}}
email
:{{DLV - email}}
(critical for syncing to CleverTap)
Repeat similar steps for view_item
, begin_checkout
, etc.
π₯ Step 3: Create GA4 Audience
Go to: GA4 > Admin > Audiences > Create Audience
Examples:
Audience A: Cart Abandoners
- Include:
add_to_cart
- Exclude:
purchase
- Include only if:
email
is present
Audience B: Category Viewers
- Users who triggered
view_item
withproduct_category = Shoes
Save and name them meaningfully, e.g., Cart_Abandoners_3D
.
πΎ Step 4: Enable BigQuery Export of GA4 Data
- GA4 Admin > BigQuery Linking
- Enable daily export
- Data appears in:
project.dataset.events_YYYYMMDD
π§ Step 5: Query GA4 Audience from BigQuery
Sample SQL to get cart abandoners:
WITH cart_events AS (
SELECT
user_pseudo_id,
MAX(IF(event_name = 'add_to_cart', 1, 0)) AS added,
MAX(IF(event_name = 'purchase', 1, 0)) AS purchased,
MAX(IF(event_name = 'add_to_cart', value.string_value) FILTER (WHERE key = 'email')) AS email
FROM
`project.dataset.events_*`
WHERE
_TABLE_SUFFIX BETWEEN FORMAT_DATE('%Y%m%d', DATE_SUB(CURRENT_DATE(), INTERVAL 2 DAY))
AND FORMAT_DATE('%Y%m%d', CURRENT_DATE())
GROUP BY user_pseudo_id
)
SELECT email
FROM cart_events
WHERE added = 1 AND purchased = 0 AND email IS NOT NULL
π Step 6: Send to CleverTap via API
Use Google Cloud Function / Node.js / Python script:
Example: Node.js Script
const axios = require('axios');
async function pushToCleverTap(email) {
const payload = {
d: [{
objectId: email,
type: "profile",
profileData: {
Email: email,
AbandonedCart: true
}
}]
};
await axios.post("https://<region>.api.clevertap.com/1/upload", payload, {
headers: {
"X-CleverTap-Account-Id": "<YOUR_ACCOUNT_ID>",
"X-CleverTap-Passcode": "<YOUR_PASSCODE>",
"Content-Type": "application/json"
}
});
}
π‘οΈ Run this daily or near-real-time using BigQuery results.
π£ Step 7: Trigger Campaign in CleverTap
Inside CleverTap:
- Go to Campaigns > Create Campaign
- Audience:
AbandonedCart = true
- Trigger: Event or profile update
- Channel: Email / Push / WhatsApp
- Personalize message using dynamic tokens (e.g., product category, value)
π Step 8: Consent Handling
Use GTM consent signals to conditionally allow sending email into GA4.
if (Cookiebot.consents.marketing) {
dataLayer.push({ event: "add_to_cart", email: ... });
}
Also, only push to CleverTap users whoβve opted in.
π§ͺ Step 9: QA the End-to-End Flow
Tool | Use |
---|---|
GA4 DebugView | Check event + email delivery |
BigQuery | Inspect audience queries |
Cloud Function Logs | See email payloads sent to CleverTap |
CleverTap Profiles | Confirm real-time user enrichment |
CRM Logs | Track retargeting delivery & click rates |
π Strategic Benefits
Feature | Value |
---|---|
Real-time sync | No need to wait for exported lists |
Personalized retargeting | Based on real GA4 signals |
Consent-compliant | Works with Cookiebot or GTM signals |
Multi-channel retargeting | Email, SMS, push, WhatsApp |