Faizo

Writing · Analytics · Google Analytics · Privacy

An event parameter named "source" rewrote my GA4 traffic attribution

17% of my GA4 sessions were credited to traffic sources called "gallery" and "seo". The cause was an event parameter name. Which names to avoid.

I use Google Analytics 4 on DWEEB to answer a few product questions: where visitors come from, which templates they pick, whether the code export gets used. In September 2026 I was reading the traffic acquisition report and found two traffic sources I had never heard of: gallery and seo. Together they made up the entire "Unassigned" channel, 565 of 3,279 sessions in the period, about 17%.

Nobody was sending traffic from a site called "gallery". Those were values of a custom event parameter.

The cause

When someone applied a template, the app sent an event like this:

gtag("event", "template_applied", { template: "server-rules", source: "gallery" });

source meant "which part of the UI the template was applied from": the gallery, or a link from one of the site's guide pages (seo). To GA4, though, source is not just any name. Together with medium, campaign, term and content, it is one of the names GA reads as manual campaign information. In my property, an event carrying source: "gallery" re-attributed the session to a traffic source named "gallery", overwriting the search engine or AI assistant that had actually sent the visitor. Since those sessions had no matching medium, they landed in "Unassigned".

The fix was a rename, plus a guard so it can't happen again:

// Names GA4 can treat as campaign information. Never use them as event parameters.
const RESERVED = new Set(["source", "medium", "campaign", "term", "content"]);

export function track(name, params = {}) {
  for (const key of Object.keys(params)) {
    if (RESERVED.has(key)) {
      throw new Error(`analytics: "${key}" is reserved by GA4 attribution; rename it`);
    }
  }
  window.gtag?.("event", name, params);
}

track("template_applied", { template: "server-rules", applied_from: "gallery" });

A unit test also checks every allowed parameter list against the five names, so the mistake fails CI rather than quietly corrupting a month of reports. The data from before the fix still undercounts Organic Search and AI-assistant referrals by that 17%, and I note that whenever I compare across that date.

The general lesson: analytics parameter names are a shared namespace. Check a vendor's reserved and automatically collected names before inventing your own. Generic words like source, type or value are exactly the ones vendors reserve.

DWEEB's privacy policy promises analytics cookies and no advertising or cross-site tracking. While tightening the Content Security Policy on the site's static pages, I saw a console error on every page that loaded analytics: a request to stats.g.doubleclick.net blocked by the CSP. That's gtag's Google-signals ping, an advertising-related request.

I tried the documented switches first. Google signals was already turned off for the property. Setting allow_google_signals: false and allow_ad_personalization_signals: false, through gtag("set") or the config call, did not stop the request. What did stop it was setting consent defaults before the js and config calls:

window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }

gtag("consent", "default", {
  ad_storage: "denied",
  ad_user_data: "denied",
  ad_personalization: "denied",
  analytics_storage: "granted",
});
gtag("js", new Date());
gtag("config", "G-XXXXXXXXXX", {
  allow_google_signals: false,
  allow_ad_personalization_signals: false,
});

Page views were still collected afterwards. The collection requests carry consent state that reflects denied ad storage, and the DoubleClick request was gone. I kept the two flags anyway, because they are the documented per-tag opt-outs. The wrong fix would have been to widen the CSP to let the request through. The error was the CSP doing its job.

Lesson three: what never goes into analytics

A message builder handles things people would rather not have in an analytics product: message text, webhook URLs (which contain a secret token), server and channel IDs. The rules I follow:

  • Allow-lists, not deny-lists. Each event has an explicit list of permitted parameters with fixed values. Anything else is dropped before it leaves the page.
  • Turn off Enhanced Measurement. GA4's automatic outbound-click, site-search and history-change events collect URLs and query strings your own filters never see. A page URL with a shared message in its fragment, or a query containing an ID, would go straight into the property.
  • Send a controlled page location. The page location sent is a canonical path, and the referrer is reduced to its origin. Hash fragments and arbitrary query strings are never sent.
  • No free-form text, ever. Not message content, not search terms, not error messages.

This costs a little analytical detail. In exchange, I can describe in the privacy policy exactly what is collected, and it stays true when someone adds an event in a hurry.

Summary

  • Don't name event parameters source, medium, campaign, term or content in GA4. Enforce it in code.
  • If you deny advertising, set consent defaults first. The individual flags didn't stop the DoubleClick request for me.
  • Allow-list parameters and disable automatic collection you can't filter.