Exclude Bot Activity (Web/JavaScript)

By default, the following bots are filtered out by the Mixpanel JavaScript library:

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:

  1. Find the user agent information of the individual accessing the site.
  2. Look for the word “bot” anywhere in the user agent information.
  3. If you find “bot,” set the $ignore property to true.

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.


$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.

How do I remove bot data from my project?

Mixpanel data is write once, read forever, which means once a datapoint is written to a project, there isn't a way to selectively remove it.

However, there are a few other options:

Related topics

Is this article helpful?
1 out of 4 found this helpful



Article is closed for comments.