Geo-Tracking in Usermaven
Why Geo-Tracking?
Geo-tracking allows businesses to analyze user data based on geographic locations. This can be crucial for various reasons, such as compliance with regional regulations, marketing strategies, and understanding user behavior across different locations. However, there might be scenarios where you need to exclude data from certain regions from being tracked and analyzed.
Methods to block analytics from specific countries
Usermaven provides two primary methods to block analytics from specific countries:
- Implementing a Geo-Tracking script on your end
- Blocking traffic via IP ranges in Usermaven
1. Implementing a Geo-Tracking script on your end
You can implement a geo-tracking script that triggers the Usermaven tracking pixel only in desired locations. This method provides flexibility and control over where your analytics data is collected. Here's how you can do it:
- Implementing a geo-tracking script may vary depending on the Content Management System (CMS) you are using.
- Use a geo-tracking service such as MaxMind GeoIP2, IP2Location, or any other preferred service.
- Use the chosen service to retrieve the geographic location data of your users.
- Based on the retrieved location data, conditionally trigger the Usermaven tracking pixel only for allowed locations.
Here is a basic example of how you might implement this using JavaScript. Here US is being used as an example:
// Sample script using an external geo-location service API
fetch('https://your-geo-location-service-api')
.then(response => response.json())
.then(data => {
// Check if the user is not from the USA
if (data.country !== 'United States') {
// Trigger Usermaven tracking pixel
(function () {
window.usermaven = window.usermaven || (function () { (window.usermavenQ = window.usermavenQ || []).push(arguments); })
var t = document.createElement('script'),
s = document.getElementsByTagName('script')[0];
t.defer = true;
t.id = 'um-tracker';
t.setAttribute('data-tracking-host', "https://um.example.com")
t.setAttribute('data-key', 'UMJoAieDi5');
t.setAttribute('data-autocapture', 'true');
t.setAttribute('data-randomize-url','true');
t.src = 'https://um.example.com/lib.js';
s.parentNode.insertBefore(t, s);
})();
usermaven('track', 'pageview');
}
})
.catch(error => console.error('Error fetching geo-location data:', error));
Add this script to the header section of your website or the appropriate section in your CMS.
Make sure the geo-location service you use is reliable and provides up-to-date data. It is also recommended to implement error handling to manage cases where the geo-location service might fail.
2. Blocking traffic via IP ranges in Usermaven
You can block traffic from a specific country by blocking the full range of IPs from that country. Usermaven allows you to add these IP ranges in the Workspace settings. Here's how you can do this:
- Get the list of IP ranges for the desired country. For example, you can use IP2Location's list of United States IP ranges: IP Ranges for USA (opens in a new tab).
- Login to your Usermaven account and click on Workspace Settings and Miscellaneous.
- Scroll to the bottom of the page to find the
Exclude internal traffic and users
section. Enable this option if it is not already enabled. - To add IP Addresses, click
Add Rule
and enter the IP ranges obtained from your preferred geo-tracking site. - Once done, click on the save button to save the changes.
Additional methods to exclude traffic
In case you only wish to exclude internal traffic and users, Usermaven provides a Chrome Extension that makes it super easy for you. This method is particularly useful for excluding traffic from team members or specific devices. To do so:
- Install the
Usermaven Traffic Exclusion
extension from the Chrome Web Store. - Once installed, activate the extension.
- Next, go to your website, click on the extension icon, and enable traffic exclusion.
Adding rules to exclude traffic and users
Usermaven also allows you to set up specific rules to filter out unwanted traffic based on email addresses, IP addresses, or hostnames. To do so, in the Exclude internal traffic and users
section, click on Add Rule
and specify the conditions for exclusion, such as:
Email contains @yourdomain.com
to exclude traffic from company email addresses.Hostname contains localhost
to exclude local development traffic.
Conclusion
Geo-tracking is vital for businesses operating in multiple regions and needing to comply with various regulations or optimize their marketing strategies. Usermaven provides flexible and powerful options to manage geo-tracking and exclude traffic from specific countries. By following the methods outlined in this document, you can ensure that your analytics data is accurate and aligned with your business needs.