acnil cookies Google A nalytics

resolved (19 posts) (2 voices)

  1. serenitis
    Member

    Hello,

    I need to integrate on top of my site this it is about a new legislation for cookies. Here is an example

    I tried to put this code in general, with the google analytics I tried to put this code in general, with the code google analytics , but it does not work. how I can do this is very important.

    <script type='text/javascript'>
        // Remplacez la valeur UA-XXXXXX-Y par l'identifiant analytics de votre site.
        gaProperty = 'UA-50412905-1';
     
        // Disables tracking if the cookie opt-out already.
     
        var disableStr = 'ga-disable-' + gaProperty;
     
        if (document.cookie.indexOf('hasConsent=false') > -1) {
        window[disableStr] = true;
        }
        //This function returns the expiry date of the cookie consent
     
        function getCookieExpireDate() {
         var cookieTimeout = 34214400000;// The number of milliseconds that are 13 months 
         var date = new Date();
        date.setTime(date.getTime()+cookieTimeout);
        var expires = "; expires="+date.toGMTString();
        return expires;
        }
     
        // This function is called to display the request for consent
        function askConsent(){
            var bodytag = document.getElementsByTagName('body')[0];
            var div = document.createElement('div');
            div.setAttribute('id','cookie-banner');
            div.setAttribute('width','70%');
            // Le code HTML de la demande de consentement
            // Vous pouvez modifier le contenu ainsi que le style
              
         div.innerHTML =  '<div style="background-color: #fffacd;color: #000;float: left;text-align: center;width: 100%;">Ce site utilise Google Analytics.\
            By continuing to browse, you authorize us to set cookies for the purpose of \
    \ 's audience measurement. To oppose it, click \
            ici.</div><div style="clear:none;"></div>';      
            bodytag.insertBefore(div,bodytag.firstChild); // Ajoute la bannière juste au début de la page
            document.getElementsByTagName('body')[0].className+=' cookiebanner';             
        }
               
               
        // Returns the string corresponding to name = value
        function getCookie(NomDuCookie)  {
            if (document.cookie.length > 0) {       
                begin = document.cookie.indexOf(NomDuCookie+"=");
                if (begin != -1)  {
                    begin += NomDuCookie.length+1;
                    end = document.cookie.indexOf(";", begin);
                    if (end == -1) end = document.cookie.length;
                    return unescape(document.cookie.substring(begin, end));
                }
             }
            return null;
        }
            
        // Delete cookies function  
        function delCookie(name )   {
            path = ";path=" + "/";
            domain = ";domain=" + "."+document.location.hostname;
            var expiration = "Thu, 01-Jan-1970 00:00:01 GMT";      
            document.cookie = name + "=" + path + domain + ";expires=" + expiration;
        }
           
        // Clears all types of cookies used by Google Analytics   
        function deleteAnalyticsCookies() {
            var cookieNames = ["__utma","__utmb","__utmc","__utmz","_ga"]
            for (var i=0; i<cookieNames.length; i++)
                delCookie(cookieNames[i])
        }
            
        // La fonction d'opt-out  
        function gaOptout() {
            document.cookie = disableStr + '=true;'+ getCookieExpireDate() +' ; path=/';      
            document.cookie = 'hasConsent=false;'+ getCookieExpireDate() +' ; path=/';
            var div = document.getElementById('cookie-banner');
            // Ci dessous le code de la bannière affichée une fois que l'utilisateur s'est opposé au dépôt
            // Vous pouvez modifier le contenu et le style
            if ( div!= null ) div.innerHTML = '<div style="background-color:#ffffff"> Vous vous êtes opposé \
            au dépôt de cookies de mesures d\'audience dans votre navigateur </div>'
            window[disableStr] = true;
            deleteAnalyticsCookies();
        }
     
     
     
        //This piece of code checks that the consent has not been obtained before displaying
    / / Banner
        var consentCookie =  getCookie('hasConsent');
        if (!consentCookie) {//L'utilisateur n'a pas encore de cookie de consentement
         var referrer_host = document.referrer.split('/')[2];
           if ( referrer_host != document.location.hostname ) { //si il vient d'un autre site
           //on désactive le tracking et on affiche la demande de consentement           
             window[disableStr] = true;
             window[disableStr] = true;
             window.onload = askConsent;
           } else { //sinon on lui dépose un cookie
              document.cookie = 'hasConsent=true; '+ getCookieExpireDate() +' ; path=/';
           }
        }
    </script>

    thank you

    Attachments

    1. acnil.jpg (31.7 KB, 0 downloads) 3 years old
    Posted 3 years ago #
  2. Elliott
    Support

    Hello serenitis,

    It's a script so can put it in Dashboard -> your theme -> General Settings -> Additional Headers.

    Posted 3 years ago #
  3. serenitis
    Member

    Is this script will be placed before the Google Analytics code? because it's the way he has placed.

    I do not understand this : Link to the mechanism of rejecting cookies analytics
    You still have to show the link to the opposition mechanism in the "learn more" describing the cookies used on your site. This link is valid for you to use Google Analytics or Universal Analytics.
    Click here to oppose cookies audience measurement Google

    Is it necessary that I create another page which itself must not use cookies?

    Thank you for your help

    Posted 3 years ago #
  4. serenitis
    Member

    Sorry I do not want to put a link. that is related to this party of code : "javascript:gaOptout()"

    Posted 3 years ago #
  5. Elliott
    Support

    Is this a plugin your using?

    Posted 3 years ago #
  6. serenitis
    Member

    not plugin, it's just a code script. I need to add code before code google and give visitors the opportunity to not have google analytics tracking cookies on their computer and that they must click a link with the code "" javascript: gaOptout () ".

    Posted 3 years ago #
  7. Elliott
    Support

    I would try using the full google analytics code that it gives you when you sign up for google analytics and place that bit in front of it.

    Posted 3 years ago #
  8. serenitis
    Member

    I tried to place the code before the code given by google in Dashboard -> your theme -> General Settings ->google analytics . But d'ont work. if i place this code in Dashboard -> your theme -> General Settings -> Additional Headers will the code be placed before the code google analytics ?

    Posted 3 years ago #
  9. Elliott
    Support

    If you place it inside the regular code that anaylytics gives you then I assume so.

    Posted 3 years ago #
  10. serenitis
    Member

    Hello,

    I put this code in its entirety in Dashboard -> your theme -> General Settings ->google analytics, but the Bandau does not appear on the banner as in the example of picture.
    How can I to show this band ?
    Here is my site: http://www.voyance-tchat.net
    And the code javascript

    <script>
    // Remplacez la valeur UA-XXXXXX-Y par l'identifiant analytics de votre site.
    var gaProperty = 'UA-XXXXXX-Y';
    // Désactive le tracking si le cookie d'Opt-out existe déjà
    var disableStr = 'ga-disable-' + gaProperty;
    if (document.cookie.indexOf('hasConsent=false') > -1) window[disableStr] = true;
    //Cette fonction retourne la date d.expiration du cookie de consentement
    function getCookieExpireDate() {
      var cookieTimeout = 34214400000; // Le nombre de millisecondes que font 13 mois
      var date = new Date();
      date.setTime(date.getTime()+cookieTimeout);
      var expires = "; expires="+date.toGMTString();
      return expires;
    }
    // Cette fonction est appelée pour afficher la demande de consentement
    function askConsent(){
      var bodytag = document.getElementsByTagName('body')[0];
      var div = document.createElement('div');
      div.setAttribute('id','cookie-banner');
      div.style.width="50%";
      div.style.position="absolute";
      div.style.left="20%";
      // Le code HTML de la demande de consentement
      // Vous pouvez modifier le contenu ainsi que le style
      div.innerHTML =  '<div style="background-color:transparent;color:#ABD2F0">Ce site utilise Google Analytics.\
      En continuant à naviguer, vous nous autorisez à déposer des cookies à des fins de \
      mesure d\'audience. Vous pouvez vous opposer à ce dépôt ou ignorer ce message.</div>';         
      bodytag.insertBefore(div,bodytag.firstChild); // Ajoute la bannière juste au début de la page
      document.getElementsByTagName('body')[0].className+=' cookiebanner';             
    }     
    // Retourne la chaine de caractère correspondant à nom=valeur
    function getCookie(NomDuCookie)  {
      if (document.cookie.length > 0) {       
        var begin = document.cookie.indexOf(NomDuCookie+"=");
        if (begin != -1)  {
          begin += NomDuCookie.length+1;
          var end = document.cookie.indexOf(";", begin);
          if (end == -1) end = document.cookie.length;
          return unescape(document.cookie.substring(begin, end));
        }
      }
      return null;
    }
    // Fonction d'effacement des cookies  
    function delCookie(name)   {
      var path = ";path=" + "/";
      var domain = ";domain=" + "."+document.location.hostname;
      var expiration = "Thu, 01-Jan-1970 00:00:01 GMT";      
      document.cookie = name + "=" + path + domain + ";expires=" + expiration;
    }
    // Efface tous les types de cookies utilisés par Google Analytics   
    function deleteAnalyticsCookies() {
      var cookieNames = ["__utma","__utmb","__utmc","__utmz","_ga"]
      for (var i=0; i<cookieNames.length; i++) delCookie(cookieNames[i])
    }
    // La fonction d'opt-out  
    function gaOptout() {
      document.cookie = disableStr + '=true;'+ getCookieExpireDate() +' ; path=/';      
      document.cookie = 'hasConsent=false;'+ getCookieExpireDate() +' ; path=/';
      var div = document.getElementById('cookie-banner');
      // Ci dessous le code de la bannière affichée une fois que l'utilisateur s'est opposé au dépôt
      // Vous pouvez modifier le contenu et le style
      if ( div!= null ) div.innerHTML = '<div style="background-color:#ABD2F0"> Vous vous êtes opposé \
      au dépôt de cookies de mesures d\'audience dans votre navigateur.</div>'
      window[disableStr] = true;
      deleteAnalyticsCookies();
    }
    function gaOptIn() {
      document.cookie = 'hasConsent=true; '+ getCookieExpireDate() +' ; path=/';
    }
    //Ce bout de code vérifie que le consentement n'a pas déjà été obtenu avant d'afficher la bannière
    var consentCookie = getCookie('hasConsent');
    //L'utilisateur n'a pas encore de cookie de consentement
    if (!consentCookie) askConsent()
    // tag universal analytics
    (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', gaProperty , 'auto'); // Créer le tracker.
    ga('require', 'linkid', 'linkid.js');
    ga('send', 'pageview'); // Envoyer l'information qu'une page a été visitée.
    </script>
    Thanks

    Posted 3 years ago #
  11. Elliott
    Support

    I do not know. It would be best to contact google analytics support.

    Posted 3 years ago #
  12. serenitis
    Member

    Hello,

    I tried this with css but it's ugly. would have the background to be at the very top

    // Le code HTML de la demande de consentement
      // Vous pouvez modifier le contenu ainsi que le style
     div.innerHTML =  '<div style="background-color: #1E45E2; top: 0; color: #000;float: left;text-align: center;width: 100%">Ce site utilise Google Analytics.\
      En continuant à naviguer, vous nous autorisez à déposer des cookies à des fins de \
      mesure d\'audience. Vous pouvez vous opposer à ce dépôt ou ignorer ce message.</div>';         
      bodytag.insertBefore(div,bodytag.firstChild); // Ajoute la bannière juste au début de la page
      document.getElementsByTagName('body')[0].className+=' cookiebanner'; 
                
    and the css for header : padding-top: 15px

    look look what happens

    Attachments

    1. acnil_google_analytics_result.jpg (76.7 KB, 0 downloads) 3 years old
    Posted 3 years ago #
  13. serenitis
    Member

    i'm used extra_header to add text and I have tried to put this css #header_extras { top: 0px !important; }but not work. i want the extra header in the top. How i can make this ?

    Attachments

    1. cookies.jpg (53.5 KB, 0 downloads) 3 years old
    Posted 3 years ago #
  14. Elliott
    Support

    Send us a link.

    Posted 3 years ago #
  15. serenitis
    Member

    As you can see the text is not at the top and I can not go down the logo with css #logo{top:35px ! important;} and css for extra header css #header_extras { top: 0px; height:25px !important; }

    My site http://www.voyance-tchat.net/

    Posted 3 years ago #
  16. Elliott
    Support

    See here, http://mysitemyway.com/docs/index.php/Customizing_the_Header, you can use a negative value for the top option to move it up even further.

    Posted 3 years ago #
  17. serenitis
    Member

    I finally also ,adding css for extras header text.

    Now there is another problem on all my pages sidebar normally are all right at the bottom of page.
    I do not understand what is happening. Look my site http://www.voyance-tchat.net/voyante-par-telephone/

    Posted 3 years ago #
  18. Elliott
    Support

    Let's try the following,

    1. Deactivate all plugins.

    2. Completely delete the theme before downloading / uploading a fresh copy.

    Posted 3 years ago #
  19. serenitis
    Member

    Finally here works I change the code to google. I think itis on account of css position: absolute.

    thank you

    Posted 3 years ago #

Reply

You must log in to post.

Construct WordPress Theme
Construct wordpress theme
Myriad WordPress Theme
Myriad wordpress theme
Method WordPress Theme
Method wordpress theme
Fusion WordPress Theme
Fusion wordpress theme
Elegance WordPress Theme
Elegance wordpress theme
Echelon WordPress Theme
Echelon wordpress theme
Dejavu WordPress Theme
Dejavu wordpress theme
Modular WordPress Theme
Modular wordpress theme