Adding recommendation.js to Your Site
How to use Woosmap RecommendationThis API has been deprecated and will be terminated on the 31/03/2021.
Need to automate user geolocation? Check out the Geolocation API instead.
Introduction
The recommendation.js
is a lightweight JavaScript library for quickly requesting the Woosmap Recommendation REST API. The library is designed to be small (less than 4Ko) and multi-browser (ie9 support).
This page shows you how to use Woosmap Recommendation Javascript API to provide a personalized and local experience to your visitors.
Need service or support to get started with this feature? Start your request online and we’ll find you a solution.
Get the User Position
Adding the following code to your site’s templates is the easiest way to get started using recommendation.js
.
The getUserPosition(GetPositionOptions)
returns a successCallback
with the Woosmap estimated Latitude and Longitude for the current user.
Please, check the GetPositionOptions object Specification to see how to use this method in details.
<script src="https://sdk.woosmap.com/recommendation/recommendation.js"></script>
<script>
(publicKey => {
woosmapRecommendation.setProjectKey(publicKey);
woosmapRecommendation.getConsent((consent) => {
if (consent === true) {
woosmapRecommendation.getUserPosition({
successCallback: function (latlng) {
if ('latitude' in latlng) {
console.log('User Position Found', latlng);
}
}
});
} else if (consent === false) {
// invite the user to accept your privacy policy/cookies
// before optIn him to Woosmap recommendation
// using woosmapRecommendation.optIn();
}
});
})('WOOS-XXXX-YYYY');
</script>
The string woos-XXXX-YYYY
should be replaced with your Woosmap Project Public Key.
Open the user position use case to test yourself this feature.
Get the User Recommended Stores
The getUserRecommendation(GetRecommendationOptions)
returns a successCallback with stores nearby the user estimated position.
Please, check the GetRecommendationOptions object Specification to see how to use this method in details.
<script src="https://sdk.woosmap.com/recommendation/recommendation.js"></script>
<script>
(function (publicKey) {
woosmapRecommendation.setProjectKey(publicKey);
woosmapRecommendation.getConsent((consent) => {
if (consent === true) {
woosmapRecommendation.getUserRecommendation({
successCallback: function (stores) {
if (stores && stores.features && stores.features.length > 0) {
console.log("Recommended Store Found", stores.features[0])
}
},
limit: 1
});
}
}
})('woos-XXXX-YYYY')
</script>
The string woos-XXXX-YYYY
should be replaced with your Woosmap Project Public Key.
Open the list stores use case to see this feature in action.
Contributing to Recommendation
In order to build profiles and benefit from the recommendation, every implementation must contribute to collecting location data through users’ digital journey. See Contributing doc for more details.