Blog

Forward BigQuery export to a webhook with sGTM

A reverse pipeline that lets you activate warehouse data as ad audience events with sGTM as the bridge.

Most analytics pipelines flow events into a warehouse. Sometimes you want the reverse: warehouse data flowing back out as conversion events, attributed to specific platforms. sGTM is well-suited as the bridge because it speaks the destination protocols natively.

The use case

A common scenario: a customer signed up online (tracked client-side, fine), but converted to a paid plan two weeks later in a sales call (tracked in your CRM, not on the website). You want that paid conversion to flow back to Meta and Google as a conversion event so the platforms can optimise for paid signups, not just signups.

The pipeline

  1. Schedule a query in BigQuery (or your warehouse) that selects new paid conversions since the last run.
  2. Output each row as a JSON event with the user's email (hashed) and the original click IDs (gclid, fbclid).
  3. POST each event to your sGTM webhook endpoint with the appropriate auth token.
  4. sGTM receives the event and fires tags as if it had come from a browser.

The Cloud Function trigger

The cleanest way to run the BigQuery query and POST results is a scheduled Cloud Function (or equivalent on AWS Lambda). The function runs on a cron, queries BigQuery for new rows, and POSTs each row to sGTM.

// Pseudocode
const rows = await bigquery.query('SELECT email, gclid, fbclid, value FROM new_paid_conversions');
for (const row of rows) {
  await fetch('https://data.example.com/webhook/conversion', {
    method: 'POST',
    body: JSON.stringify({
      event: 'paid_conversion',
      user_data: { email: hash(row.email) },
      gclid: row.gclid,
      fbclid: row.fbclid,
      value: row.value
    }),
    headers: { 'Authorization': 'Bearer ' + WEBHOOK_TOKEN }
  });
}

In sGTM

Add a Webhook client listening on /webhook/conversion with bearer token verification. The client emits a paid_conversion event. Configure your Meta CAPI tag and Google Ads tag with triggers on this event.

For Meta, set the action_source to "system_generated" rather than "website" since the event did not originate in a browser. This signals to Meta that it is an offline conversion.

Watch the timing

Both Meta and Google have attribution windows (28 days for Meta, 30 days for Google by default). Conversions sent more than the window after the original click are received but not attributed. If your sales cycle is longer than 30 days, the click ID is no longer useful and you must rely on email matching alone.