Skip to content

Instantly share code, notes, and snippets.

@ak--47
Created March 20, 2024 01:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ak--47/e79f27aa7464d3b2c078877d6f5d09ab to your computer and use it in GitHub Desktop.
Save ak--47/e79f27aa7464d3b2c078877d6f5d09ab to your computer and use it in GitHub Desktop.
blocking user agents mixpanel
const express = require('express');
const app = express();
const Mixpanel = require('mixpanel')
const mixpanel = mixpanel.init('your token')
var BLOCKED_UA_STRS = [
'googlebot',
'googleweblight',
'mediapartners-google',
'storebot-google' //etc... list can be expanded as necessary.
];
app.use((req, res, next) => {
const userAgent = req.headers['user-agent'].toLowerCase();
for (let blockedUA of BLOCKED_UA_STRS) {
if (!userAgent.includes(blockedUA)) {
//user is not a bot
mixpanel.track('foo')
}
}
next();
});
const PORT = 3000;
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment