technical-guidesUpdated 2025

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.

8 min readtechnical-guides

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.

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

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

Code
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

Get Your Free Audit Report

Technical Difference: How Servers Handle Them

Path Processing

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

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

Javascript
// 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:

Javascript
window.location.pathname;  // "/products/utm_source/facebook/utm_medium/cpc"
// GA4 has no standard way to parse this

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

Javascript
// 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')); // null

Browsers have built-in APIs for query strings, but not for path parameters.

When to Use Path vs Query String

Use PATH for:

Resource identification:

Code
/products          - Products page
/products/shoes    - Shoes category
/products/shoes/123 - Specific shoe product
/blog/2024/article  - Blog post

Hierarchical navigation:

Code

/help/guides/getting-started
/store/locations/new-york

SEO-important structure:

Code
/category/subcategory/product-name
(Clean URLs that define content hierarchy)

Use QUERY STRING for:

Filtering/sorting:

Code
/products?category=shoes&color=blue&size=10
/search?q=running+shoes&sort=price

Pagination:

Code
/blog?page=2
/products?offset=20&limit=10

Tracking/analytics:

Code
/page?utm_source=facebook&utm_medium=cpc
/article?ref=newsletter&campaign=weekly

Optional modifications:

Code
/product?variant=large&color=red
/video?autoplay=true&mute=false

Real-World Examples

E-commerce Product Page

✅ CORRECT:

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

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

Code
https://blog.com/2024/01/how-to-run-utm-campaigns?utm_source=newsletter&utm_medium=email
            │                   │                            │
         path              path (article)            query (tracking)

❌ WRONG:

Code
https://blog.com/2024/01/how-to-run-utm-campaigns/source/newsletter/medium/email

REST API (Exception)

REST APIs DO use path parameters:

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

Code
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

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

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

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

Code
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

Javascript
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

Run Complete UTM Audit (Free Forever)

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:

  1. RFC 3986 URL standard
  2. Browser APIs (URLSearchParams) only parse query strings
  3. GA4 and all analytics platforms expect query strings
  4. Universal convention across the web

Use paths for: Resource identification and content hierarchy Use query strings for: Filtering, tracking, and optional parameters

Correct structure:

Code
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

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.