Next Commerce
Data AttributesURL Parameters

JavaScript API

Read and modify URL parameters from JavaScript. All methods are exposed on window.next after the SDK initializes.


Reading Parameters

// Get a single parameter
const variant = next.getParam('variant');  // 'a' | undefined

// Check if a parameter exists
if (next.hasParam('debug')) {
  console.log('Debug mode active');
}

// Get every parameter as an object
const allParams = next.getAllParams();
// → { variant: 'a', utm_source: 'google', ... }

Setting Parameters

// Set a single parameter (and update storage + URL)
next.setParam('banner', 'n');

// Set multiple parameters at once
next.setParams({
  timer: 'n',
  reviews: 'n',
});

Setting a parameter triggers re-evaluation of every data-next-show / data-next-hide element bound to it. The page UI updates immediately.


Clearing Parameters

// Remove one parameter
next.clearParam('timer');

The cleared parameter is removed from sessionStorage. Page elements that depended on it re-evaluate their visibility.


API Reference

MethodDescription
next.getParam(name)Returns the parameter value as a string, or undefined if not set
next.getAllParams()Returns an object with every captured parameter
next.hasParam(name)Returns true if the parameter is set (regardless of value)
next.setParam(name, value)Stores a parameter and updates dependent UI
next.setParams(object)Stores multiple parameters in one call
next.clearParam(name)Removes a parameter

Example: Reading the Variant in Analytics

window.nextReady.push(() => {
  const variant = next.getParam('variant');
  if (variant) {
    gtag('event', 'ab_variant_view', { variant });
  }
});

Example: Setting a Flag From a Button

<button onclick="next.setParam('preview', 'true')">
  Enable preview mode
</button>
<div data-next-show="param.preview">
  <p>You are in preview mode</p>
</div>

After the button is clicked, the preview block appears immediately.

There is no JavaScript event for "parameter changed". Conditional displays update automatically, but if you have your own JavaScript that depends on a parameter, you need to read it again after calling setParam/setParams.

On this page