Skip to content

Instantly share code, notes, and snippets.

@dcvogi
Last active December 7, 2017 10:38
Show Gist options
  • Save dcvogi/e7854daa0c0aec2fec7a4141d8898fb5 to your computer and use it in GitHub Desktop.
Save dcvogi/e7854daa0c0aec2fec7a4141d8898fb5 to your computer and use it in GitHub Desktop.
(function trackGeolocation(){
if (!window.navigator.geolocation) {
ga('send', 'event', 'browser support features', 'geolocation information', 'geolocation api is not supported');
return;
}
function geoSuccess(position) {
ga('send', 'event', 'geolocation', 'position', position.coords.latitude + ',' + position.coords.longitude);
}
function geoError(positionError) {
ga('send', 'event', 'geolocation', 'error', positionError.message);
}
navigator.geolocation.watchPosition(geoSuccess, geoError);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment