Skip to content

Instantly share code, notes, and snippets.

@fblundun
Created November 20, 2015 09:10
Show Gist options
  • Save fblundun/ff605ac72fdece1513ab to your computer and use it in GitHub Desktop.
Save fblundun/ff605ac72fdece1513ab to your computer and use it in GitHub Desktop.
Manually sending geolocation events
if (!geolocationContextAdded && navigatorAlias.geolocation && navigatorAlias.geolocation.getCurrentPosition) {
navigator.geolocation.getCurrentPosition(function (position) {
var coords = position.coords;
var geolocationContext = {
schema: 'iglu:com.snowplowanalytics.snowplow/geolocation_context/jsonschema/1-1-0',
data: {
latitude: coords.latitude,
longitude: coords.longitude,
latitudeLongitudeAccuracy: coords.accuracy,
altitude: coords.altitude,
altitudeAccuracy: coords.altitudeAccuracy,
bearing: coords.heading,
speed: coords.speed,
timestamp: position.timestamp
}
};
window.snowplow('trackStructEvent', 'geolocation', 'geolocation_added', null, null, null, [geolocationContext]);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment