Track timezone and geolocation on web
Track users' timezone and geolocation with these configuration options.
Timezone
Since version 4 of the JavaScript tracker, the tracker automatically captures the user's timezone. It populates the os_timezone atomic field. This feature uses the Intl.DateTimeFormat function in modern browsers.
If you're using an older version of the tracker, or your users use older browsers, use the timezone plugin to capture timezone information. It uses the jstimezonedetect library to determine the user's timezone and populate the os_timezone field.
The timezone property is automatically tracked.
Install plugin
- JavaScript (tag)
- Browser (npm)
| Tracker Distribution | Included |
|---|---|
sp.js | ❌ |
sp.lite.js | ❌ |
Download:
| Download from GitHub Releases (Recommended) | Github Releases (plugins.umd.zip) |
| Available on jsDelivr | jsDelivr (latest) |
| Available on unpkg | unpkg (latest) |
Note: The links to the CDNs above point to the current latest version. You should pin to a specific version when integrating this plugin on your website if you are using a third party CDN in production.
window.snowplow('addPlugin',
"https://cdn.jsdelivr.net/npm/@snowplow/browser-plugin-timezone@latest/dist/index.umd.min.js",
["snowplowTimezone", "TimezonePlugin"]
);
npm install @snowplow/browser-plugin-timezoneyarn add @snowplow/browser-plugin-timezonepnpm add @snowplow/browser-plugin-timezone
import { newTracker, trackPageView } from '@snowplow/browser-tracker';
import { TimezonePlugin } from '@snowplow/browser-plugin-timezone';
newTracker('sp1', '{{collector_url}}', {
appId: 'my-app-id',
plugins: [ TimezonePlugin() ],
});
Once configured, all subsequent events will contain this property.
Geolocation
If this plugin is enabled, the tracker will attempt to create a entity from the visitor's geolocation information.
If the visitor hasn't already given or denied the website permission to use their geolocation information, a prompt will appear. If they give permission, then all events from that moment on will include their geolocation information, as a context entity.
If the geolocation entity isn't enabled at tracker initialization, you can enable it at a later time by calling enableGeolocationContext. This is useful if you have other areas of your site where you require requesting geolocation access, as you can defer enabling this on your Snowplow events until you have permission to read the users geolocation for your other use case.
For more information on the geolocation API, see the specification.
Check out the geolocation tracking overview for the entity schema.
The geolocation entity is automatically tracked once configured.
Install plugin
- JavaScript (tag)
- Browser (npm)
| Tracker Distribution | Included |
|---|---|
sp.js | ❌ |
sp.lite.js | ❌ |
This plugin was included in sp.js in version 3, but removed from the default bundle in version 4.
Download:
| Download from GitHub Releases (Recommended) | Github Releases (plugins.umd.zip) |
| Available on jsDelivr | jsDelivr (latest) |
| Available on unpkg | unpkg (latest) |
Note: The links to the CDNs above point to the current latest version. You should pin to a specific version when integrating this plugin on your website if you are using a third party CDN in production.
To enable after initialization:
window.snowplow('addPlugin',
"https://cdn.jsdelivr.net/npm/@snowplow/browser-plugin-geolocation@latest/dist/index.umd.min.js",
["snowplowGeolocation", "GeolocationPlugin"],
);
// Enable when appropriate e.g. after user consents
// This prompts the browser for location permission
window.snowplow('enableGeolocationContext');
To enable at initialization:
window.snowplow('addPlugin',
"https://cdn.jsdelivr.net/npm/@snowplow/browser-plugin-geolocation@latest/dist/index.umd.min.js",
["snowplowGeolocation", "GeolocationPlugin"],
[true] // Prompts for permission immediately
);
npm install @snowplow/browser-plugin-geolocationyarn add @snowplow/browser-plugin-geolocationpnpm add @snowplow/browser-plugin-geolocation
To enable after initialization:
import { newTracker, trackPageView } from '@snowplow/browser-tracker';
import { GeolocationPlugin, enableGeolocationContext } from '@snowplow/browser-plugin-geolocation';
newTracker('sp1', '{{collector_url}}', {
appId: 'my-app-id',
plugins: [ GeolocationPlugin() ], // Inactive by default
});
// Enable when appropriate e.g. after user consents
// This prompts the browser for location permission
enableGeolocationContext();
To enable at initialization:
import { newTracker, trackPageView } from '@snowplow/browser-tracker';
import { GeolocationPlugin } from '@snowplow/browser-plugin-geolocation';
newTracker('sp1', '{{collector_url}}', {
appId: 'my-app-id',
plugins: [ GeolocationPlugin(true) ], // Prompts for permission immediately
});
There's no API to turn off geolocation tracking once enabled.
If you have multiple tracker instances on your site, you can choose to enable geolocation tracking on a per-tracker basis. Provide a list of tracker namespaces to the enableGeolocationContext function.
- JavaScript (tag)
- Browser (npm)
window.snowplow('enableGeolocationContext', ['sp1']);
enableGeolocationContext(['sp1']);