How to Track Marketing Attribution with n8n and Google Analytics
Most marketing teams know which campaigns they're running. Very few know which ones actually drive revenue. The gap between "we sent traffic" and "that traffic converted" is where attribution lives —
Most marketing teams know which campaigns they're running. Very few know which ones actually drive revenue. The gap between "we sent traffic" and "that traffic converted" is where attribution lives — and where most tools either fail you or charge you a fortune. n8n, combined with Google Analytics 4, gives you a way to close that gap without paying for another SaaS platform or writing a custom backend from scratch.
What Marketing Attribution Actually Requires
Attribution isn't just about tracking clicks. To connect a sale to a source, you need three things to line up: the UTM parameters from the ad or post, a session record in GA4 tied to those parameters, and a conversion event that fires when the purchase actually completes. If any of these break — UTMs stripped by redirects, sessions not stitching correctly, conversion events misfiring — your attribution data becomes noise.
The common failure points are:
- Landing pages that strip UTM parameters on redirect
- Third-party checkout flows (Gumroad, Shopify, Stripe) that break the GA4 session
- Missing or inconsistent UTM conventions across campaigns
- No server-side fallback when client-side GA4 is blocked by ad blockers
n8n lets you patch each of these without rebuilding your stack. You automate the data collection, normalization, and alerting — and GA4 becomes a reliable source of truth instead of a best-guess dashboard.
Building the Attribution Pipeline in n8n
The core workflow has four stages: capture, enrich, store, and report. Here's how each one works in practice.
Capture: Use a Webhook node as the entry point. Any time a conversion fires — a purchase webhook from Gumroad, a form submission, a checkout completion — it hits this endpoint. The payload should include at minimum: the transaction ID, timestamp, product ID, and whatever referral data the platform exposes (Gumroad includes referral URL in its webhook payload).
Enrich: Parse the referral URL to extract UTM parameters. If the purchase came through ?utm_source=pinterest&utm_medium=organic&utm_campaign=n8n-crm, you now know the exact origin. Use a Code node or a Set node to extract and standardize these fields. Cross-reference with GA4 using the Measurement Protocol to fire a server-side conversion event — this bypasses ad blockers entirely and ensures the event registers even when the client-side tag doesn't fire.
Store: Write the enriched record to a Google Sheet or a database (Supabase works well here). Each row represents one conversion with its full attribution chain: source, medium, campaign, content, and revenue amount. This becomes your attribution table — queryable, portable, yours.
Report: Schedule a second workflow to aggregate this table weekly and send a summary via Slack or email. Total revenue by source, top campaigns by conversion rate, which UTM content values are driving purchases versus just clicks.
Connecting n8n to GA4 via Measurement Protocol
GA4's Measurement Protocol lets you send events directly from a server — no browser required. This is what makes server-side attribution reliable. To set it up:
- Get your GA4 Measurement ID (format: G-XXXXXXXXXX) and API secret from the GA4 admin panel under Data Streams
- In n8n, use an HTTP Request node to POST to
https://www.google-analytics.com/mp/collect - Include
client_id(a stable identifier for the user),eventsarray with your event name and parameters, andsession_idif you can recover it from the original click - Map UTM parameters to GA4's traffic source fields:
session_traffic_source_last_clickor custom event parameters
The tricky part is client_id. If your checkout flow is on a third-party domain like Gumroad, you won't have access to the GA4 cookie directly. The workaround: append a unique token to your product URLs and pass it through the purchase webhook. When the conversion fires, match the token back to the originating session you stored at click time.
Automating UTM Hygiene Across Campaigns
Attribution breaks quietly. A team member posts a link without UTMs. A tool auto-shares a URL and strips the parameters. An email client rewrites the query string. None of this shows up as an error — it just inflates your "direct" traffic and dilutes your paid channel data.
Build a monitoring workflow in n8n that runs daily:
- Pull recent sessions from GA4 using the Data API
- Flag any sessions where source is "(direct)" but the landing page is a known campaign destination
- Check your active social posts and ads for missing or malformed UTMs using a scraper or API integration
- Alert via Slack when UTM coverage drops below a threshold (aim for 95%+ on paid channels)
This kind of automated hygiene check is tedious to do manually and almost never happens consistently on teams. Automating it in n8n means it runs without anyone remembering to do it.
If you want to move faster, ready-made n8n templates for GA4 integration and webhook-based attribution are already built and tested — you configure the credentials and the workflow is live in minutes rather than hours.
Marketing attribution with n8n isn't about replacing GA4 — it's about making GA4 data trustworthy. The combination of server-side event firing, automated UTM audits, and a clean conversion table gives you attribution you can actually act on. When you know which campaign drove a sale, you know where to double down. That's the only thing attribution is for.

Ja construimos isso pra voce
Nao comece do zero. O Sales Efficiency Score - Weekly e um workflow n8n pronto para instalar que faz exatamente isso — em minutos, nao horas.
Instalar por $59 →