Support » Plugin: Cookie Notice for GDPR » Cookie notice and MonsterInsights

Viewing 7 replies - 1 through 7 (of 7 total)
  • Anyone able to help?

    I realize this might be the wrong forum to post the answer since most of it is related to the MonsterInsights plugin, but since the thread already exists this seemed the easiest thing to do. Feel free to delete the post, if you find it irrelevant.

    Since I had trouble finding a solution online I will tell you what I did, to solve this. However I kinda did it in another way, where the cookies will be created only if the user accepts cookies. Pressing “No” or not doing anything the analytics cookies will not exist.

    You need to access the source code for MonsterInsights. In wordpress achieve this by navigating to Plugins -> Editor. Then set the plugin to edit as the MonsterInsights plugin and press select. In “Includes -> Frontend -> Tracking” there is a file called class-tracking-analytics.php open it and find the line starting with (function(i,s,o,g,r,a,m) [around line 200 for me]. All you need to do is to insert this code on the line above the function <?php if ( function_exists('cn_cookies_accepted') && cn_cookies_accepted() ) { ?> and this on the line below the function <?php } ?>

    MonsterInsights is compatible now with Cookie Notice using the EU Compliance Addon (available with any of the paid plans).

    nix255

    (@nix255)

    It’s rather annoying that something as important as this requires a paid plan from monster insights. I’m afraid for me that means goodbye to monster insights as it is easier to just add the analytics code to the Cookie Notice scripts box. So no, it isn’t really compatible at all.

    JohnBoone

    (@johnboone)

    The following snippet will make Monsterinsights plugin aware of the choice users made through the Cookie Notice plugin. Just add it to your functions.php file.

    add_action( 'init', 'set_monsterinsight_cookie_according_to_cookie_notice' );
    
    function set_monsterinsight_cookie_according_to_cookie_notice() {
        if ( function_exists( 'cn_cookies_accepted' ) && function_exists('monsterinsights_get_ua')) {
            if ( cn_cookies_accepted() ) {
                setCookie( 'ga-disable-'.monsterinsights_get_ua(), 'false' );
    	}else{
    	     setCookie( 'ga-disable-'.monsterinsights_get_ua(), 'true' );
    	}
        }
    }
    csci-fi

    (@csci-fi)

    @johnboone,

    I tried your solution and it works perfectly as long as I accept the Cookie Notice on the homepage of my site. However, if I accept the notice on another page GA doesn’t start tracking unless I navigate back to the homepage. Once I have hit the homepage it will track me to any other page. Any idea?

    csci-fi

    (@csci-fi)

    @joped,

    Your solution worked, but I wish I could get John Boone’s functions.php solution to work since it would prevent the issues with plugin updates that your solution will experience.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Cookie notice and MonsterInsights’ is closed to new replies.