On this page
What this issue is
A URL has three main parts after the domain: the path, the query string (starts with ?) and the fragment (starts with #). Campaign tags such as utm_source and click IDs such as gclid are expected in the query string, before the #.
Some single-page apps (SPAs) use hash routing, for example React Router's HashRouter, Vue Router in hash mode or older Angular setups. Their page addresses look like /#/pricing. If someone builds a campaign link by adding ?utm_source=... to the end of that address, the UTMs land inside the fragment. Browsers never send the fragment to the server, and GA4's page_location parsing does not treat it as the query string, so the campaign data is not read.
Broken: https://example.com/#/pricing?utm_source=google&utm_medium=cpc&utm_campaign=spring
Working: https://example.com/?utm_source=google&utm_medium=cpc&utm_campaign=spring#/pricingWhy it costs you leads or sales
The visitor still lands and may still convert, so nothing looks broken on the page. The damage is in reporting: paid, email and social visits are filed as direct or as a referral, and campaigns look weaker than they are. You may cut budget on channels that work, or fail to see which ads drive leads.
Ad platforms can also lose the link between click and conversion if a click ID such as gclid sits after the #. Smart bidding then learns from less data.
- Ad clickLink ends in /#/page?utm_source=google
- SPA loadsRouter reads the hash, page renders
- GA4 page_viewNo UTMs found in the query string
- Session sourceRecorded as direct or referral
- Conversion reportLead credited to the wrong channel
The campaign data is lost at the first analytics hit, so every later step is credited to the wrong source.
Example: 100 paid visits to a hash-routed app. Illustrative numbers only.
How to check if your site has it
Check how your app routes
Click through your app. If page addresses contain /#/ (for example /#/pricing), it uses hash routing.
Look at your live campaign links
Open your ad, email and social links. Any URL where
?utm_orgclid=appears after the # is affected.Test with a tagged linkGoogle Analytics 4
Open the link in a fresh private window, then in GA4 go to Admin > DebugView (or Reports > Realtime) and look at the session's source and medium. Direct or (not set) means the UTMs were ignored.
Inspect the hit
In browser dev tools, open the Network tab, filter by
collect, and read thedl(page location) value of the GA4 request. If it holds the whole URL but no UTMs are read as campaign fields, the tags were in the fragment.Compare reports
A high share of direct traffic landing on your SPA entry page, with little paid traffic despite ad spend, is a warning sign.
How to fix it
There are two routes. The quickest is to correct the links. The lasting one is to stop relying on the hash for routing. Do the first now and plan the second.
Rebuild campaign links with UTMs before the #
Use the format
https://example.com/?utm_source=...&utm_medium=...#/page. Update live ads, email templates and social bios.Make sure the server keeps the query string
The root page must not redirect in a way that drops
?parameters. Test with a tagged link and watch the final URL.Rescue old links with a small script
If you cannot change links already in market, run code early in the page that moves parameters from the hash into the real query string before analytics loads (snippet below).
Plan a move to history-mode routing
Switch to
BrowserRouter(React),createWebHistory(Vue) or the Angular default, with a server rule that serves index.html for app paths. Then URLs look like /pricing?utm_source=... and work normally.
(function () {
var hash = window.location.hash; // e.g. #/pricing?utm_source=google
var i = hash.indexOf('?');
if (i === -1) return;
var hashParams = new URLSearchParams(hash.slice(i + 1));
var keep = ['utm_source','utm_medium','utm_campaign','utm_term','utm_content','gclid','fbclid','msclkid'];
var search = new URLSearchParams(window.location.search);
var moved = false;
keep.forEach(function (k) {
if (hashParams.has(k)) {
if (!search.has(k)) search.set(k, hashParams.get(k));
hashParams.delete(k);
moved = true;
}
});
if (!moved) return;
var rest = hashParams.toString();
var newHash = hash.slice(0, i) + (rest ? '?' + rest : '');
var url = window.location.pathname + '?' + search.toString() + newHash;
window.history.replaceState(null, '', url);
})();Add the script to index.html
Put the snippet in an inline script in the head, above your analytics snippet.
Update router mode
Move to history mode when you can, and add a server fallback to index.html.
Use a Custom HTML tag
Paste the script into a Custom HTML tag fired on Consent Initialization or Initialization - All Pages, so it runs before your GA4 configuration tag.
Set tag sequencing
In the GA4 tag's Advanced Settings, choose Tag Sequencing and fire the Custom HTML tag first.
How to confirm it's fixed
Open a test link in a private window
Use
https://yoursite.com/?utm_source=test&utm_medium=cpc&utm_campaign=hashcheck#/pricing.Check GA4 DebugView or RealtimeGoogle Analytics 4
The session should show source
testand mediumcpc.Test the old style link too
Open
/#/pricing?utm_source=testand confirm the script moves the tags and the source is still read.Move to another page and convert
Navigate inside the app and submit a test lead. The conversion should stay attributed to the test campaign.
Before
- UTMs sit after the # in the URL
- GA4 reads no campaign data
- Paid and email visits show as direct
After
- UTMs sit before the # or are moved there by script
- GA4 sees source, medium and campaign
- Reports credit the right channel
How to prevent it happening again
- Write a UTM link rule: parameters always go before the #.
- Use a link builder template that fixes the URL structure.
- Test every new campaign link in a private window before launch.
- Prefer history-mode routing for new apps.
- Re-test tagged links after router, hosting or analytics changes.
- Watch for sudden growth in direct traffic on your app's entry page.
How FunnelGuard handles this
FunnelGuard does not check this yet. Spotting UTMs placed after a # is a possible future check, but today it is not part of the product.
What FunnelGuard does do nearby: a robot visitor runs your real journeys, such as a lead form or checkout, on a schedule, and checks the tracking hits sent to GA4, Google Ads, Meta and other platforms, plus whether test leads reach your inbox and CRM. If a tag stops firing after a release, that can show up. It will not tell you that your campaign links are shaped wrongly.
To watch for this issue yourself, test each new campaign link in a private window and read the source in GA4 DebugView. You can also add a GA4 exploration or report that tracks the share of direct sessions on your app's entry page, and review it monthly. A free FunnelGuard plan (1 site, 2 journeys, daily checks) can still cover your main lead journey while you do this.
Questions people ask
Why is GA4 ignoring my UTM parameters?
One common cause is that the UTMs are placed after a # in the URL. GA4 reads campaign tags from the query string, which comes before the #. Move them before the # and the source and medium will be recorded.
Do UTM parameters work after a hash in the URL?
No, not for standard analytics. Everything after # is the fragment, which browsers do not send to servers and GA4 does not treat as the query string. UTMs must sit between ? and #.
How do I add UTM parameters to a React HashRouter app?
Put them in the real query string before the hash, like https://example.com/?utm_source=google&utm_medium=cpc#/pricing. The router still reads the hash route, while GA4 reads the UTMs. Moving to BrowserRouter is the cleaner long-term fix.
Why does my SPA traffic show as direct in Google Analytics?
If campaign links have their UTMs after the #, GA4 sees no campaign data and falls back to direct or referral. Other causes include redirects that strip the query string and missing UTMs on email or SMS links.
Can I fix old links that already have UTMs after the #?
Yes. Add a small script high in the head that moves utm_ and click ID parameters from the hash into the query string with history.replaceState before analytics loads. It must run before GA4 or Google Tag Manager reads the URL.
Does this also affect gclid and fbclid?
Yes. Click IDs after the # are not read as part of the query string either, so Google Ads and Meta may not link the click to a conversion. Treat them the same as UTMs.
Does FunnelGuard detect UTMs placed after the #?
Not yet. It is a possible future check. FunnelGuard currently checks journeys, tracking hits and lead delivery, so you should test campaign links yourself in GA4 DebugView.
Related issues
- TRK-311UTMs lost on redirect (http->https, www, trailing slash)Fix guide
- TRK-312UTMs lost when moving from landing page to form pageFix guide
- TRK-320UTM parameters URL-encoded twiceFix guide
- TRK-329Direct traffic inflated by missing UTMs on emails/SMSFix guide
- TRK-334Server redirects drop query string (301 to /)Fix guide
- TRK-317UTMs overwritten by internal links with utm tagsFix guide