Fix Fragment Before Query Error in 60 Seconds

UTMGuard Team
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:

❌ 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)

Step 1: Swap the Order (30 seconds)

Change this:

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

To this:

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 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

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

When you put UTM parameters after the hash:

domain.com#section?utm_params

The browser sees:

  • URL sent to server: domain.com
  • Fragment kept locally: #section?utm_params

Your UTM parameters never reach Google Analytics.

Real Example: 30-Second Fix Saves $5K Campaign

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

Broken URL:

saas-app.com#features?utm_source=linkedin&utm_campaign=launch

Fixed URL (30 seconds later):

saas-app.com?utm_source=linkedin&utm_campaign=launch#features

Result:

  • Tracking restored immediately
  • Remaining 12 days tracked correctly
  • Clear ROI data for future campaigns

Time to fix: 30 seconds Value saved: $5,000 in attribution data

Common Variations of This Error

Variation 1: Multiple Anchors

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

(Only one anchor allowed; use the first one)

Variation 2: SPA Hash Routing

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

Variation 3: Anchor with Special Characters

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

Quick Validation Checklist

Before launching, verify:

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

Prevention: Never Make This Mistake Again

Use This URL Template

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) - optional
  5. Anchor name - optional

Automation

Stop manually checking URLs. UTMGuard:

  • Scans your GA4 data automatically
  • Detects fragment-before-query errors
  • Alerts you before campaigns launch
  • Shows exact sessions affected

✅ 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. The fix only affects future traffic.

Do I need to restart my campaigns?

No. Just update the URLs. Active campaigns will track correctly immediately.

How fast does the fix work?

Instant. Test in GA4 Real-Time reports within 60 seconds.

Can I skip the anchor entirely?

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

What if I have multiple UTM parameters?

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

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

Conclusion

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

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

Update your campaign URLs. Test in GA4 Real-Time. Done in 60 seconds.


Technical Reference: Fragment Before Query Validation Rule