Query String vs URL Path: Where UTM Parameters Belong
Technical guide to URL structure: query strings vs paths. Learn why UTM parameters must be in query strings for GA4 tracking.
Why do UTM parameters HAVE to go in the query string? Why can't they be in the URL path?
This is the complete technical explanation of query strings vs paths, and why it matters for analytics tracking.
Table of contents
- URL Anatomy: The Two Data Locations
- 1. The Path (Hierarchical Navigation)
- 2. The Query String (Optional Parameters)
- Technical Difference: How Servers Handle Them
- Path Processing
- Query String Processing
- Why GA4 Requires Query Strings
- 1. Standard JavaScript API
- 2. Universal Convention
- 3. Browser Behavior
- When to Use Path vs Query String
- Use PATH for:
- Use QUERY STRING for:
- Real-World Examples
- E-commerce Product Page
- Blog Article
- REST API (Exception)
- RFC 3986: The Official URL Standard
- Technical Implementation Best Practices
- 1. Never Mix Path and Query for Same Data
- 2. Use Path for Content, Query for Context
- 3. Keep Paths Short, Queries Flexible
- 4. URL Encode Query Values, Not Paths
- JavaScript: Accessing Path vs Query
- FAQ
- Why can't GA4 just parse path parameters?
- Are path parameters ever okay for tracking?
- Do path parameters affect SEO differently than query parameters?
- Can I use both path and query parameters?
- What if my framework requires path parameters?
- Do all analytics platforms require query strings?
- 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: The Two Data Locations
Every URL has two places to put data:
1. The Path (Hierarchical Navigation)
https://shop.com/products/shoes/nike/air-zoom
↑
path
Purpose: Define resource location (like a file system)
Characteristics:
- Hierarchical structure (folders/subfolders)
- Defines WHAT resource you're accessing
- Permanent part of the URL
- Indexed by search engines
- Affects routing and file serving
2. The Query String (Optional Parameters)
https://shop.com/products?category=shoes&brand=nike&utm_source=facebook
↑
query string
Purpose: Provide additional data about the request
Characteristics:
- Flat key-value pairs
- Modifies HOW resource is displayed/tracked
- Temporary/contextual data
- Often ignored by search engines (via canonicals)
- Doesn't affect routing (server still serves same resource)
😰 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
Technical Difference: How Servers Handle Them
Path Processing
// Express.js example
app.get('/products/:category/:brand', (req, res) => {
const category = req.params.category; // 'shoes'
const brand = req.params.brand; // 'nike'
// Server ROUTES based on path
// Different paths = different resources
});Query String Processing
// Express.js example
app.get('/products', (req, res) => {
const category = req.query.category; // 'shoes'
const brand = req.query.brand; // 'nike'
const utm_source = req.query.utm_source; // 'facebook'
// Server FILTERS/MODIFIES based on query
// Same path, different query = same resource, different display
});Key insight: Paths define resources. Query strings modify behavior.
Why GA4 Requires Query Strings
1. Standard JavaScript API
// How GA4 extracts UTMs
const params = new URLSearchParams(window.location.search);
const source = params.get('utm_source');
const medium = params.get('utm_medium');
const campaign = params.get('utm_campaign');This only works if UTMs are in query string. If they're in the path:
window.location.pathname; // "/products/utm_source/facebook/utm_medium/cpc"
// GA4 has no standard way to parse this2. Universal Convention
Analytics platforms (GA4, Mixpanel, Amplitude) all follow the same convention:
- Tracking parameters go in query strings
- Defined in RFC 3986 URL specification
- Used by ALL major analytics tools
3. Browser Behavior
// Query string
const url = new URL('https://shop.com/products?utm_source=facebook');
console.log(url.searchParams.get('utm_source')); // 'facebook'
// Path
const url2 = new URL('https://shop.com/products/utm_source/facebook');
console.log(url2.searchParams.get('utm_source')); // nullBrowsers have built-in APIs for query strings, but not for path parameters.
When to Use Path vs Query String
Use PATH for:
Resource identification:
/products - Products page
/products/shoes - Shoes category
/products/shoes/123 - Specific shoe product
/blog/2024/article - Blog post
Hierarchical navigation:
/help/guides/getting-started
/store/locations/new-york
SEO-important structure:
/category/subcategory/product-name
(Clean URLs that define content hierarchy)
Use QUERY STRING for:
Filtering/sorting:
/products?category=shoes&color=blue&size=10
/search?q=running+shoes&sort=price
Pagination:
/blog?page=2
/products?offset=20&limit=10
Tracking/analytics:
/page?utm_source=facebook&utm_medium=cpc
/article?ref=newsletter&campaign=weekly
Optional modifications:
/product?variant=large&color=red
/video?autoplay=true&mute=false
Real-World Examples
E-commerce Product Page
✅ CORRECT:
https://shop.com/products/nike-air-zoom-39?color=blue&size=10&utm_source=facebook&utm_medium=cpc&utm_campaign=spring2024
│ │ │ │
path path (product) query (filter) query (tracking)
Breakdown:
- Path:
/products/nike-air-zoom-39- Identifies the product - Query:
color=blue&size=10- Filters product variants - Query:
utm_source=facebook&...- Tracks campaign
❌ WRONG:
https://shop.com/products/nike-air-zoom-39/color/blue/size/10/utm_source/facebook/utm_medium/cpc/utm_campaign/spring2024
Why wrong:
- Too many path segments
- Hard to parse
- Not standard convention
- GA4 can't extract UTMs
Blog Article
✅ CORRECT:
https://blog.com/2024/01/how-to-run-utm-campaigns?utm_source=newsletter&utm_medium=email
│ │ │
path path (article) query (tracking)
❌ WRONG:
https://blog.com/2024/01/how-to-run-utm-campaigns/source/newsletter/medium/email
REST API (Exception)
REST APIs DO use path parameters:
GET /api/users/123/posts/456
│ │ │ │
resource user resource post
But this is different from web analytics:
- APIs are programmatic (not browser-based)
- APIs have custom parsers
- Not subject to GA4 tracking conventions
RFC 3986: The Official URL Standard
The Internet Engineering Task Force (IETF) defines URL structure in RFC 3986:
URI = scheme:[//authority]path[?query][#fragment]
Examples:
https://example.com/path?query#fragment
│ │ │ │ │
scheme authority path query fragment
Key points from RFC 3986:
- Query components begin with
? - Query parameters separated by
& - Format:
key=value - Query is optional but standardized
- Fragment comes after query
This is why GA4 expects query strings: It's the universal standard.
Technical Implementation Best Practices
1. Never Mix Path and Query for Same Data
❌ BAD:
/products/shoes?category=shoes
(Redundant: 'shoes' in both path and query)
✅ GOOD:
/products/shoes
OR
/products?category=shoes
(Choose one location for each piece of data)
2. Use Path for Content, Query for Context
✅ GOOD:
/article/how-to-track-campaigns?utm_source=facebook&share=twitter
│ │ │ │
content (article) content (title) context (source) context (share)
3. Keep Paths Short, Queries Flexible
✅ GOOD:
/products?category=shoes&brand=nike&color=blue&size=10&utm_source=facebook
(Short path, flexible filtering in query)
❌ BAD:
/products/category/shoes/brand/nike/color/blue/size/10/utm_source/facebook
(Unmanageably long path)
4. URL Encode Query Values, Not Paths
Path: /my-article-title
(Use hyphens, keep simple)
Query: ?utm_campaign=my%20article%20title
(URL encode spaces and special chars)
JavaScript: Accessing Path vs Query
const url = 'https://shop.com/products/shoes?utm_source=facebook&size=10#reviews';
// Parse URL
const parsed = new URL(url);
// PATH
console.log(parsed.pathname); // "/products/shoes"
const pathParts = parsed.pathname.split('/').filter(Boolean);
console.log(pathParts); // ["products", "shoes"]
// QUERY STRING
console.log(parsed.search); // "?utm_source=facebook&size=10"
console.log(parsed.searchParams.get('utm_source')); // "facebook"
console.log(parsed.searchParams.get('size')); // "10"
// FRAGMENT
console.log(parsed.hash); // "#reviews"For GA4 tracking: Use parsed.searchParams (only works with query strings).
✅ 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
Why can't GA4 just parse path parameters?
It could, but it doesn't. GA4 follows universal web standards (RFC 3986) where tracking data goes in query strings.
Are path parameters ever okay for tracking?
Only if you write custom JavaScript to extract them. But this is error-prone and non-standard. Always use query strings.
Do path parameters affect SEO differently than query parameters?
Yes. Paths are indexed as separate pages. Query parameters (especially UTMs) are typically ignored via canonical tags.
Can I use both path and query parameters?
Yes, but for different purposes. Paths for content hierarchy, query for filtering/tracking.
What if my framework requires path parameters?
Use server-side rewrites to convert path parameters to query parameters for external links. Keep internal routing however you like.
Do all analytics platforms require query strings?
Yes. Google Analytics, Mixpanel, Amplitude, Adobe Analytics—all expect UTMs in query strings.
Conclusion
UTM parameters belong in query strings, not URL paths.
Why:
- RFC 3986 URL standard
- Browser APIs (URLSearchParams) only parse query strings
- GA4 and all analytics platforms expect query strings
- Universal convention across the web
Use paths for: Resource identification and content hierarchy Use query strings for: Filtering, tracking, and optional parameters
Correct structure:
https://domain.com/path/to/resource?utm_source=x&utm_medium=y&utm_campaign=z
│ │
path query string
Get this right, and analytics tracking works perfectly every time.
Technical Reference: UTM in Path Validation Rule