troubleshootingUpdated 2025

Fix UTM in Path Issue: Convert to Query String

Quick fix for UTM parameters in URL path. Convert path-based to query-based format and restore GA4 tracking in 5 minutes.

7 min readtroubleshooting

Your UTM parameters are in the URL path instead of the query string. GA4 doesn't track them.

Here's the 5-minute fix to convert path-based to query-based format.

🚨 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 (10-Second Version)

Code
❌ PATH-BASED (broken):
site.com/page/utm_source/facebook/utm_medium/cpc

✅ QUERY-BASED (working):
site.com/page?utm_source=facebook&utm_medium=cpc

GA4 only reads query strings (after ?), not URL paths.

The 5-Minute Fix

Step 1: Identify Path-Based UTMs (1 minute)

Your URLs look like folder structures:

Code
❌ site.com/article/utm_source/newsletter/
❌ site.com/products/source/facebook/medium/cpc/
❌ site.com/page/facebook/cpc/spring/

All WRONG - UTMs in path

Step 2: Convert Format (2 minutes)

Conversion formula:

Code
Remove: Folder slashes (/)
Add: Question mark before first param (?)
Add: Ampersands between params (&)
Add: Equal signs for key-value (=)

Examples:

Code
❌ site.com/page/utm_source/facebook/utm_medium/cpc/
✅ site.com/page?utm_source=facebook&utm_medium=cpc

❌ site.com/article/source/newsletter/campaign/weekly/
✅ site.com/article?utm_source=newsletter&utm_campaign=weekly

❌ site.com/products/facebook/paid/spring2024/
✅ site.com/products?utm_source=facebook&utm_medium=paid&utm_campaign=spring2024

Step 3: Update Active Campaigns (1 minute)

Replace broken URLs everywhere:

  • Social media posts
  • Email campaigns
  • Paid ads
  • Partner links

Step 4: Test (1 minute)

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

Done? Tracking restored.

😰 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: Common Causes

WordPress, Webflow, and other CMS platforms sometimes interpret UTM parameters as page structure:

Code
WordPress Custom Permalinks:
/%postname%/utm_source/%utm_source%/utm_medium/%utm_medium%/

Result:
site.com/article/utm_source/facebook/utm_medium/cpc/

Fix: Remove UTM variables from permalink structure.

Cause 2: URL Rewrite Rules Gone Wrong

Server-side rewrite rules can accidentally convert query strings to paths:

Apache
# ❌ WRONG Apache rewrite rule
RewriteRule ^(.*)$ /$1 [QSA]
 
# Converts: site.com?utm_source=x
# To: site.com/utm_source/x
Javascript
// ❌ WRONG - Builds path instead of query
function buildUrl(base, source, medium) {
  return `${base}/${source}/${medium}/`;
}
 
// Result: site.com/page/facebook/cpc/

Cause 4: Copy-Paste from Path-Based System

Some marketing platforms display tracking params as paths in their UI, and users copy this format directly.

Quick Conversion Tool (JavaScript)

Javascript
// Convert path-based UTM to query-based
function convertPathToQuery(pathUrl) {
  // Extract base URL and path components
  const parts = pathUrl.split('/').filter(p => p);
 
  // Find where UTM parameters start
  const utmIndex = parts.findIndex(p =>
    p.startsWith('utm_') ||
    p === 'source' ||
    p === 'medium' ||
    p === 'campaign' ||
    p === 'content' ||
    p === 'term'
  );
 
  if (utmIndex === -1) {
    return pathUrl; // No UTMs found
  }
 
  // Base URL (everything before UTMs)
  const protocol = pathUrl.startsWith('http') ? pathUrl.split('//')[0] + '//' : '';
  const domain = pathUrl.match(/(?:https?:\/\/)?([^\/]+)/)?.[1] || '';
  const pathParts = parts.slice(0, utmIndex);
  const base = protocol + domain + '/' + pathParts.join('/');
 
  // Extract UTM parameters
  const utmParts = parts.slice(utmIndex);
  const utmParams = [];
 
  for (let i = 0; i < utmParts.length; i += 2) {
    const key = utmParts[i].startsWith('utm_') ? utmParts[i] : `utm_${utmParts[i]}`;
    const value = utmParts[i + 1] || '';
    if (value) {
      utmParams.push(`${key}=${value}`);
    }
  }
 
  // Rebuild as query string
  return utmParams.length ? `${base}?${utmParams.join('&')}` : base;
}
 
// Usage
const broken = 'https://site.com/page/utm_source/facebook/utm_medium/cpc/';
const fixed = convertPathToQuery(broken);
console.log(fixed);
// Output: https://site.com/page?utm_source=facebook&utm_medium=cpc

Common Path-Based Patterns

Pattern 1: Full utm_ Prefix

Code
❌ site.com/page/utm_source/facebook/utm_medium/cpc/utm_campaign/spring/
✅ site.com/page?utm_source=facebook&utm_medium=cpc&utm_campaign=spring

Pattern 2: Abbreviated Keys

Code
❌ site.com/page/source/facebook/medium/cpc/campaign/spring/
✅ site.com/page?utm_source=facebook&utm_medium=cpc&utm_campaign=spring

Pattern 3: No Key Labels

Code
❌ site.com/page/facebook/cpc/spring/
✅ site.com/page?utm_source=facebook&utm_medium=cpc&utm_campaign=spring
(Assumes order: source, medium, campaign)

