city-hive-custom-elements

City Hive SDK

Make sure you received the API Key from us.

First, add the SDK code to the page:

<script>
window.cityHiveSDKInit = function(cityHiveSDK) {
window.cityHiveSDK = cityHiveSDK;
// Called when the SDK is Ready.
}
</script>
<script async src="https://widget.cityhive.net/city-hive-sdk.js"></script>

By default, the SDK instance is not exposed on window, we let you decide whether or not to do so.

To use the Destinations SDK, initialize a Destinations instance, providing your appID and apiKey.

const destinations = cityHiveSDK.Destinations({appID: "your-app-id", apiKey: "your-api-key"});
const params = {upc: "123"};
destinations.getOffersForUpc(params).then(offer => {
console.info(offer.name + " for: " + offer.bestPrice.toString())
})

The SDK allows for providing the user's location directly or alternatively, you can leverage our builtin GeoIP translation layer that will provide offers based on the user's IP address.

In the example above, you can pass the user's location as follows:

const destinations = cityHiveSDK.Destinations({appID: "your-app-id", apiKey: "your-api-key"});
const userLocation = {latitude: 40.6895034, longitude: -74.0441627};
const params = {upc: "123", userLocation: userLocation};
destinations.getOffersForUpc(params).then(offer => {
console.info(offer.name + " for: " + offer.bestPrice.toString())
})