16

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:

enter image description here

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?

Daniel Ramirez-Escudero
  • 3,877
  • 13
  • 43
  • 80
  • 1
    check out http://www.embeddedanalytics.com (I work with the company). We offer widgets which will do exactly this. Both "all time visitors" and "real-time visitors". And we can even filter for the current pages the browser is on. – M Schenkel Oct 11 '14 at 00:03

5 Answers5

6

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

tony m
  • 4,769
  • 1
  • 21
  • 28
  • 3
    I've checked realtime reporting API. I really don't see any code which I can use, something like a hook. I checked also and they need to wait Google to whitelist my site... Is there not a simple method for this? My client only needs to display the number of visits or hits. Maybe it's a solution tony, but it's too complex for what he needs. DO you have any other hints? – Daniel Ramirez-Escudero Sep 30 '13 at 16:07
3

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

  1. Create account on http://www.seethestats.com/.
  2. Select GA stats you want to publish.
  3. Insert stats widget on your website.

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

Somnath Muluk
  • 55,015
  • 38
  • 216
  • 226
1

This APIs (Management API Client Libraries & Sample Code) help you easily and quickly.

MReza
  • 152
  • 1
  • 7
0

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!

Petr Havlik
  • 3,307
  • 1
  • 19
  • 17
-6

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.

Daniel Ramirez-Escudero
  • 3,877
  • 13
  • 43
  • 80
  • 1
    Hi @Daniel Rami, The above solution is using custom php code.Did you get a chance to work out through Google Analytics? SeeTheStats and all are paid services. I just wanted to show the total number of visitors of my site. Its pure HTML site. – Joy George Kunjikkuru Oct 03 '15 at 20:46
  • First of all the answer doesn't refer to Google analytics, secondly it would need PHP. – Vishal Kumar Sahu Apr 28 '20 at 10:42