Skip to content
FunnelGuard

Fix guide by FunnelsGuard

GA4 _ga cookie on wrong domain: how to find and fix it

TRK-029Medium impactPartlyBy FunnelGuardPublished Updated
On this page

What this issue is

GA4 recognises a returning browser through a first-party cookie called _ga. It stores a client ID. A cookie is only sent to the hostname it was set for, unless its Domain attribute is a parent domain such as .example.com.

By default GA4 uses cookie_domain: auto, which picks the highest-level domain it can write to. That usually works. It breaks when the tag sets a fixed, too-narrow domain (for example www.example.com), when a theme, plugin or consent tool rewrites the cookie, or when the site sits on a public suffix such as example.co.uk and is configured by hand wrongly. The result: the _ga cookie on www and the one on shop hold different client IDs.

Why it costs you leads or sales

The visitor who clicked your Google ad, read your landing page and then moved to a booking or checkout subdomain is counted as two users. The second one often arrives with a self-referral from your own site, so the real source is lost. Conversions get credited to "direct" or to your own domain instead of the campaign that paid for the visit.

How one visitor becomes two users
  1. Ad clickVisitor lands on www.example.com with campaign data
  2. _ga set on www onlyCookie domain is www.example.com, not .example.com
  3. Move to shop subdomainNo _ga cookie is sent; a new client ID is created
  4. PurchaseCredited to direct or self-referral, not the ad

The cookie set on www is not sent to the shop subdomain, so GA4 starts again.

Purchases credited by sourceExample numbers
Purchases credited by source (example)Paid search (correct setup): 100 purchases; Paid search (split cookie): 55 purchases; Direct / self-referral (split cookie): 45 purchases038771005545Paid search (correct …Paid search (split co…Direct / self-referra…purchases

Example: 100 purchases that really came from paid search. With a split cookie, many are reported as direct or self-referral.

How to check if your site has it

Check the cookie domain in your browser
  1. Open the main site

    Visit your landing page in a fresh private window and accept analytics cookies if a banner appears.

  2. Open DevToolsChrome

    In Chrome press F12, go to Application, then Storage > Cookies, and select your site.

  3. Find the _ga cookie

    Look at the Domain column. A healthy value is .example.com (leading dot). A value like www.example.com is the problem. Also note the _ga_XXXX cookie for your measurement ID.

  4. Compare on the subdomain

    Click through to your checkout, booking or app subdomain in the same window. The _ga value should be identical. If it changes or a second _ga appears, the users are split.

  5. Look for self-referrals

    In GA4 go to Reports > Acquisition > Traffic acquisition, add Session source / medium, and look for your own domain as a source.

What you may see in the Domain column
Cookie domainMeaningSubdomains share it?
.example.comParent domain, the normal resultYes
www.example.comSingle hostname onlyNo
shop.example.comSet separately on the subdomainNo
Two _ga cookiesParent and host-level cookies clashUnreliable

How to fix it

The fix is the same everywhere: make every GA4 tag on every subdomain use the same measurement ID and write the cookie to the shared parent domain. Where you do not need a custom value, leave cookie_domain on auto.

Set the cookie domain by platform
  1. Open the Google tag

    In Tags, open your GA4 Google tag (or GA4 Configuration tag).

  2. Add the setting

    Under Configuration settings (or Fields to Set), add cookie_domain with value auto. Use your parent domain, such as example.com, only if auto fails.

  3. Use one tag on all subdomains

    Make sure every subdomain loads the same container or a tag with the same settings.

  4. Preview and publish

    Use Preview, check the cookie in DevTools, then Submit.

gtag.js config with a shared cookie domainjavascript
gtag('js', new Date());
gtag('config', 'G-XXXXXXXXXX', {
  cookie_domain: 'auto'
});

// If auto does not pick the parent domain, set it explicitly:
// gtag('config', 'G-XXXXXXXXXX', { cookie_domain: 'example.com' });

How to confirm it's fixed

Confirmation checks
  • In a fresh private window, _ga shows the Domain .example.com on the main site.
  • Only one _ga cookie exists, and its value is the same on every subdomain.
  • In GA4 Realtime, one visit that crosses subdomains shows as one user.
  • Your own domain no longer appears as a traffic source for conversions after a few days.
  • The same measurement ID is used on every subdomain.

How to prevent it happening again

Habits that keep it fixed
  • Keep one documented GA4 setup and reuse it for every new subdomain.
  • Leave cookie_domain on auto unless you have a proven reason to change it.
  • Re-check the _ga cookie domain after theme, plugin, consent tool or tag manager changes.
  • Add a new subdomain to your test routine the day it goes live.
  • Watch for your own domain appearing in the referral report.

How FunnelGuard handles this

FunnelGuard detects this issue only partly. Its cookie matcher checks that the cookies it expects (such as _ga) are present when the robot visitor runs your journey. It does not check the cookie's domain, so it cannot tell you that _ga was set on www.example.com instead of .example.com.

To cover the rest by hand, use the DevTools check above on your landing page and on each subdomain a journey passes through, and repeat it after any tracking or theme change. FunnelGuard still helps around the edges: it runs your real journeys on a schedule, checks the GA4 hits sent at each step, and alerts you with a screenshot if a tag stops firing or a cookie goes missing. The Free plan covers 1 site and 2 journeys with daily checks and no card, and a free read-only website audit is available.

Questions people ask

Why is my GA4 _ga cookie set on www instead of the root domain?

Usually because the tag, a plugin or a consent tool sets a fixed cookie domain such as www.example.com. GA4 normally uses cookie_domain: auto, which picks the parent domain. Set it back to auto or to your parent domain and test in a fresh private window.

Why does GA4 count the same visitor as two users on my subdomain?

The _ga cookie holds the client ID. If it is stored only for one hostname, the subdomain cannot read it and GA4 creates a new ID. Writing the cookie to the shared parent domain fixes this.

How do I set cookie_domain in GA4?

Add cookie_domain to the config settings of your Google tag, either as a field in Google Tag Manager or inside gtag('config', 'G-XXXXXXXXXX', { cookie_domain: 'auto' }). Use the same setting on every subdomain.

Do I need cross-domain tracking for subdomains?

No. Subdomains of the same parent domain share cookies when the cookie domain is correct. Cross-domain measurement is only needed when you move visitors between different domains.

Why does my own website show as a referral source in GA4?

Often because a visitor moved to a subdomain that did not share the _ga cookie, so GA4 treated your main site as the referrer of a new session. Fixing the cookie domain, and checking your referral exclusion list, reduces this.

How can I check the _ga cookie domain?

Open Chrome DevTools, go to Application > Cookies, select your site and read the Domain column for _ga. A leading dot and your parent domain, like .example.com, is correct.

Does FunnelGuard detect a wrong _ga cookie domain?

Only partly. FunnelGuard's cookie matcher checks that expected cookies are present, but it does not check the cookie's domain. You need to confirm the domain by hand in your browser.

Does FunnelGuard catch this?

Partly

FunnelGuard checks part of this.

How: cookie matcher; domain not checked.

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.