troubleshootingUpdated 2025

Fix Fragment Before Query Error in 60 Seconds

Your UTMs are in the wrong order. Here's the instant fix that restores campaign tracking in Google Analytics 4.

6 min readtroubleshooting

You got an alert: "Fragment Before Query detected in your campaign URLs."

You're seeing unattributed traffic in GA4. Your campaign data is missing.

Here's the 60-second fix.

🚨 Not sure what's breaking your tracking?

Run a free 60-second audit to check all 40+ ways UTM tracking can fail.

Scan Your Campaigns Free

✓ No credit card ✓ See results instantly

The Problem (5-Second Version)

Your URL has the # symbol before the ? symbol:

Code
❌ yoursite.com#pricing?utm_source=facebook

Everything after # stays in the browser and never reaches Google Analytics.

Result: Zero campaign tracking.

The Fix (3 Steps - 60 Seconds Total)

Step 1: Swap the Order (30 seconds)

Change this:

Code
yoursite.com#pricing?utm_source=facebook&utm_campaign=summer

To this:

Code
yoursite.com?utm_source=facebook&utm_campaign=summer#pricing

That's it. Question mark ? BEFORE hash #.

Step 2: Update Active Campaigns (20 seconds)

Replace the broken URL in:

  • Social media posts
  • Email campaigns
  • Paid ads
  • QR codes

No need to pause campaigns. Just update the destination URLs.

Step 3: Test (10 seconds)

  1. Visit your corrected URL in incognito mode
  2. Open GA4 → Real-Time reports
  3. Verify campaign appears

Done. Your tracking is fixed.

😰 Is this your only tracking issue?

This is just 1 of 40+ ways UTM tracking breaks. Most marketing teams have 8-12 critical issues they don't know about.

• 94% of sites have UTM errors

• Average: $8,400/month in wasted ad spend

• Fix time: 15 minutes with our report

✓ Connects directly to GA4 (read-only, secure)

✓ Scans 90 days of data in 2 minutes

✓ Prioritizes issues by revenue impact

✓ Shows exact sessions affected

Get Your Free Audit Report

Why This Happens: URL Structure Rules

The # symbol (fragment/anchor) is for in-page navigation. Browsers don't send anything after # to servers.

Standard URL structure:

Code
https://domain.com/path?query_parameters#fragment
                      ↑                  ↑
                   Query comes first   Fragment comes last

When you put UTM parameters after the hash:

Code
domain.com#section?utm_source=facebook&utm_medium=cpc
          ↑       ↑
       Fragment  Query (WRONG ORDER!)

What the browser does:

  1. Sends to server: domain.com
  2. Keeps locally: #section?utm_source=facebook&utm_medium=cpc

Your UTM parameters never reach Google Analytics.

Technical Explanation

How browsers parse URLs:

Code
URL: https://shop.com/products?category=shoes&utm_source=email#reviews

Sent to server (GA4 can see):
- Domain: shop.com
- Path: /products
- Query: category=shoes&utm_source=email

Kept in browser (GA4 cannot see):
- Fragment: #reviews

