• Resolved reanimuotasis

    (@reanimuotasis)


    Hi Gaspar,
    I’m in need to make the third party cookies to be loaded automatically. If I leave it as it is, practically no user enables cookies and Google Analytics is just worthless.
    I have tried to use your functions.php script from other threads and it works but with a few big problems:

    first of all the cookies arent loaded on first page load. Just the moove_gdpr_popup cookie is set and only after the refresh all the scripts are loaded. So if the users opens the page, reads it and exits, my Analytics code will not detect that.

    The second problem is that cookie notice at the footer of the page is showing only the first time user loads page too. I think it should be showing till the user accepts or declines cookies. After that just show the settings button.

    Third problem is that decline setting doesnt stick. If user opt-out of cookies, the page reloads, the scripts arent loaded, but the moove_gdpr_popup is setup again and after next refresh everything loads again. So probably the cookie should be set to save declined state.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter reanimuotasis

    (@reanimuotasis)

    I have solved my issue.

    In my functions.php file I have inserted this code:

    function gdpr_js_extension() {
    	if (!isset($_COOKIE['cookie-helper']) && !isset($_COOKIE['moove_gdpr_popup'])) {
    		setcookie("moove_gdpr_popup", '{"strict":"1","thirdparty":"1","advanced":"0"}', strtotime("+365 days"), '/');
    		$_COOKIE['moove_gdpr_popup'] = '{"strict":"1","thirdparty":"1","advanced":"0"}';
    		setcookie("cookie-helper", 1, strtotime("+365 days"), '/');
    	}
    }
    add_action( 'init', 'gdpr_js_extension', 100 );

    It creates plugin cookie manually for initial load and creates additional cookie which is used to check if the plugin cookie should be created or not.

    Now I can check if third party cookies are enabled with code:

    <?php if (isset($_COOKIE['moove_gdpr_popup']) && json_decode(stripslashes($_COOKIE['moove_gdpr_popup']))->thirdparty == 1): ?>
      <!--YOUR TRACKING CODE -->
    <?php endif; ?>

    In your header insert this snippet and include all the tracking codes inside.

    Also I have added the js code. It shows the cookie bar and hides settings button on the initial load.

    if (document.cookie.indexOf("moove_gdpr_popup") == 0) {
            $("#moove_gdpr_cookie_info_bar").removeClass("moove-gdpr-info-bar-hidden");
            $("#moove_gdpr_save_popup_settings_button").hide();
    }

    Hi @reanimuotasis

    I have a problem with this plugin not inserting my GA snippet into the header.php as it is supposed to, so as I have a child theme setup, I have copied my parent theme header.php to my child theme reflecting the same structure.

    I understand the first and second code sections and where they should be placed but where do you place the last third section of code?

    Any pointer much appreciated.

    Thanks in advance.

    Andrew

    Hi @reanimuotasis

    Where did you add the js?- I can’t seem to get the bar to appear on initial load

    Thanks

    • This reply was modified 6 years, 8 months ago by gerbull001. Reason: Simplified
    Thread Starter reanimuotasis

    (@reanimuotasis)

    You can insert into your main js file or you can add inline code to you header/footer between <script> tags

    Plugin Author Moove Agency

    (@mooveagency)

    Hi there,

    Thanks for your comments on this. The plugin will inject the scripts using javascript AJAX and because of this it’s not visible in the view-source of your page. You can use the developer console to check the loaded scripts. Loading the scripts with javascript we can prevent the caching issues, sometimes the PHP cookie checking will be cached by server and it doesn’t work as intended.

    I hope this makes sense.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Auto accept and decline cookies’ is closed to new replies.