Pattern 4: Mixed Format

Code
❌ site.com/page/utm_source/facebook?other=value
✅ site.com/page?utm_source=facebook&other=value
(Keep all parameters in query string)

Bulk Conversion (Spreadsheet)

If you have many URLs to fix:

Google Sheets Formula:

Code
=REGEXREPLACE(
  REGEXREPLACE(
    REGEXREPLACE(A1,
      "/utm_source/([^/]+)/",
      "?utm_source=$1&"),
    "/utm_medium/([^/]+)/",
    "utm_medium=$1&"),
  "/utm_campaign/([^/]+)/",
  "utm_campaign=$1")

This converts:

  • First occurrence → Adds ?
  • Subsequent occurrences → Adds &

Python Bulk Converter:

Python
import re
 
def convert_path_to_query(url):
    # Pattern to match path-based UTMs
    pattern = r'/utm_(source|medium|campaign|content|term)/([^/]+)'
 
    matches = re.findall(pattern, url)
    if not matches:
        return url
 
    # Remove path-based UTMs from URL
    base = re.split(r'/utm_', url)[0]
 
    # Build query string
    params = [f"utm_{key}={value}" for key, value in matches]
 
    return f"{base}?{'&'.join(params)}"
 
# Usage
urls = [
    "site.com/page/utm_source/facebook/utm_medium/cpc/",
    "site.com/article/utm_source/email/utm_campaign/newsletter/"
]
 
for url in urls:
    print(convert_path_to_query(url))

Platform-Specific Quick Fixes

WordPress

Code
1. Admin → Settings → Permalinks
2. Select: Post name (/%postname%/)
3. Ensure no UTM variables in custom structure
4. Save Changes
5. Flush cache (W3 Total Cache, WP Super Cache, etc.)

Webflow

Code
1. CMS Settings → URL Structure
2. Remove UTM variables from slug structure
3. Check Collection Template Settings
4. Republish site

Shopify

Code
1. Online Store → Preferences
2. Check URL format settings
3. Ensure query parameters not routed to paths
4. Clear cache

Custom Site (.htaccess redirect)

Apache
# Add to .htaccess to redirect old path format to query format
RewriteEngine On
RewriteRule ^(.+)/utm_source/([^/]+)/utm_medium/([^/]+)/?$ /$1?utm_source=$2&utm_medium=$3 [R=301,L,QSA]

This creates 301 redirects so old URLs automatically forward to correct query format.

Real Example: E-commerce Campaign

Company: Fashion retailer Campaign: Instagram ads for spring collection URL Builder: Custom system with path-based output

Broken URLs sent to Instagram:

Code
shop.com/products/utm_source/instagram/utm_medium/paid-social/utm_campaign/spring-2024/

Result in GA4:

  • Source/Medium: (direct) / (none)
  • Campaign: (not set)
  • $4,200 ad spend with zero attribution

Fixed with query format (5 minutes):

Code
shop.com/products?utm_source=instagram&utm_medium=paid-social&utm_campaign=spring-2024

Result:

  • Full campaign attribution restored
  • ROI tracking accurate for remaining 3 weeks
  • Future campaigns prevented from same error

✅ 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

If you have published links, set up 301 redirects from old format to new format using .htaccess or your platform's redirect manager.

Can I automate the conversion?

Yes, use server rewrite rules (see Platform-Specific section) or the JavaScript function above to convert automatically.

What if I have thousands of URLs to fix?

Use bulk conversion in spreadsheets, then update campaign management platforms in bulk. Most platforms allow CSV import for bulk URL updates.

Do I need to pause my campaigns?

No. Just update the URLs. Tracking resumes immediately for new clicks. Consider 301 redirects for already-published links.

How do I prevent this from happening again?

  • Disable CMS URL rewriting features for query parameters
  • Always use query string format for UTM parameters
  • Validate URLs before campaign launch
  • Use standard URL builders (Google Campaign URL Builder, UTMGuard)

Why do some platforms use path-based tracking?

Some analytics platforms (not GA4) can parse path-based parameters, but GA4 strictly requires query strings. Always use query format for GA4 compatibility.

Can search engines index both URL formats?

Yes, but they treat them as different pages. Use canonical tags and 301 redirects to consolidate SEO value to the query string version.

What if my CMS automatically converts query strings to paths?

Check your CMS permalink settings. Disable path-based query parameter routing. If unavailable, use 301 redirects to convert back to query format.

How do I test if conversion worked?

  1. Visit the new URL
  2. Open browser console
  3. Run: new URL(location.href).searchParams.get('utm_source')
  4. Should return your UTM source value
  5. Check GA4 Real-Time for campaign appearance

Does this affect other query parameters?

No. Only UTM parameters in paths need conversion. Other query parameters should already use query string format.

Conclusion

UTM parameters in URL path? Convert to query string format.

Conversion:

Code
❌ BROKEN: site.com/page/utm_source/facebook/utm_medium/cpc/
✅ FIXED:  site.com/page?utm_source=facebook&utm_medium=cpc

Steps:

  1. Remove folder slashes
  2. Add ? before first parameter
  3. Use & between parameters
  4. Use = for key-value pairs
  5. Test in GA4 Real-Time

Fixed in 5 minutes. Perfect tracking restored.


Technical Reference: UTM in Path 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.