Display number of visitors of google analytics on website
Asked Answered
R

5

17

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?

Regional answered 30/9, 2013 at 10:43 Comment(1)
check out 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.Chibcha
D
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

Democrat answered 30/9, 2013 at 13:52 Comment(1)
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?Regional
B
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

Benitabenites answered 28/3, 2014 at 11:45 Comment(0)
G
1

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

Gonsalez answered 31/3, 2014 at 7:5 Comment(0)
K
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!

Katheryn answered 1/10, 2013 at 6:25 Comment(0)
R
-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.

Regional answered 1/10, 2013 at 14:13 Comment(2)
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.Buddle
First of all the answer doesn't refer to Google analytics, secondly it would need PHP.Hermy

© 2022 - 2024 — McMap. All rights reserved.