Skip to content
FunnelGuard

Fix guide by FunnelsGuard

Staging or localhost events in production analytics: fix

TRK-349Medium impactPartlyBy FunnelGuardPublished Updated
On this page

What this issue is

Most sites are built and tested on a copy: localhost, staging.example.com, a host's preview URL or a cloned site. If that copy is a straight clone, it carries the same tracking code, including your production GA4 Measurement ID, Google Ads conversion ID and Meta pixel ID.

Why it costs you leads or sales

Bad data leads to bad decisions. Test conversions make a campaign look better than it is, so you may keep budget on something that is not working. Smart bidding in Google Ads and Meta's optimisation learn from those fake conversions and aim at the wrong signals. Conversion rates, funnel drop-off and landing page reports become unreliable.

How test events skew a small site's numbersExample numbers
How test events skew a small site's numbers (example)Real leads: 40 conversions; Staging test leads: 15 conversions; Reported total: 55 conversions02142401555Real leadsStaging test leadsReported totalconversions

Example: a month with 40 real leads and 15 test leads from staging. Reports show 55, so the cost per lead looks about 27% lower than reality.

How staging data reaches production reports
  1. Developer tests on stagingSubmits forms, runs a test checkout
  2. Staging loads production tagsSame GA4, Ads and Meta IDs as the live site
  3. Production propertyTest sessions and conversions recorded
  4. Ad platform optimisationBidding learns from fake conversions

The break is the staging site using production IDs. Everything after it is polluted.

How to check if your site has it

Find non-production hostnames in your data
  1. Open a GA4 report with hostnameGoogle Analytics 4

    In GA4 go to Reports > Engagement > Pages and screens. Click the plus icon to add a secondary dimension, or build an Explore report, and add the dimension Hostname.

  2. Look for anything that is not your live domain

    Scan for localhost, 127.0.0.1, staging., dev., test., preview or builder URLs such as *.myshopify.com, *.webflow.io, *.wpengine.com or *.netlify.app.

  3. Check conversions by hostnameGoogle Analytics 4

    In Explore, use Hostname as a row and your key events as values. Any conversions on a non-live hostname are polluting your counts.

  4. Check the ad platforms

    In Meta Events Manager, open your pixel and look at the event details and the URLs events came from. In Google Ads, compare conversion counts with GA4 for the same dates.

  5. Look at the staging site itself

    Open staging, view source or use browser dev tools (Network tab), and search for your production Measurement ID (G-XXXXXXX), AW- ID or pixel ID.

How to fix it

There are two layers. First stop new bad data at the source by loading production tags only on the live domain. Then clean up how you read the past data, since platforms do not let you delete events already collected.

Stop staging from sending to production
  1. Add a hostname condition

    Create a Page Hostname built-in variable (Variables > Configure). On your GA4, Ads and Meta tags, add a trigger condition: Page Hostname equals your live domain, such as www.example.com.

  2. Or use GTM environments

    In Admin > Environments, create a Staging environment and publish tested changes to it first. Use the environment's snippet on the staging site so it loads a separate workspace version.

  3. Use a lookup variable for IDs

    Create a Lookup Table variable that maps Page Hostname to a Measurement ID: the live domain returns the production ID, everything else returns a test property ID. Use it in the GA4 configuration tag.

Load GA4 only on the live domainjavascript
(function () {
  var liveHosts = ['www.example.com', 'example.com'];
  if (liveHosts.indexOf(location.hostname) === -1) return; // staging, localhost, previews
  var s = document.createElement('script');
  s.async = true;
  s.src = 'https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX';
  document.head.appendChild(s);
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  window.gtag = gtag;
  gtag('js', new Date());
  gtag('config', 'G-XXXXXXXXXX');
})();
Clean up how you read existing data
  1. Add a hostname filter in reportsGoogle Analytics 4

    In GA4 reports and Explorations, filter Hostname to contain your live domain. Save it in your standard reports and dashboards.

  2. Create a data filter if neededGoogle Analytics 4

    GA4 data filters (Admin > Data collection and modification > Data filters) cover internal and developer traffic. Developer traffic can be marked with a debug mode or a traffic type rule; read the current options before relying on one.

  3. Annotate the polluted period

    Add a note in your reporting with the dates affected, so nobody compares them with clean months without context.

  4. Review ad conversion actions

    If staging conversions fed Google Ads or Meta, note the date range and avoid judging campaign performance from it.

Tag setup before and after

Before

  • Staging is a clone with production IDs
  • Hostname report shows staging and localhost rows
  • Test form fills count as leads

After

  • Production tags load only on the live hostname
  • Staging uses a separate test property or no tags
  • Reports show one hostname

How to confirm it's fixed

Confirmation checks
  • Open staging with the browser Network tab and confirm no requests go to google-analytics.com/g/collect with the production ID
  • In GTM Preview mode on staging, confirm GA4, Ads and Meta tags show as Not fired
  • Run a test lead on staging and wait a day: no new rows for that hostname in GA4
  • Check GA4 Realtime while testing on staging: you should not appear
  • Confirm the live site still fires every tag normally

How to prevent it happening again

Prevention
  • Keep a separate GA4 test property and test pixel for non-live environments
  • Gate production tags by hostname or environment variable, never by hand
  • After every site clone, push or migration, re-check tracking settings
  • Add a hostname filter to saved reports and dashboards
  • Add a step to your release checklist: confirm no production IDs on staging
  • Block staging from search engines and password-protect it

How FunnelGuard handles this

FunnelGuard detects this issue only partly. It checks the tracking tag IDs on the pages and journeys it runs, so if you point a FunnelGuard journey at your staging site, it can show which tag IDs load there and flag production IDs on staging. It only sees staging if a journey actually runs on it.

Questions people ask

Why is localhost traffic showing up in my Google Analytics?

Your local development copy is loading the same GA4 Measurement ID as production, so every page you open on localhost is sent to your live property. Gate the tag by hostname or use a separate test property for development.

How do I exclude a staging site from Google Analytics 4?

Stop the tag from loading on staging by adding a Page Hostname condition in GTM or a hostname check in your code. For past data, filter reports by Hostname equal to your live domain, since GA4 cannot delete collected events.

How do I find out if staging data is in my GA4 property?

Add the Hostname dimension to a Pages and screens report or an Explore report. Any row that is not your live domain, such as localhost, staging or a preview URL, is non-production traffic.

Can staging events hurt my Google Ads or Meta results?

Yes. If the staging site fires real conversion tags, the ad platforms count those as conversions and bidding can learn from them. This makes campaigns look better than they are and can steer optimisation the wrong way.

Can I delete staging data from my GA4 property?

Not for events already collected, in general. The practical fix is to stop new data at the source, then filter by hostname in reports and note the polluted date range.

Should staging have its own Google Analytics property?

Yes, a separate test property and test pixel is the safest way to check tracking on staging without touching live reports. Alternatively use a GTM environment so staging loads a separate tag version.

Can FunnelGuard detect staging events in my production property?

Only partly. It checks tag IDs on the pages and journeys it runs, so it can catch production IDs on a staging site if a journey runs there. It does not scan your analytics property for old staging hostnames.

Does FunnelGuard catch this?

Partly

FunnelGuard checks part of this.

How: tag_ids on staging only if journey runs there.

Stop finding out from your customers

FunnelGuard runs your real forms and checkouts on a schedule, checks the tracking and the leads behind them, and alerts you once, with a screenshot. Try any paid plan free for 3 days.