URL Structure and UTM Basics: Complete Beginner's Guide
Learn URL structure fundamentals: paths, query strings, fragments. Master UTM parameter placement for perfect GA4 tracking.
You're building your first marketing campaign. Someone tells you to "add UTM parameters to the URL."
You open a URL builder. You copy-paste some parameters. You launch the campaign.
Then GA4 shows zero campaign data.
What went wrong? You don't understand URL structure. And that's okay—this guide explains everything.
Table of contents
- URL Anatomy 101
- Part 1: The Scheme (Protocol)
- Part 2: The Domain
- Part 3: The Path
- Part 4: The Query String (UTM Parameters Go Here)
- Query String Rules
- Query String Anatomy
- Part 5: The Fragment (Anchor Links)
- URL Order Matters
- ✅ CORRECT Order
- ❌ WRONG Order
- UTM Parameters Explained
- The 5 UTM Parameters
- Required vs Optional
- Parameter Naming Rules
- Building Your First Campaign URL
- Step 1: Start with Landing Page
- Step 2: Add Question Mark
- Step 3: Add utmsource
- Step 4: Add utmmedium
- Step 5: Add utmcampaign
- Step 6: (Optional) Add Fragment
- Common URL Structure Mistakes
- Mistake 1: No Question Mark
- Mistake 2: Fragment Before Query
- Mistake 3: Using & Instead of ?
- Mistake 4: Multiple Question Marks
- Mistake 5: Spaces in Parameters
- Testing Your URL
- Method 1: Browser Console
- Method 2: GA4 Real-Time
- Method 3: URL Validator
- URL Building Best Practices
- 1. Use a URL Builder
- 2. Follow Naming Conventions
- 3. Validate Before Launch
- 4. Test in GA4
- FAQ
- What's the difference between path and query string?
- Can I have a URL with only a query string and no path?
- Do query parameters affect SEO?
- Can I use uppercase in UTM parameters?
- What's the maximum URL length?
- Can I have spaces in URLs?
- Conclusion
🚨 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
URL Anatomy 101
Every URL has up to 5 main parts:
https://shop.com:443/products/shoes?utm_source=facebook&size=10#reviews
↑ ↑ ↑ ↑ ↑ ↑
scheme domain port path query string fragment
1. Scheme: https://
2. Domain: shop.com
3. Port: :443 (usually hidden)
4. Path: /products/shoes
5. Query string: ?utm_source=facebook&size=10
6. Fragment: #reviews
For marketing campaigns, you care about:
- Path: Where users land
- Query string: Where UTM parameters go
- Fragment: Optional anchor link
Part 1: The Scheme (Protocol)
https://shop.com
↑
scheme
Common schemes:
https://- Secure web (recommended)http://- Insecure web (avoid)mailto:- Email addressestel:- Phone numbers
For campaigns: Always use https:// (more secure, better SEO).
Part 2: The Domain
https://shop.com/products
↑
domain
Examples:
shop.comwww.shop.comsubdomain.shop.com
For campaigns: Use your primary domain (match your GA4 property).
Part 3: The Path
https://shop.com/products/shoes/nike-air-zoom
↑
path
The path is where users land on your site:
/- Homepage/products- Products page/products/shoes- Shoes category/blog/article- Blog post
For campaigns: Point to your landing page path.
Part 4: The Query String (UTM Parameters Go Here)
https://shop.com/products?utm_source=facebook&utm_medium=cpc
↑
query string starts with ?
Query String Rules
- Starts with
?(question mark) - Parameters separated by
&(ampersand) - Format:
key=value - Example:
?color=blue&size=10&utm_source=facebook
Query String Anatomy
?utm_source=facebook&utm_medium=cpc&utm_campaign=spring
↑ ↑ ↑ ↑ ↑ ↑ ↑
│ │ │ │ │ │ │
│ │ │ │ │ │ └─ value
│ │ │ │ │ └──────── key
│ │ │ │ └────────────────── separator
│ │ │ └───────────────────────── value
│ │ └────────────────────────────── key
│ └─────────────────────────────────────── separator
└────────────────────────────────────────────── starts query string
😰 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
Part 5: The Fragment (Anchor Links)
https://shop.com/products?utm_source=facebook#reviews
↑
fragment
Purpose: Scroll to specific section on page.
Example HTML:
<div id="reviews">Customer Reviews</div>
URL: shop.com/products#reviews → Scrolls to reviews sectionImportant: Fragment comes AFTER query string.
URL Order Matters
✅ CORRECT Order
https://shop.com/products?utm_source=facebook#reviews
1 2 3 4
1. Domain
2. Path
3. Query string (UTMs)
4. Fragment
❌ WRONG Order
https://shop.com/products#reviews?utm_source=facebook
1 2 4 3
Problem: Fragment comes before query string
Result: UTMs become part of fragment, not sent to server
UTM Parameters Explained
The 5 UTM Parameters
?utm_source=facebook # Where traffic comes from
&utm_medium=cpc # Marketing medium (channel)
&utm_campaign=spring2024 # Campaign identifier
&utm_content=carousel-v1 # Ad variant (optional)
&utm_term=running-shoes # Keyword/audience (optional)
Required vs Optional
Required (always use):
utm_source- Traffic source (facebook, google, email)utm_medium- Marketing medium (cpc, social, email, organic)utm_campaign- Campaign name (spring2024, launch, retarget)
Optional (use when needed):
utm_content- Ad creative or link variant (banner-v1, text-link)utm_term- Paid search keyword or audience (running-shoes, lookalike)
Parameter Naming Rules
✅ Do:
- Use lowercase:
utm_source=facebook - Use hyphens:
utm_campaign=spring-sale-2024 - Use underscores:
utm_campaign=spring_sale_2024 - Keep it short:
utm_campaign=spring24
❌ Don't:
- Use uppercase:
utm_source=Facebook(breaks channel grouping) - Use spaces:
utm_campaign=spring sale(breaks URL) - Use special chars:
utm_campaign=spring&sale(breaks parsing)
Building Your First Campaign URL
Step 1: Start with Landing Page
https://shop.com/products/shoes
Step 2: Add Question Mark
https://shop.com/products/shoes?
↑
Add this
Step 3: Add utm_source
https://shop.com/products/shoes?utm_source=facebook
Step 4: Add utm_medium
https://shop.com/products/shoes?utm_source=facebook&utm_medium=cpc
↑
Add & separator
Step 5: Add utm_campaign
https://shop.com/products/shoes?utm_source=facebook&utm_medium=cpc&utm_campaign=spring2024
Step 6: (Optional) Add Fragment
https://shop.com/products/shoes?utm_source=facebook&utm_medium=cpc&utm_campaign=spring2024#featured
Final URL: Complete and valid!
Common URL Structure Mistakes
Mistake 1: No Question Mark
❌ shop.com/products utm_source=facebook
✅ shop.com/products?utm_source=facebook
Mistake 2: Fragment Before Query
❌ shop.com/products#section?utm_source=facebook
✅ shop.com/products?utm_source=facebook#section
Mistake 3: Using & Instead of ?
❌ shop.com/products&utm_source=facebook
✅ shop.com/products?utm_source=facebook
Mistake 4: Multiple Question Marks
❌ shop.com/products?color=blue?utm_source=facebook
✅ shop.com/products?color=blue&utm_source=facebook
Mistake 5: Spaces in Parameters
❌ shop.com/products?utm_campaign=spring sale
✅ shop.com/products?utm_campaign=spring-sale
Testing Your URL
Method 1: Browser Console
const url = new URL('YOUR_CAMPAIGN_URL');
console.log('UTM Source:', url.searchParams.get('utm_source'));
console.log('UTM Medium:', url.searchParams.get('utm_medium'));
console.log('UTM Campaign:', url.searchParams.get('utm_campaign'));Expected: All three should show values, not null.
Method 2: GA4 Real-Time
- Visit your campaign URL in incognito mode
- Open GA4 → Real-Time reports
- Look for your session with campaign attribution
- Verify source, medium, campaign appear correctly
Method 3: URL Validator
Paste into a URL validator tool:
- Check for syntax errors
- Verify length (< 420 chars for GA4)
- Confirm all parameters detected
URL Building Best Practices
1. Use a URL Builder
Don't build manually. Use:
- Google's Campaign URL Builder
- Your marketing platform's builder
- UTMGuard's validator
- Custom team template
2. Follow Naming Conventions
Create a standard format:
utm_campaign format: `{"{"}{"{"}year{"}"}{"}"}}`-`{"{"}{"{"}type{"}"}{"}"}}`-`{"{"}{"{"}detail{"}"}{"}"}}`
Examples:
2024-spring-shoes
2024-launch-prodX
2024-retarget-cart
3. Validate Before Launch
Always check: ✅ URL length < 420 characters ✅ Question mark before first parameter ✅ Fragment (if used) comes last ✅ No spaces or special characters ✅ All parameters lowercase
4. Test in GA4
Never skip testing:
- Visit URL in incognito
- Check GA4 Real-Time
- Verify campaign appears
- Confirm all parameters tracked
✅ 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
Join 2,847 marketers fixing their tracking daily
FAQ
What's the difference between path and query string?
Path is WHERE users land (/products). Query string is additional DATA sent with the request (?utm_source=x).
Can I have a URL with only a query string and no path?
Yes: shop.com?utm_source=facebook (path defaults to /).
Do query parameters affect SEO?
UTM parameters don't affect SEO. Google strips them when indexing. Use canonical tags to be safe.
Can I use uppercase in UTM parameters?
Technically yes, but DON'T. GA4 channel grouping is case-sensitive. Always use lowercase.
What's the maximum URL length?
Google Search supports 2,048 chars. But GA4 truncates at 420 chars. Always stay under 420.
Can I have spaces in URLs?
Spaces must be URL-encoded as %20. Better practice: use hyphens instead.
Conclusion
URL structure for UTM tracking:
https://domain.com/path?utm_source=x&utm_medium=y&utm_campaign=z#anchor
Order:
1. Domain and path
2. ? (starts query string)
3. UTM parameters (& separators)
4. # (optional anchor)
Master this structure once, and every campaign URL will track perfectly.
Technical Reference: Missing Query Separator Validation Rule