Block Unwanted Traffic
In this guide, we describe how to avoid bot traffic from affecting your tracking.
At its core, blocking unwanted traffic relies on the reserved event property $ignore to drop unwanted traffic. Anytime our ingestion API detects the $ignore property on an event, it drops that event from ingestion.
Exclude Bot Traffic From Javascript SDK
By default, the following bots are filtered out by the Mixpanel JavaScript library:
- Yahoo! Slurp
- bingbot/2.0
- Googlebot/2.1
- Baiduspider/2.0
- YandexBot/3.0
You can find the exact list on our GitHub
Any other bot hitting your site will affect your Mixpanel data. That being said, it’s possible to set up some code to filter out these users:
- Find the user agent information of the individual accessing the site.
- Look for the word “bot” anywhere in the user agent information.
- If you find “bot,” set the
$ignoreproperty totrue.
If you can, identify a common pattern in the bots to block them all in one shot by filtering out any interaction with your site that comes from a web framework that is not a consumer-facing browser. As an example, for GTM bots, this code would look like this:
var userAgentBotTest = navigator.userAgent;
mixpanel.register({"User Agent": userAgentBotTest});
if (/(Mozilla\/4.0)/i.test(userAgentBotTest)) {
mixpanel.register({"$ignore": true});
}If you implement this code, you will block all userAgents with “Mozilla/4.0” in the userAgent. This does include some older browsers, but modern browsers such as Chrome, Safari, and Firefox will never include this in their userAgent strings. See a common list of bot userAgents and common bot browsers.
If this does not work, you can start tracking this userAgent going forward so you can find the common pattern among all of the bots crawling your site.
Note: $ignore must have a string or at least be set to true, or else the event will fire. For example, if I have '$ignore': '', the event will still fire since it’s an empty string. '$ignore': false will also fire the event.
Remove Bot Traffic Historically
Events in Mixpanel are immutable, which means they cannot be removed. However, they can be filtered out. If there are some events that have been sent in with bots and you can identify those events based on some property value (eg: the device type or location), we recommend creating a custom event that applies that filter. You can also hide the original event. That way, when you use the custom event, all bot traffic will automatically be filtered out.
Block Internal or IP-Based Traffic
The same $ignore approach used above for bot traffic can also be applied to filter out internal traffic. (ex: events generated by your own team during testing, QA, or traffic originating from specific IP addresses you own).
Filtering by IP Address
If you want to exclude traffic from known IP addresses (such as your office network or a VPN), you can resolve the user’s IP and conditionally set $ignore. Since the browser doesn’t expose the client IP directly, you’ll need a lightweight server-side endpoint or third-party service to retrieve it:
fetch("https://api.ipify.org?format=json")
.then((res) => res.json())
.then((data) => {
const blockedIPs = ["203.0.113.50", "198.51.100.27"]; // your internal IPs
if (blockedIPs.includes(data.ip)) {
mixpanel.register({ $ignore: true });
}
});Filtering by Internal Email Domain
If your team members are identified in Mixpanel, you can also suppress events based on an internal email domain or user property:
//After identifying the user and knowing their email
var userEmail = getCurrentUserEmail(); // your own helper
if (/@yourcompany\.com$/.test(userEmail)) {
mixpanel.register({ $ignore: true });
}Server-Side Filtering
If you are sending events from a server-side method, you can apply the same logic before the event is sent. Attach $ignore: true as an event property whenever the request originates from an internal IP range or an internal service account:
import ipaddress
internal_networks = [
ipaddress.ip_network("10.0.0.0/8"),
ipaddress.ip_network("192.168.1.0/24"),
]
def is_internal(ip):
addr = ipaddress.ip_address(ip)
return any(addr in network for network in internal_networks)
if is_internal(request_ip):
mp.track(user_id, "Page View", {"$ignore": True})As with bot filtering, remember that $ignore must be set to true (or a non-empty string) to suppress the event. An empty string or false will not prevent the event from being recorded. If internal traffic has already been recorded, you can retroactively filter it out using a custom event as described in Remove Bot Traffic Historically.
Was this page useful?