简体   繁体   English

没有 JavaScript 或 Cookie 的 Google Analytics

[英]Google Analytics without JavaScript or Cookies

I have a unique situation where I have a site with several thousand users who are all browing using a client that does not support JavaScript or cookies.我有一个独特的情况,我的网站有数千名用户,这些用户都在使用不支持 JavaScript 或 cookie的客户端浏览

It is also unable to load normal image files, but instead will only load a special image type, NTFT它也无法加载普通的图像文件,而只会加载一种特殊的图像类型,NTFT

<img src="http://example.com/image.ntft" height="1" width="1" />

The client isn't a web browser per se, but renders a non-standard form of HTML.客户端本身不是 Web 浏览器,而是呈现非标准形式的 HTML。

I want to use Google Analytics to get visitor information for my site, and get unique visitor information.我想使用 Google Analytics 来获取我网站的访问者信息,并获得唯一的访问者信息。 I get several hundred thousand hits and about ~40GB of bandwidth usage a day, so I'm very interested in the information for unique visitors.我每天获得数十万次点击和大约 40GB 的带宽使用量,因此我对独立访问者的信息非常感兴趣。 I've been looking at https://github.com/thomasbachem/php-ga but do not want anything like this: How do I get PHP-GA to stop incrementing real-time visitors in google analytics?我一直在查看https://github.com/thomasbachem/php-ga但不想要这样的东西:如何让 PHP-GA 停止增加谷歌分析中的实时访问者? to happen, as I'll get swamped with "Unique Visitors" that are really just one page visit.发生,因为我会被“唯一身份访问者”淹没,而这些“唯一身份访问者”实际上只是一页访问。

I'm using PHP.我正在使用 PHP。 Can you suggest a decent solution to measure traffic from unique visitors (unique IPs, for example)?您能否提出一个不错的解决方案来衡量来自唯一访问者(例如,唯一 IP)的流量?

I would consider giving PIWIK a try.我会考虑尝试一下 PIWIK。 You can assign your users a unique ID and track them via the tracking API您可以为您的用户分配一个唯一 ID 并通过跟踪 API 跟踪他们

http://piwik.org/ http://piwik.org/

Tracking API DOCS: http://piwik.org/docs/tracking-api/跟踪 API 文档: http : //piwik.org/docs/tracking-api/

PHP Client for Tracking API http://developer.piwik.org/api-reference/PHP-Piwik-Tracker用于跟踪 API 的 PHP 客户端http://developer.piwik.org/api-reference/PHP-Piwik-Tracker

Another option would be to implement the Google Measurement Protocol.另一种选择是实施 Google 测量协议。 Since you can define your own definition of a unique visitor by passing the cid parameter.因为您可以通过传递cid参数来定义您自己的唯一访问者定义。 For example a hashed ip-address or another unique ID based on the user.例如,散列的 ip 地址或基于用户的另一个唯一 ID。 Please not that it is not allowed to pass the plain ip number (or any user data that can identify a user) so always use hashed values.请注意,不允许传递IP 号(或任何可以识别用户的用户数据),因此请始终使用散列值。

By using the GA measurement protocol you can use all the features provided by GA without the need of javascript.通过使用 GA 测量协议,您可以使用 GA 提供的所有功能,而无需 javascript。

PHP client: https://github.com/krizon/php-ga-measurement-protocol API Doc: https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide PHP 客户端: https : //github.com/krizon/php-ga-measurement-protocol API 文档: https : //developers.google.com/analytics/devguides/collection/protocol/v1/devguide

disclaimer: i wrote the php client.免责声明:我编写了 php 客户端。

Here an useful code to agree with the regulation of cookies in Europe.这里有一个有用的代码来同意欧洲的 cookie 规定。 It works at this moment (november 2020) :它现在有效(2020 年 11 月):

<script>
const cyrb53 = function(str, seed = 0) {
   let h1 = 0xdeadbeef ^ seed,
      h2 = 0x41c6ce57 ^ seed;
   for (let i = 0, ch; i < str.length; i++) {
      ch = str.charCodeAt(i);
      h1 = Math.imul(h1 ^ ch, 2654435761);
      h2 = Math.imul(h2 ^ ch, 1597334677);
   }
   h1 = Math.imul(h1 ^ h1 >>> 16, 2246822507) ^ Math.imul(h2 ^ h2 >>> 13, 3266489909);
   h2 = Math.imul(h2 ^ h2 >>> 16, 2246822507) ^ Math.imul(h1 ^ h1 >>> 13, 3266489909);
   return 4294967296 * (2097151 & h2) + (h1 >>> 0);
};

let clientIP = "{Client_IP}";
let validityInterval = Math.round (new Date() / 1000 / 3600 / 24 / 4);
let clientIDSource = clientIP + ";" + window.location.host + ";" + navigator.userAgent + ";" + navigator.language + ";" + validityInterval;
let clientIDHashed = cyrb53(clientIDSource).toString(16);

(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', 'Your-analytics-code', {
   'storage': 'none',
   'clientId': clientIDHashed
});
ga('set', 'anonymizeIp', true);
ga('send', 'pageview');
</script>

You have to replace Your-analytics-code.您必须替换您的分析代码。 In php you can get the ip of client "{Client_IP}" by this way:在 php 中,您可以通过以下方式获取客户端“{Client_IP}”的 ip:

if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
    $ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
    $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
    $ip = $_SERVER['REMOTE_ADDR'];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM