Reputation: 4047
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?
Upvotes: 17
Views: 43339
Reputation: 152
This APIs (Management API Client Libraries & Sample Code) help you easily and quickly.
Upvotes: 1
Reputation: 57846
You can do graphical representation by using http://www.seethestats.com/
also.
Different type of counts you can get like Visits, Unique Visitors, Visits by Page title, etc
ex. http://www.seethestats.com/site/monvidedressing.ch
Upvotes: 3
Reputation: 4047
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.
Upvotes: -6
Reputation: 3317
Unless you get whitelisted for Realtime Reporting API, there is no way to get current number of online visitor from GA. And if with the Realtime API, the implementation might be tricky and require a bit of coding as well.
The easiest way to go is to use tools like 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!
Upvotes: 0
Reputation: 4789
You can use google anlaytics api , which can be enabled in your google api console. 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
Upvotes: 6