Plugin Support
Lap
(@lapzor)
There is no way to do this yet, but I think it can fairly easily be added.
Koko already filters some user agents:
// do not track if user agent looks like a bot
if ((/bot|crawler|spider|crawling|seo|chrome-lighthouse|preview/i).test(navigator.userAgent)) {
return
}
And I’m sure Danny wouldn’t mind adding a filter to that list of agents so that you can append some yourself via a code snippet.
https://github.com/ibericode/koko-analytics/issues/170
Plugin Support
Lap
(@lapzor)
after thinking about it for another minute I’ve added to the request to suggestion to create a PHP filter that can return true or false to prevent Koko from loading completely via any possible PHP condition. That way it could be used for user agent, ip, referrer url and so much more.
Hello @dbauer9,
You can use the following code snippet to not load the tracking snippet if the User-Agent string contains either of your two values.
// This instructs Koko Analytics to not load the tracking script
// If the User-Agent contains either "StatusCake_Pagespeed_Indev" or "GTmetrix"
add_filter( 'koko_analytics_load_tracking_script', function() {
if ( isset( $_SERVER['HTTP_USER_AGENT'] ) ) {
if ( preg_match( '/StatusCake_Pagespeed_Indev|GTmetrix/', $_SERVER['HTTP_USER_AGENT'] ) ) {
return false;
}
}
return true;
});
`
I’ve also pushed the snippet to our sample code snippets repository here.
Hope that helps, good luck!