• Resolved Anonymous User 20698748

    (@anonymized-20698748)


    I’m using statusCake for uptime monitoring of my website and GTmetrix for page speed monitoring. statusCake is using StatusCake_Pagespeed_Indev as user agend and GTmetrix appends GTmetrix at the end of its user agent string.

    Is there a way to exclude those user agents from Koko Analytics?

Viewing 3 replies - 1 through 3 (of 3 total)
  • 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.

    Plugin Author Danny van Kooten

    (@dvankooten)

    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!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Filtering out specific User Agents’ is closed to new replies.