URLs with query parameters (e.g., ?utm_source=facebook&variant=123
) can make your Shopify store look messy, affect tracking accuracy, and even cause duplicate content issues in SEO. In this guide, you’ll learn how to automatically strip URL parameters from Shopify product pages while keeping the rest of your site unaffected.
Why Remove URL Parameters from Product Pages?
Avoids Unintended Tracking Conflicts – Some marketing tools add unwanted parameters that can break tracking.
Cleaner, More Professional URLs – Improves user experience by removing unnecessary clutter.
Prevents Duplicate Content Issues – Search engines may treat example.com/product
and example.com/product?ref=123
as separate pages, hurting SEO.
Better Analytics Accuracy – Ensures traffic is attributed to the correct page without parameter interference.
{% if template.name == 'product' %}
<script>
(function() {
// Get the current URL
const url = window.location.href;
// Check if URL has a query string (?)
if (url.includes('?')) {
// Remove everything after '?'
const cleanUrl = url.split('?')[0];
// Replace the URL in the browser (without reloading)
window.history.replaceState({}, document.title, cleanUrl);
}
})();
</script>
{% endif %}