Product Locator
Locator widget
Javascript API

Javascript API

The scripts adds a nearst object to the window object. The following methods are available:

nearst.showStores(options)

Allows you to summon the locator modal window without using a button widget. Accepts an object of options using the same keys and values as the data- keys described on the customisation page, but using camelCase rather than snake-case.

Example:

<button onclick="nearst.showStores({ 
   licenseKey: '{license_key}',
   barcode: '9781914314025',
   locale: 'en_US',
   cta: 'shop_nearby'
})">
   Find nearby store
</button>

nearst.renderWidget(element)

Allows you to render a widget that is added to the page after the initial page load.

Example:

// Create a new div and add it to body
const element = document.createElement("div");
element.className = "nearst-locator-button";
element.dataset.barcode = "9781914314025";
element.dataset.licenseKey = "example";
document.body.appendChild(element);
 
// Load the widget
nearst.renderWidget(element);

nearst.getStoresData(options)

Allows you to call the Locator API to get raw information about nearby stores selling a product.

Example:

const data = await nearst.getStoresData({
   licenseKey: "{license_key}",
   barcode: "9781914314025",
   locale: "en_US",
   geolocation: [51.5262244,-0.0782993]
});
 
console.log(data);