Données de vitesse absentes de Google Analytics avec mon script personnalisé

Discussion dans 'Google Analytics' créé par ortolojf, 27 Juillet 2018.

  1. ortolojf
    ortolojf WRInaute accro
    Inscrit:
    14 Août 2002
    Messages:
    2 799
    J'aime reçus:
    8
    Bonjour

    J'ai mis en place ce code Javascript il y a plusieurs mois , de manière à fournir à Google ( Analytics ), les données de fréquentation, sans avoir à mettre de cookie Analytics

    Le problème, est que Analytics me reporte les données de vitesse toutes nulles.

    Les autre rapports GA semblent correctes.

    Où est l'erreur ?

    En particulier, les UUID et Client_UUID sont-ils dépendants du visiteur ( dans mon cas ), ou bien aléatoires ?

    La théorie des UUID semble indiquer aléatoire, alors que je le calcule en fonction de l'ip, du serveur et du ndd.

    Merci de me dire comment obtenir correctement les données de vitesse.

    Amicalement.



    Code:
    
    <script>
        function sha1 (str) {
            function hex (value) {
                var s = (value >>> 0).toString(16)
                while (s.length < 8) s = '0' + s
                return s
            }
            function limit (n) {
                return n & 0xffffffff
            }
            function rotateLeft (n, s) {
                return (n << s) | (n >>> (32 - s))
            }
            var H0 = 0x67452301
            var H1 = 0xefcdab89
            var H2 = 0x98badcfe
            var H3 = 0x10325476
            var H4 = 0xc3d2e1f0
            var i, j
            var blockstart
            var W = new Array(80)
            var A, B, C, D, E
            var temp
            str = unescape(encodeURIComponent(str))
            str = str.split(/.*?/).map(function (s) {
                return s.charCodeAt(0)
            })
            var length = str.length
            var words = []
            for (i = 0; i < length - 3; i += 4) {
                j = str[i] << 24 | str[i + 1] << 16 | str[i + 2] << 8 | str[i + 3]
                words.push(j)
            }
            switch (length % 4) {
                case 0:
                    i = 0x80000000
                    break
                case 1:
                    i = str[length - 1] << 24 | 0x800000
                    break
                case 2:
                    i = str[length - 2] << 24 | str[length - 1] << 16 | 0x8000
                    break
                case 3:
                    i = str[length - 3] << 24 | str[length - 2] << 16 | str[length - 1] << 8 | 0x80
                    break
            }
            words.push(i)
            while ((words.length % 16) != 14) {
                words.push(0)
            }
            words.push(length >>> 29)
            words.push(limit(length << 3))
            for (blockstart = 0; blockstart < words.length; blockstart += 16) {
                for (i = 0; i < 16; i++) {
                    W[i] = words[blockstart + i]
                }
                for (i = 16; i < 80; i++) {
                    W[i] = rotateLeft(W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16], 1)
                }
                A = H0
                B = H1
                C = H2
                D = H3
                E = H4
                for (i = 0; i <= 19; i++) {
                    temp = limit(rotateLeft(A, 5) + ((B & C) | (~B & D)) + E + W[i] + 0x5a827999)
                    E = D
                    D = C
                    C = rotateLeft(B, 30)
                    B = A
                    A = temp
                }
                for (i = 20; i <= 39; i++) {
                    temp = limit(rotateLeft(A, 5) + (B ^ C ^ D) + E + W[i] + 0x6ed9eba1)
                    E = D
                    D = C
                    C = rotateLeft(B, 30)
                    B = A
                    A = temp
                }
                for (i = 40; i <= 59; i++) {
                    temp = limit(rotateLeft(A, 5) + ((B & C) | (B & D) | (C & D)) + E + W[i] + 0x8f1bbcdc)
                    E = D
                    D = C
                    C = rotateLeft(B, 30)
                    B = A
                    A = temp
                }
                for (i = 60; i <= 79; i++) {
                    temp = limit(rotateLeft(A, 5) + (B ^ C ^ D) + E + W[i] + 0xca62c1d6)
                    E = D
                    D = C
                    C = rotateLeft(B, 30)
                    B = A
                    A = temp
                }
                H0 = limit(H0 + A)
                H1 = limit(H1 + B)
                H2 = limit(H2 + C)
                H3 = limit(H3 + D)
                H4 = limit(H4 + E)
            }
            return hex(H0) + hex(H1) + hex(H2) + hex(H3) + hex(H4)
        }
        function hexdec (hexString) {
          //  discuss at: http://locutus.io/php/hexdec/
          // original by: Philippe Baumann
          //   example 1: hexdec('that')
          //   returns 1: 10
          //   example 2: hexdec('a0')
          //   returns 2: 160
          hexString = (hexString + '').replace(/[^a-f0-9]/gi, '')
          return parseInt(hexString, 16)
        }
        function chr (code) {
            return(String.fromCharCode(code));
        }
        function UUID(anon_id)
        {
            // Binary Value
            nstr = '';
            // Convert Namespace UUID to bits
            for(i = 0; i < anon_id.length; i+=2) {
                var nbre = (hexdec(anon_id.substr(i, 1))).toString(16) + (hexdec(anon_id.substr(i + 1, 1))).toString(16);
                nstr += chr(Number(nbre));
            }
            // Calculate hash value
            hash = sha1(nstr + anon_id);
            // 32 bits for "time_low"
            data_1 = hash.substr(0, 8);
            // 16 bits for "time_mid"
            data_2 = hash.substr(8, 4);
            // 16 bits for "time_hi_and_version",
            // four most significant bits holds version number 3
            tmp_data3 = (hexdec(hash.substr(12, 4)) & 0x0fff) | 0x4000;
            data3 = tmp_data3.toString(16).substr(0, 4);
            // 16 bits, 8 bits for "clk_seq_hi_res",
            // 8 bits for "clk_seq_low",
            // two most significant bits holds zero and one for variant DCE1.1
            tmp_data4 = (hexdec(hash.substr(16, 4)) & 0x3fff) | 0x8000;
            data4 = tmp_data4.toString(16).substr(0, 4);
            // 48 bits for "node"
            data5 = hash.substr(20, 12);
            result = data_1 + '-' + data_2 + '-' + data3 + '-' + data4 + '-' + data5;
            return(result);
        }
        function Utf8Encode(string) {
        regex = new RegExp("\r\n", 'g');
            string = string.replace(regex, "\n");
            var utftext = "";
            for (var n = 0; n < string.length; n++) {
                var c = string.charCodeAt(n);
                if (c < 128) {
                    utftext += String.fromCharCode(c);
                } else if((c > 127) && (c < 2048)) {
                    utftext += String.fromCharCode((c >> 6) | 192);
                    utftext += String.fromCharCode((c & 63) | 128);
                } else {
                    utftext += String.fromCharCode((c >> 12) | 224);
                    utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                    utftext += String.fromCharCode((c & 63) | 128);
                }
            }
            return utftext;
        };
        function crc32 (str) {
            str = Utf8Encode(str); 
            var table = "00000000 77073096 EE0E612C 990951BA 076DC419 706AF48F E963A535 9E6495A3 0EDB8832 79DCB8A4 E0D5E91E 97D2D988 09B64C2B 7EB17CBD E7B82D07 90BF1D91 1DB71064 6AB020F2 F3B97148 84BE41DE 1ADAD47D 6DDDE4EB F4D4B551 83D385C7 136C9856 646BA8C0 FD62F97A 8A65C9EC 14015C4F 63066CD9 FA0F3D63 8D080DF5 3B6E20C8 4C69105E D56041E4 A2677172 3C03E4D1 4B04D447 D20D85FD A50AB56B 35B5A8FA 42B2986C DBBBC9D6 ACBCF940 32D86CE3 45DF5C75 DCD60DCF ABD13D59 26D930AC 51DE003A C8D75180 BFD06116 21B4F4B5 56B3C423 CFBA9599 B8BDA50F 2802B89E 5F058808 C60CD9B2 B10BE924 2F6F7C87 58684C11 C1611DAB B6662D3D 76DC4190 01DB7106 98D220BC EFD5102A 71B18589 06B6B51F 9FBFE4A5 E8B8D433 7807C9A2 0F00F934 9609A88E E10E9818 7F6A0DBB 086D3D2D 91646C97 E6635C01 6B6B51F4 1C6C6162 856530D8 F262004E 6C0695ED 1B01A57B 8208F4C1 F50FC457 65B0D9C6 12B7E950 8BBEB8EA FCB9887C 62DD1DDF 15DA2D49 8CD37CF3 FBD44C65 4DB26158 3AB551CE A3BC0074 D4BB30E2 4ADFA541 3DD895D7 A4D1C46D D3D6F4FB 4369E96A 346ED9FC AD678846 DA60B8D0 44042D73 33031DE5 AA0A4C5F DD0D7CC9 5005713C 270241AA BE0B1010 C90C2086 5768B525 206F85B3 B966D409 CE61E49F 5EDEF90E 29D9C998 B0D09822 C7D7A8B4 59B33D17 2EB40D81 B7BD5C3B C0BA6CAD EDB88320 9ABFB3B6 03B6E20C 74B1D29A EAD54739 9DD277AF 04DB2615 73DC1683 E3630B12 94643B84 0D6D6A3E 7A6A5AA8 E40ECF0B 9309FF9D 0A00AE27 7D079EB1 F00F9344 8708A3D2 1E01F268 6906C2FE F762575D 806567CB 196C3671 6E6B06E7 FED41B76 89D32BE0 10DA7A5A 67DD4ACC F9B9DF6F 8EBEEFF9 17B7BE43 60B08ED5 D6D6A3E8 A1D1937E 38D8C2C4 4FDFF252 D1BB67F1 A6BC5767 3FB506DD 48B2364B D80D2BDA AF0A1B4C 36034AF6 41047A60 DF60EFC3 A867DF55 316E8EEF 4669BE79 CB61B38C BC66831A 256FD2A0 5268E236 CC0C7795 BB0B4703 220216B9 5505262F C5BA3BBE B2BD0B28 2BB45A92 5CB36A04 C2D7FFA7 B5D0CF31 2CD99E8B 5BDEAE1D 9B64C2B0 EC63F226 756AA39C 026D930A 9C0906A9 EB0E363F 72076785 05005713 95BF4A82 E2B87A14 7BB12BAE 0CB61B38 92D28E9B E5D5BE0D 7CDCEFB7 0BDBDF21 86D3D2D4 F1D4E242 68DDB3F8 1FDA836E 81BE16CD F6B9265B 6FB077E1 18B74777 88085AE6 FF0F6A70 66063BCA 11010B5C 8F659EFF F862AE69 616BFFD3 166CCF45 A00AE278 D70DD2EE 4E048354 3903B3C2 A7672661 D06016F7 4969474D 3E6E77DB AED16A4A D9D65ADC 40DF0B66 37D83BF0 A9BCAE53 DEBB9EC5 47B2CF7F 30B5FFE9 BDBDF21C CABAC28A 53B39330 24B4A3A6 BAD03605 CDD70693 54DE5729 23D967BF B3667A2E C4614AB8 5D681B02 2A6F2B94 B40BBE37 C30C8EA1 5A05DF1B 2D02EF8D";
            var crc = 0;
            var x = 0;
            var y = 0;
            crc = crc ^ (-1);
            for( var i = 0, iTop = str.length; i < iTop; i++ ) {
                y = ( crc ^ str.charCodeAt( i ) ) & 0xFF;
                x = "0x" + table.substr( y * 9, 8 );
                crc = ( crc >>> 8 ) ^ x;
            }
            return (crc ^ (-1)) >>> 0;
        };
        function Client_UUID(anon_id)
        {
            hash = sha1(anon_id);
            anon_id = sha1(hash);
            hashed = crc32(anon_id) + crc32(anon_id);
            var regex = new RegExp('^(0+)', 'g');
            var regex2 = new RegExp('^[0]+(.+)', 'g');
            if(regex.test(hashed))
            {
                var array_match = hashed.match(regex2);
                var regex3 = new RegExp(array_match[0] + '$', 'g');
                // Debut avec des zéro;
                var prefix = hashed.replace(regex3, '');
                var tmp_len = prefix.length;
                // Remplacement avec des chiffres différents de zéro.
                tmp_prefix = '';
                for(i = 0; i < tmp_len; i++)
                {
                    nbre = 1 + (i * 2) % 10;
                    tmp_prefix += nbre.toString(10);
                }
                tmp_prefix += hashed.replace(regex, '');
                hashed = tmp_prefix;
            }
            return hashed;
        }
        function user_agent()
        {
            var regex_space = new RegExp('[ ]+', 'g');
            var version = window.navigator.appVersion;
            var tmp_array_space = version.split(regex_space);
            var tmp_count = tmp_array_space.length;
            var avant_dernier_browser = tmp_array_space[tmp_count - 2];
            var dernier_browser = tmp_array_space[tmp_count - 1];
            var txt='';
            txt += window.navigator.appCodeName + ' ';
            txt += window.navigator.appName;
            txt += '/' + tmp_array_space[0];
            txt += ' ' + avant_dernier_browser + ' ' + dernier_browser;
            txt = window.navigator.userAgent;
            return(txt);
        }
        function http_post(url, data)
        {
            output_string = Array();
            for(index in data)
            {
                output_string.push(encodeURI(index) + '=' + encodeURI(data[index]));
            }
            var request = output_string.join('&');
            var xsr;
            xsr=null;
            xsr=createXsrObject();
            xsr.onreadystatechange = function()
            {
                if(xsr.readyState == 4)
                {
                    if((xsr.status == 200)||(xsr.status == 0))
                    {
                        var result = xsr.responseText;
                    }
                    else
                    {
                        console.log("Status de la réponse: %d (%s)", xsr.status, xsr.statusText);
                    }
                }
            }
            xsr.open("POST", encodeURI(url), true);
            xsr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
            xsr.send(request);
        }
        var user_agent = user_agent();
        function GA_data() {
            // Check for browser support
            if(!(window.performance && window.performance.timing)) {
                return;
            }
            var ip_addr = '78.194.232.180';    // Tracking ID / Property ID.
            if((ip_addr === false)||(ip_addr === '')) {
                return;
            }
            var tmp_dp = document.location.pathname;    // Page.
                var regex = new RegExp("(statistiques|contact)", 'g');
            if(regex.test(tmp_dp)) {
                return;
            }
            // Create an anonymous ID - we double hash with salt, GA won't who's who
            var server = 'www.pronostics-courses.fr164.132.56.180';
            var salt = sha1(server);
            var hash_const = sha1(ip_addr + salt);
            var hash_const2 = sha1(ip_addr);
            // Client ID
            var CID = UUID(hash_const);
            // User ID
            var UID = Client_UUID(hash_const2);
            var v = '1';        // Version.
            var tid = 'UA-2860929-2';    // Tracking ID / Property ID.
            var ds = 'gdpr_analytics';        // Data Source.
            var cid = CID;                // Anonymous Client ID.
            var uid = UID;                // Client ID.
            var uip = ip_addr;            // IP Override.
            var ua = Utf8Encode(user_agent);    // User Agent Override.
            var t = 'pageview';            // Pageview hit type.
            var dr = Utf8Encode(document.referrer);    // Document referrer.
            var ul = window.navigator.language;    // User Language.
            var dh = Utf8Encode(document.location.protocol + '//' + document.location.hostname);    // Document hostname.
            var dp = Utf8Encode(document.location.pathname + document.location.search);            // Page.
            var dt = 'Statistiques et Pronostics Courses de Chevaux';// Title.
            data1 = Array();
            data1['v'] = v;
            data1['tid'] = tid;
            data1['ds'] = ds;
            data1['cid'] = cid;
            data1['uid'] = uid;
            data1['uip'] = uip;
            data1['ua'] = ua;
            data1['t'] = t;
            data1['dr'] = dr;
            data1['ul'] = ul;
            data1['dh'] = dh;
            data1['dp'] = dp;
            data1['dt'] = dt;
            var url = 'https://www.google-analytics.com/collect';
            http_post(url, data1);
            var tmp_time = window.performance.timing;    // Instance de Performance.Timing.
            var v = '1';        // Version.
            var tid = 'UA-2860929-2';    // Tracking ID / Property ID.
            var ds = 'gdpr_analytics';        // Data Source.
            var cid = CID;                // Anonymous Client ID.
            var uid = UID;                // Client ID.
            var uip = ip_addr;            // IP Override.
            var ua = Utf8Encode(user_agent);    // User Agent Override.
            var t = 'timing';            // Timing hit type.
            var utc = 'all_timing';            // Timing Category.
            var utv = 'load';            // Timing variable.
            var utl = 'label';                            // Timing label.
            // These values are part of browser load times.
            var utt = tmp_time.domInteractive - tmp_time.navigationStart;        // User Timing Time.
            var plt = tmp_time.responseStart - tmp_time.navigationStart;        // Page Load Time.
            var dns = tmp_time.domainLookupEnd - tmp_time.domainLookupStart;    // DNS Time.
            var pdt = tmp_time.domLoading - tmp_time.responseStart;            // Page Download Time.
            var rrt = tmp_time.redirectEnd - tmp_time.redirectStart;        // Redirect Response Time.
            var tcp = tmp_time.connectEnd - tmp_time.connectStart;            // TCP Connect Time.
            var srt = tmp_time.responseStart - tmp_time.requestStart;        // Server Response Time.
            var dit = tmp_time.domInteractive - tmp_time.domLoading;        // DOM Interactive Time.
            var clt = tmp_time.domContentLoadedEventEnd - tmp_time.domInteractive;    // Content Load Time.
            data2 = Array();
            data2['v'] = v;
            data2['tid'] = tid;
            data2['ds'] = ds;
            data2['cid'] = cid;
            data2['uid'] = uid;
            data2['uip'] = uip;
            data2['t'] = t;
            data2['utc'] = utc;
            data2['utv'] = utv;
            data2['utt'] = utt;
            data2['utl'] = utl;
            data2['plt'] = plt;
            data2['dns'] = dns;
            data2['pdt'] = pdt;
            data2['rrt'] = rrt;
            data2['tcp'] = tcp;
            data2['srt'] = srt;
            data2['dit'] = dit;
            data2['clt'] = clt;
            http_post(url, data2);
        }
        document.addEventListener("readystatechange", function(event) {
            if(document.readyState == 'complete')
            {
                GA_data();
            }
        });
    </script>
    
    
     
  2. spout
    spout WRInaute accro
    Inscrit:
    14 Mai 2003
    Messages:
    8 760
    J'aime reçus:
    234
  3. ortolojf
    ortolojf WRInaute accro
    Inscrit:
    14 Août 2002
    Messages:
    2 799
    J'aime reçus:
    8
    Spout ...

    C'est quoi donc?
     
  4. ortolojf
    ortolojf WRInaute accro
    Inscrit:
    14 Août 2002
    Messages:
    2 799
    J'aime reçus:
    8
    Pardon

    Voici le log avec l'url debug :

    Code:
    
    17:19:11.962 (index):1098 {
      "hitParsingResult": [ {
        "valid": true,
        "parserMessage": [ ],
        "hit": "/debug/collect?v=1\u0026tid=UA-2860929-2\u0026ds=gdpr_analytics\u0026cid=80942ddd-fbbf-47eb-b387-f19d2f0c1980\u0026uid=6117541554\u0026uip=xxxxxxxxxxxxxx\u0026ua=Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.75 Safari/537.36\u0026t=pageview\u0026dr=\u0026ul=fr-FR\u0026dh=https://www.pronostics-courses.fr\u0026dp=/\u0026dt=Statistiques et Pronostics Courses de Chevaux\u0026_anon_uip=78.194.232.0"
      } ],
      "parserMessage": [ {
        "messageType": "INFO",
        "description": "Found 1 hit in the request."
      } ]
    }
    17:19:11.962 (index):1098 {
      "hitParsingResult": [ {
        "valid": true,
        "parserMessage": [ {
          "messageType": "INFO",
          "description": "Unrecognized parameter '_anon_uip' found.",
          "messageCode": "UNKNOWN_PARAMETER",
          "parameter": "_anon_uip"
        } ],
        "hit": "/debug/collect?v=1\u0026tid=UA-2860929-2\u0026ds=gdpr_analytics\u0026cid=80942ddd-fbbf-47eb-b387-f19d2f0c1980\u0026uid=6117541554\u0026uip=xxxxxxxxxxxxxx\u0026t=timing\u0026utc=all_timing\u0026utv=load\u0026utt=246\u0026utl=label\u0026plt=84\u0026dns=0\u0026pdt=13\u0026rrt=0\u0026tcp=0\u0026srt=53\u0026dit=149\u0026clt=0\u0026_anon_uip=78.194.232.0"
      } ],
      "parserMessage": [ {
        "messageType": "INFO",
        "description": "Found 1 hit in the request."
      } ]
    }
    
    
    Où est l'erreur ?

    Le premier "hitParsingResult" est pour les data classiques, le second pour les timing.

    Pour le premier tout baigne.
    Pour le second, GA ne rend que des vitesses égales à zéro.

    Spout dira que moi aussi je suis un zéro mais bon...
    Merci beaucoup de votre aide.

    Respectueusement.
     
Chargement...
Similar Threads - Données vitesse absentes Forum Date
Site piraté - base de données supprimée Administration d'un site Web Mercredi à 13:12
Confus sur la manière d'intégrer les données structurées Référencement Google 30 Juillet 2019
Données structurées : vos expériences Référencement Google 15 Juillet 2019
Breadcrumb Résultat différent dans Outil de données structurées Crawl et indexation Google, sitemaps 6 Mai 2019
Consolidation données Search Console du 10/04 Référencement Google 26 Avril 2019
Search Console Pas de mise a jour des données Search Console Crawl et indexation Google, sitemaps 23 Avril 2019
Données structurées sur produit d'un catalogue Rédaction web et référencement 16 Avril 2019
Base de données en local avec WAMP server Développement d'un site Web ou d'une appli mobile 21 Mars 2019
Afficher/cacher données dans un tableau Développement d'un site Web ou d'une appli mobile 9 Mars 2019
Données structurées : quel outil choisir ? Référencement Google 12 Février 2019
  1. Ce site utilise des cookies. En continuant à utiliser ce site, vous acceptez l'utilisation des cookies.
    Rejeter la notice