Recommendation

Adding recommendation.js to Your Site

How to use Woosmap Recommendation

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://recommendation-js.woosmap.com/recommendation.js"></script>
<script>
(function (publicKey) {
   woosmapRecommendation.setProjectKey(publicKey);
   woosmapRecommendation.getUserPosition({
        successCallback: function (latlng) {
            if ('latitude' in latlng) {
                console.log('User Position Found' , latlng);
            }
    }});
})('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.

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://recommendation-js.woosmap.com/recommendation.js"></script>
<script>
(function (publicKey) {
   woosmapRecommendation.setProjectKey(publicKey);
   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.