Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #30895

    babouz44
    Participant

    Hi,
    I would like to know if there is somthing in jquery, like the php fonction,
    if ( function_exists('cn_cookies_accepted') && cn_cookies_accepted() ) {}
    to know the states of cookie acceptance ?
    I would like to open up a lightbox after cookies were accepted…
    Sincerely
    Boris

    #30911

    babouz44
    Participant

    Hello,
    Well I tried to used the only one solution I found in this post here but unfortunately it doesnt works for me…

    If someone can help on this it will be great :)
    Boris

    #30916

    Bartosz
    Keymaster

    You can do that very easilly as the plugin sets the body class to “cookies-accepted”. You can just use any of the jQuery methods like hasClass to check that. Or you can hook into setCookieNotice js event that’s being triggered when the cookies are accepted. You do this same way as you would do for “click”, “change” or any other events.

    #30955

    babouz44
    Participant

    Yes I already tryed to watch the class name which is on the body but it works only on page refresh…
    I think the second method is the only way. I need to hook on the setCookieNotice event, but unfortunately that is this method I don’t find how to do…

    #30956

    Bartosz
    Keymaster

    Just as you’d do with click:

    $(document).on('setCookieNotice', function() {
      // execute something here when cookies are accepted
    });
    #30957

    babouz44
    Participant

    Yes indeed it was easyer than I was thinking :)

    I also done a change to be more RGPD compliant. Google analytics tracking code are not set by default but is working as soon as cookies are accepted not only on page refresh. But I had to also check if the body had the class ‘cookie-accepted’ to get the code working allways if cookies were accepted.

    
    <script>
    enableGoogleAnalytics = function(event) {
    	//placer le code analytics ici
    	var IdAnalytics = 'XX-XXXXX-XX'; //modifier l'id ICI
    	(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
    	(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
    	m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    	})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
    	ga('create', IdAnalytics, 'auto');
    	ga('set', 'anonymizeIp', true);
    	ga('send', 'pageview');
    	//fin analytics
    }
    </script>
    <script>
    $(document).on('setCookieNotice', function(event) {
    	enableGoogleAnalytics();
    });
    $(document).ready(function($) {
    	if($('body').hasClass('cookies-accepted')){
    		enableGoogleAnalytics();
    	}
    });
    </script>  
    

    Thank you for your help Bartosz !

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.