简体   繁体   English

显示网站上Google Analytics的访问者数量

[英]Display number of visitors of google analytics on website

A client asked me to display the number of hits/visitors in their website. 客户要求我显示其网站中的点击次数/访问者数量。 I would like to know how can you do display this. 我想知道你怎么能显示这个。

I would insert it in my footer as displayed: 我会在显示的页脚中插入它:

在此输入图像描述

If not possible with google analytics, do you know of a snippet which will work? 如果谷歌分析无法实现,您知道一个可行的片段吗? I've checked websites which offer their services but they recollect information and I would like to learn to do it myself or with google analytics. 我检查了提供服务的网站,但是他们回忆起了我想要的信息,我想学习自己或谷歌分析。 My files are PHP so maybe there is something I can do with that? 我的文件是PHP,所以也许我可以用它做些什么?

You can use google anlaytics api , which can be enabled in your google api console. 您可以使用google anlaytics api ,它可以在您的google api控制台中启用。 For knowing the number of visitors in given time period, you can utilize Core Reporting API and for knowing the current number of visitors in real time , you can use Realtime Reporting API 要了解给定时间段内的访问者数量,您可以使用Core Reporting API并实时了解当前访问者数量,您可以使用Realtime Reporting API

You can do graphical representation by using http://www.seethestats.com/ also. 您也可以使用http://www.seethestats.com/进行图形表示。 Different type of counts you can get like Visits, Unique Visitors, Visits by Page title, etc 您可以获得不同类型的计数,如访问次数,唯一身份访问者,按页面标题访问次数等

  1. Create account on http://www.seethestats.com/ . http://www.seethestats.com/上创建帐户。
  2. Select GA stats you want to publish. 选择要发布的GA统计信息。
  3. Insert stats widget on your website. 在您的网站上插入统计信息小部件。

ex. 恩。 http://www.seethestats.com/site/monvidedressing.ch http://www.seethestats.com/site/monvidedressing.ch

此API( 管理API客户端库和示例代码 )可以帮助您轻松快速地完成工作。

Unless you get whitelisted for Realtime Reporting API , there is no way to get current number of online visitor from GA. 除非您获得Realtime Reporting API列入白名单,否则无法从GA获取当前的在线访问者数量。 And if with the Realtime API, the implementation might be tricky and require a bit of coding as well. 如果使用Realtime API,实现可能会很棘手并且需要一些编码。

The easiest way to go is to use tools like StatCounter . 最简单的方法是使用StatCounter等工具。 The numbers won't probably align (there are no two web analytics tools that would give you the same numbers anyway :-), but they will be "accurate enough" and most importantly - you will be done with the implementation part in no time! 这些数字可能不一致(没有两个网络分析工具可以为您提供相同的数字:-),但它们将“足够准确”,最重要的是 - 您将很快完成实施部分!

I found a solution once I investigated again: 我再次调查后找到了一个解决方案:

<?php
session_start();
$counter_name = "counter.txt";

// Check if a text file exists. If not create one and initialize it to zero.
if (!file_exists($counter_name)) {
  $f = fopen($counter_name, "w");
  fwrite($f,"0");
  fclose($f);
}

// Read the current value of our counter file
$f = fopen($counter_name,"r");
$counterVal = fread($f, filesize($counter_name));
fclose($f);

// Has visitor been counted in this session?
// If not, increase counter value by one
if(!isset($_SESSION['hasVisited'])){
  $_SESSION['hasVisited']="yes";
  $counterVal++;
  $f = fopen($counter_name, "w");
  fwrite($f, $counterVal);
  fclose($f); 
}

echo "You are visitor number $counterVal to this site";

This snippet can be found clicking here . 这个片段可以点击这里找到。 THe credits are for him. 这些学分适合他。 I display it to see if this can help somebody else in this topic. 我显示它是否可以帮助此主题中的其他人。

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

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