With wrong order (#products?utm...):

Code
URL: https://shop.com#products?utm_source=email

Sent to server:
- Domain: shop.com
- Path: /
- Query: (empty)

Kept in browser:
- Fragment: #products?utm_source=email

GA4 receives zero tracking data.

Real Example: $5K Campaign Saved in 30 Seconds

Campaign: LinkedIn product launch Budget: $5,000 Problem: Zero attribution after 2 days

Broken URL:

Code
saas-app.com#features?utm_source=linkedin&utm_medium=paid-social&utm_campaign=launch

What GA4 saw:

  • Source/Medium: (direct) / (none)
  • Campaign: (not set)
  • 2 days of spend: $714 with zero attribution

Fixed URL (30 seconds later):

Code
saas-app.com?utm_source=linkedin&utm_medium=paid-social&utm_campaign=launch#features

Result:

  • Tracking restored immediately
  • Remaining 12 days tracked correctly
  • Clear ROI data for future campaigns
  • $4,286 in remaining spend properly attributed

Time to fix: 30 seconds Value saved: Complete attribution for $5,000 campaign

Common Variations of This Error

Variation 1: Multiple Anchors

Code
❌ site.com#header?utm_source=email#footer
✅ site.com?utm_source=email#header

Rule: Only one anchor allowed. Place it last. Use the first anchor, discard others.

Variation 2: SPA Hash Routing

Single Page Apps often use hash routing:

Code
❌ app.com/#/dashboard?utm_source=twitter
✅ app.com?utm_source=twitter#/dashboard

Important: Even in SPAs, query parameters must come before hash routing paths.

Variation 3: Anchor with Special Characters

Code
❌ site.com#section-1?utm_source=facebook
✅ site.com?utm_source=facebook#section-1

Variation 4: Encoded Fragments

Code
❌ site.com#%23pricing?utm_source=google
✅ site.com?utm_source=google#pricing

Note: Even URL-encoded fragments (%23 = #) must come after query parameters.

How This Mistake Happens

Cause 1: Manual URL Construction

Code
Base URL: yoursite.com#pricing
Add UTMs: ?utm_source=facebook

Wrong result: yoursite.com#pricing?utm_source=facebook

Prevention: Always add query params before fragments.

Some third-party URL builders don't validate fragment position:

Javascript
// ❌ Wrong link builder logic
function buildUrl(base, utms, anchor) {
  return base + anchor + '?' + utms;
}

Cause 3: CMS Template Errors

Html
<!-- ❌ Wrong template order -->
<a href="{{page_url}}#{{section}}?{{utm_params}}">Link</a>
 
<!-- ✅ Correct template order -->
<a href="{{page_url}}?{{utm_params}}#{{section}}">Link</a>

Prevention: URL Construction Best Practices

Correct URL Template

Code
https://domain.com/page?utm_source={source}&utm_medium={medium}&utm_campaign={campaign}#anchor

Order:
1. Domain and path
2. ? (question mark)
3. UTM parameters (connected with &)
4. # (hash)
5. Anchor name

JavaScript URL Builder

Javascript
function buildCampaignUrl(base, utms, anchor) {
  // Remove existing query/fragment
  const cleanBase = base.split('?')[0].split('#')[0];
 
  // Build correctly ordered URL
  let url = cleanBase;
 
  if (utms) {
    url += '?' + utms;
  }
 
  if (anchor) {
    // Remove # if already present
    anchor = anchor.replace(/^#/, '');
    url += '#' + anchor;
  }
 
  return url;
}
 
// Usage
const url = buildCampaignUrl(
  'yoursite.com/page',
  'utm_source=facebook&utm_medium=cpc',
  'pricing'
);
// Output: yoursite.com/page?utm_source=facebook&utm_medium=cpc#pricing

Quick Validation Checklist

Before launching campaigns:

? appears before # in URL ✅ All UTM parameters come after ? ✅ Anchor (if used) comes last after # ✅ Only one ? in URL ✅ Only one # in URL ✅ Test shows campaign in GA4 Real-Time

Automation: Never Make This Mistake

UTMGuard automatically:

  • Scans your GA4 data for fragment-before-query errors
  • Detects broken URLs before campaigns launch
  • Alerts you with exact sessions affected
  • Shows which campaigns have the issue

✅ Fixed this issue? Great! Now check the other 39...

You just fixed one tracking issue. But are your Google Ads doubling sessions? Is Facebook attribution broken? Are internal links overwriting campaigns?

Connects to GA4 (read-only, OAuth secured)

Scans 90 days of traffic in 2 minutes

Prioritizes by revenue impact

Free forever for monthly audits

Run Complete UTM Audit (Free Forever)

Join 2,847 marketers fixing their tracking daily

FAQ

Will this fix my historical data?

No. Past data stays unattributed in GA4. The fix only affects future traffic from corrected URLs.

Do I need to restart my campaigns?

No. Just update the destination URLs in your ad platforms. Tracking works immediately for new clicks.

How fast does the fix work?

Instant. Test in GA4 Real-Time reports within 60 seconds of clicking the fixed URL.

Can I skip the anchor entirely?

Yes. If you don't need in-page navigation, remove the #anchor completely. UTMs will work perfectly without it.

What if I have multiple UTM parameters?

Same rule. All UTMs go after ?, connected with &, and the anchor # comes last:

Code
domain.com?utm_source=x&utm_medium=y&utm_campaign=z&utm_content=a#anchor

Does this affect SEO?

No. Search engines understand both fragments and query parameters. The correct order doesn't impact SEO.

Mobile app deep links follow the same URL structure rules: app://path?params#fragment

Can fragments break other tracking?

Yes. If fragments come before query parameters, ALL query-based tracking breaks (not just UTMs):

  • Affiliate tracking codes
  • Referral parameters
  • Custom tracking systems

How do I find all broken URLs?

Use UTMGuard to scan your GA4 data. It automatically detects fragment-before-query errors and shows affected sessions.

What if my SPA requires hash routing?

SPAs using hash routing (#/route) still follow the same rule:

Code
✅ app.com?utm_source=email#/dashboard
❌ app.com#/dashboard?utm_source=email

Internal Guides

External Resources

Conclusion

Fragment Before Query error? Swap the order: ? before #.

Code
❌ BROKEN: site.com#anchor?utm_params
✅ FIXED:  site.com?utm_params#anchor

Quick fix steps:

  1. Find URLs with # before ?
  2. Move ?utm_params to come before #anchor
  3. Update campaign URLs
  4. Test in GA4 Real-Time

30 seconds. Perfect tracking restored.


Technical Reference: Fragment Before Query Validation Rule

✅ Fixed this issue? Great! Now check the other 39...

You just fixed one tracking issue. But are your Google Ads doubling sessions? Is Facebook attribution broken? Are internal links overwriting campaigns?

Connects to GA4 (read-only, OAuth secured)

Scans 90 days of traffic in 2 minutes

Prioritizes by revenue impact

Free forever for monthly audits

Run Complete UTM Audit (Free Forever)

Join 2,847 marketers fixing their tracking daily

UTM

Get Your Free Audit in 60 Seconds

Connect GA4, run the scan, and see exactly where tracking is leaking budget. No credit card required.

Trusted by growth teams and agencies to keep attribution clean.