Geolocation context with manual opt-in?

I’m looking for a way to track geolocation automatically with the Javascript tracker, but I do not want Snowplow to ask my users for permissions as we do that separately.

My use case is this:
I have a location search feature on my site, where a user can choose to see content close to her current location. When this feature is used, permission to the device location is given. I want the javascript tracker to attach the geolocation context whenever the device location is available, but since not all users will use this feature I do not want to ask all users to give me access to their location.

Is it possible to achieve this with the javascript tracker?

If not - how do I go around attaching geolocation context to events such as link clicks and form submissions (which are tracked automatically by the javascript tracker) manually?


After looking at the Javascript tracker code, more specifically here:

I came up with the solution to do:
‘snowplow_name_here(“enableGeolocationContext”)’ whenever a user has already given me access to her device location.

1 Like

Thanks for posting back with your answer @patrik! That’s super-helpful for the community.

Sure, no problem. Managed to find answers to pretty much all my questions here so why not help out a bit as well, right?

I can actually elaborate a bit on my own answer above. The solution there only works for one page, since the JS tracker is recreated on each new page load. Therefore, on the next page we would again disable the geolocation context…

Luckily - we use GTM, which allows us to add a variable to the dataLayer indicating whether the user has already granted location access. Then when creating the JS tracker, we use this variable to control whether to enable the geolocation context or not, something like this:

snowplow_name_here(“newTracker”, … , contexts:{geolocation: {{user_has_granted_location_access}} }

To maximize tracking of the geolocation context without having Snowplow asking for access one therefore has to do these 2 things:

  1. Enable geolocation context manually when the user grants location access
  2. On every page, enable geolocation context if the user has already granted location access.

Hope this is helpful for someone else as well!