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.
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.
- Developer tests on stagingSubmits forms, runs a test checkout
- Staging loads production tagsSame GA4, Ads and Meta IDs as the live site
- Production propertyTest sessions and conversions recorded
- 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
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.
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.
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.
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.
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.
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.
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.
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.
Discourage tracking on staging
In your analytics plugin (Site Kit, MonsterInsights, GA Google Analytics and similar), look for an option to disable tracking on non-live environments, or deactivate the plugin on staging.
Define the environment
Set WP_ENVIRONMENT_TYPE to staging in wp-config.php, and wrap your tracking code in a check for production.
Check clones
After cloning or pushing a database, re-check the tracking settings. Many hosts copy plugin settings along with the site.
Use a separate development or preview theme with care
Theme previews on your store domain share the store's pixels and customer events settings. Avoid running real-looking test orders there, or use Settings > Customer events to review which pixels are connected.
Use a dev store
For bigger changes, build on a separate development store and connect test IDs only to it.
Keep tracking off the webflow.io domain
Webflow's staging subdomain (*.webflow.io) serves the same custom code as your published site. Wrap custom tracking code in a hostname check, or manage tags through GTM with a hostname condition.
Gate the tag by hostname
Load the analytics snippet only when the hostname matches production. See the code below.
Use environment variables
Inject the Measurement ID from a build or server environment variable, and leave it empty on dev and staging.
(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');
})();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.
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.
Annotate the polluted period
Add a note in your reporting with the dates affected, so nobody compares them with clean months without context.
Review ad conversion actions
If staging conversions fed Google Ads or Meta, note the date range and avoid judging campaign performance from it.
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
- 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
- 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.
Related issues
- TRK-344Test orders/leads counted as real conversionsFix guide
- TRK-347Own staff visits counted (no IP/internal filter)Fix guide
- TRK-348Uptime monitors/crawlers triggering conversionsFix guide
- TRK-345Bot/spam traffic inflating sessionsFix guide
- TRK-337Same conversion counted by multiple tags (GA4 + Ads import + Ads tag)Fix guide
- TRK-350Ghost/referral spam hits via Measurement ProtocolFix guide