PDP Variant Redirect Stripping Query Parameters Fix
Learn how to fix your landing page URLs from redirecting and stripping query parameter/UTMs
Overview
Are your landing page URLs redirecting and stripping query parameter and UTMs?
- In theme.js, update _updateHistoryState function to the following:
_updateHistoryState: function(variant) {
if (!history.replaceState || !variant) {
return;
}
var newurl =
window.location.protocol +
"//" +
window.location.host +
window.location.pathname +
"?variant=" +
variant.id;
var pastParam = this._getAllParameters('variant')
if (pastParam != '') {
newurl += `&${pastParam}`
}
window.history.replaceState({ path: newurl }, "", newurl);
},
/* Get all Paramter */
_getAllParameters: function(except='none') {
var result = '',
tmp = [],
idx = 0;
location.search
.substr(1)
.split("&")
.forEach(function (item) {
tmp = item.split("=");
if ((except == 'none') || (tmp[0] !== except)) {
if (idx != 0) {
result += '&';
}
idx++;
result += `${tmp[0]}=${decodeURIComponent(tmp[1])}`;
}
});
return result;
},
Updated 5 months ago