Contributing

How to contribute to Woosmap Recommendation
  1. Contribute to Recommending API Profiles
    1. Synchronous and Asynchronous
  2. Contributing Use Cases
    1. Send User Searched Position
    2. Send User Consulted POI
    3. Send User Favorited POI
    4. Send User HTML5 Position
    5. Other Use Cases
  3. Privacy Requirements

Contribute to Recommending API Profiles

In order to build profiles and benefit from the recommendation, every implementation must contribute to collecting location data through users’ digital journey. As a reminder, consent must be checked, and obtained if it has not been yet, before contributing to location profiles. Here is the dedicated documentation on this point.

Synchronous and Asynchronous

Like described in the Loading topic, use the corresponding method depending on how you loaded the recommendation.js script.

//Synchronous
woosmapRecommendation.sendUserHtml5Position({lat: 43, lng: 3.3});

//Asynchronous
rRequestQueue.push(['sendUserHtml5Position', [{lat: 43, lng: 3.3}]]);

Contributing Use Cases

Send User Searched Position

Below is a sample HTML and Javascript code to allow your visitor to geocode an address. The resulted position will be pushed to Woosmap Profile using woosmapRecommendation.sendUserSearchedPosition()

<input type="text" name="query" id="queryinput" placeholder="Search an Address">
<input type="submit" id="search-geocoding">
<script>
function geocodeAddress(geocoder) {
    var address = document.getElementById('queryinput').value;
    geocoder.geocode({'address': address}, function (results, status) {
        if (status === google.maps.GeocoderStatus.OK) {
            var latitude = results[0].geometry.location.lat();
            var longitude = results[0].geometry.location.lng();
            //Contribute to Woosmap Profile
            woosmapRecommendation.getConsent((consent) => {
                if (consent === true) {
                    woosmapRecommendation.sendUserSearchedPosition({
                        lat: latitude,
                        lng: longitude,
                        successCallback: function () {
                            // finally, search the assets around your location
                            searchWoosmapApiAroundLocation(latitude, longitude);
                        }
                    });
                }
            });
        } else {
            console.log('Geocode was not successful: ' + status);
        }
    });
}
function init() {
    var geocoder = new google.maps.Geocoder();
    document.getElementById('search-geocoding').addEventListener('click',
        function () {
            geocodeAddress(geocoder);
        });
}
</script>
<script src="https://maps.googleapis.com/maps/api/js?key=API_KEY&callback=init">
</script>

Send User Consulted POI

The Recommendation API can improve the user location profile by collecting POIs consulted by a user. When a user select an item from a stores list (POIs list), call the woosmapRecommendation.sendUserConsultedPOI() passing the Store Id and location information as parameters. Check PostPOIPositionOptions reference.

<ul id='stores-list'>
  <li data-lat='3.41' data-lng='43.23' data-storeid='1' onclick='favoritedStore(this)'>My Store 1</li>
  <li data-lat='2.26' data-lng='42.19' data-storeid='2' onclick='favoritedStore(this)'>My Store 2</li>
</ul>
<script>
function favoritedStore(elem) {
    woosmapRecommendation.getConsent((consent) => {
        if (consent === true) {
            woosmapRecommendation.sendUserConsultedPOI({
                lat: elem.getAttribute('data-lat'),
                lng: elem.getAttribute('data-lng'),
                id: elem.getAttribute('data-storeid'),
                successCallback: function () {}
            });
        }
    });
}
</script>

Send User Favorited POI

Instead of posting a consulted POI, you could send a favorited POI by using the woosmapRecommendation.sendUserFavoritedPOI(). This method takes the same parameters as sendUserConsultedPOI().

Send User HTML5 Position

The Geolocation API, natively supported by modern browsers, defines a high-level interface to location information associated only with the device hosting the implementation, such as latitude and longitude. Here is a Javascript sample to plug this feature to your website and contribute to Woosmap profiles on success callback using woosmapRecommendation.sendUserHtml5Position().

// Acquire a new position object.
navigator.geolocation.getCurrentPosition(successCallback, errorCallback);

function successCallback(position) {
    //Contribute to Woosmap Profile
    woosmapRecommendation.sendUserHtml5Position({
        lat: position.coords.latitude,
        lng: position.coords.longitude,
        successCallback: function () {
            // finally, search the assets around your location
            searchWoosmapApiAroundLocation(latitude, longitude);
        }
    })
}

function errorCallback(error) {
    console.log(error.code)
}

Other Use Cases

You are able to contribute in many other instances like posting the user billing position or a shipping position. Please refer to the API Reference for an exhaustive list of all the ways such contributing could be posted.

Privacy Requirements

Woosmap takes privacy very seriously. In order to be compliant with standard reglementation on data privacy, a website using Woosmap Recommendation must add to its privacy policy the following mention: