Send GA4 purchase events to SourceTrack via Google Tag Manager
If your site already sends GA4 purchase, checkout and lead events to Google Tag Manager, one Custom HTML tag can pass them on to SourceTrack. SourceTrack does not read those events by itself, so this tag is the bridge.
Before you start
- SourceTrack is already added through Google Tag Manager on All Pages. See the Google Tag Manager guide: https://www.sourcetrack.ai/docs/gtm.
- Your site pushes GA4 ecommerce events to the dataLayer in the standard shape, for example:
dataLayer.push({ ecommerce: null }); // clear the previous ecommerce object
dataLayer.push({
event: 'purchase',
ecommerce: {
transaction_id: 'T-12345',
value: 59.98,
currency: 'USD',
items: [{ item_id: 'SKU-1', item_name: 'Example', price: 29.99, quantity: 2 }]
}
});
This tag needs no API token. Never paste a token into Google Tag Manager. If an event has no transaction_id, value and currency, send no revenue for it.
What each event becomes in SourceTrack
| GA4 event | What SourceTrack records |
|---|---|
purchase |
A purchase conversion with the order id, plus its value and currency when your event has them. |
generate_lead |
Nothing, unless you set SEND_LEADS = true in the tag. Then a lead, with no value. |
begin_checkout |
A checkout-started event. It is not a lead, a customer or revenue. |
Set it up in Google Tag Manager
- Variables. Create a Data Layer Variable named
DLV - ecommercewith Data Layer Variable Nameecommerce(version 2). Turn on the built-in variable Event (Variables, Configure, Utilities). - Triggers. Create one Custom Event trigger for each event name:
purchase,generate_lead,begin_checkout. Or one trigger with the regex match^(purchase|generate_lead|begin_checkout)$. - Tag. Create a Custom HTML tag, SourceTrack - GA4 events, with this body, and attach the trigger or triggers from step 2:
<script>
(function () {
var ec = {{DLV - ecommerce}} || {};
var eventName = {{Event}};
// Leads: set to true only if you do NOT want SourceTrack to turn form submits into conversions on its own.
// A lead sent from here turns off automatic form conversions for this site.
var SEND_LEADS = false;
function send(st) {
if (eventName === 'purchase') {
// A purchase needs the id GA4 reports as transaction_id.
if (!ec.transaction_id) return;
var call = { type: 'purchase', order_id: String(ec.transaction_id) };
var value = Number(ec.value);
if (isFinite(value) && value > 0 && ec.currency) {
call.value = value;
call.currency = String(ec.currency);
}
st.conversion(call);
} else if (eventName === 'generate_lead') {
if (SEND_LEADS) st.conversion({ type: 'lead' });
} else if (eventName === 'begin_checkout') {
st.track('begin_checkout', {
cart_value: Number(ec.value) || null,
currency: ec.currency ? String(ec.currency) : null,
item_count: Array.isArray(ec.items) ? ec.items.length : null
});
}
}
// The tracking script loads asynchronously: wait up to 5 seconds for it.
var tries = 0;
(function wait() {
if (window.sourcetrack && typeof window.sourcetrack.conversion === 'function') return send(window.sourcetrack);
if (++tries < 50) setTimeout(wait, 100);
})();
})();
</script>
- Click Preview in Google Tag Manager and trigger a test purchase. Then open Setup & Health in SourceTrack (https://app.sourcetrack.ai/setup), go to Check tracking coverage and click Show Feed under Live Events Feed.
If your site uses other event names, change only the three eventName === lines in the tag.
Leads: one source per form
SourceTrack already turns your site's form submits into leads on its own. Sending a lead from the browser turns off automatic form conversions for that site, so the same submit is not counted twice. Use one or the other for each form:
- Keep automatic form conversions (the default): leave
SEND_LEADS = false. Thegenerate_leadevent then sends nothing. - Send your own leads instead: set
SEND_LEADS = true. From then on, form submits are no longer turned into conversions automatically. Settings shows this as Automatic form and booking conversions.
What counts as revenue
The tag sends the value your page reports. SourceTrack decides how far to trust it:
- The browser is not proof of payment. A value sent from your page is not confirmed revenue by itself.
- Stripe or Shopify connected. Your page should make
transaction_idequal to the order or payment id the processor records, so the purchase matches the processor's record. The tag sends nothing for a purchase withouttransaction_id. - Neither connected. SourceTrack records the value as your page sent it, and it is unverified. Connect Stripe (https://www.sourcetrack.ai/docs/stripe) or Shopify (https://www.sourcetrack.ai/docs/shopify) for confirmed revenue.
- Leads and checkout starts carry no revenue.
If it did not work
- A purchase is missing its value: the event needs a
transaction_id, avalueabove zero and acurrency. Withouttransaction_idnothing is sent. - The tag fires too often: keep the triggers to the three event names above.
- Personal data: the tag sends no email, name or other personal data. Do not add any.
- Checkout starts are not conversions:
begin_checkoutis a step on the way, so it is not counted as one.
The browser conversion call is described in the Browser Conversions guide: https://app.sourcetrack.ai/developers/conversions