concat or append a fixed query string to a url in javascript

Solution:

I would use the URL API which has methods to check if a query param exists and if not add it

 

// DEMO ONLY - not for production
initDemoUrl()

const url = new URL(location.href);

if( url.pathname.includes('/product/') && !url.searchParams.has('nowprocket') ){
   url.searchParams.append('nowprocket','');
   
   // uncomment following to reload page
   // location.href = url
   
}
console.log(url)


// DEMO ONLY
function initDemoUrl(){
   history.pushState(null,null, '/product/some-slug')
}