The new Radar JavaScript SDK brings the power of location context to the web, including geofencing, home and work detection, and place detection.
The SDK uses the HTML5 geolocation API. Because Radar does most heavy lifting server-side, the library is simple and lightweight.
For example, an e-commerce website could use the JavaScript SDK to understand if a user is comparison shopping in-store, then show relevant offers:
<script src="https://js.radar.io/v1-beta/radar.js"></script>
...
<script type="text/javascript">
Radar.initialize(publishableKey);
Radar.trackOnce(function(status, location, user, events) {
if (status === Radar.STATUS.SUCCESS) {
if (user.place.chain.slug === 'walmart') {
// do something
}
}
});
</script>
A sports website could use the SDK to understand if a user is at a stadium, then show live stats and content for the current game:
import Radar from 'radar-sdk-js';
Radar.initialize(publishableKey);
...
componentDidMount() {
Radar.trackOnce((status, location, user, events) => {
if (status === Radar.STATUS.SUCCESS) {
for (const geofence in user.geofences) {
if (geofence.tag === 'stadium') {
// do something
}
}
}
});
}
Or, a travel website could use the SDK to understand if a user is traveling, then show flight and hotel options for the appropriate airport or city. The possibilities are endless.
The JavaScript SDK is currently in beta. Check out the radar-sdk-js repo on GitHub and the radar-sdk-js package on npm to get started.
You can also try a demo:
Happy coding!
See what Radar’s location and geofencingsolutions can do for your business.