Visible stat from Google Analytics

From my old blog Extract data from google analytic with PHP which allow you to extract data from Google Analytics to use on your website. In this post we’ll write a little script to show number of pageviews on the web for all the world to see. It’s actually an old school “web counter” as we know it.

Step to create pageview counter

1. Download GAAPI from my old blog though we’ll use only gaapi.class.php here

2. Construct gaapi class and call method All Time Page Views (total number of page views)

include_once('gaapi.class.php');
$ga=new gaApi('google username','password','ga:site id');
$allTimeSummery=$ga->getAllTimeSummery();

3. Show the counter using HTML with CSS

<div id="vGA">
  <strong><?= $allTimeSummery['ga:pageviews'] ?></strong>
  <span>Views</span></div>
</div>
#vGA{
	width: 100px;
	position: relative;
	font-size: 9px;
	font-family: Verdana, Verdana, Geneva, sans-serif;
	padding-bottom: 15px;
	background: url(poweredBy.gif) no-repeat bottom left;
}
#vGA strong{
	text-align: right;
	border: 2px solid #4f6db0;
	color: #555;
	line-height: 15px;
}
#vGA span{
	background: #4f6db0;
	text-align: center;
	color: white;
	float: right;
	padding: 0 0 0 2px;
	margin: 0 0 0 2px;
}

And now we’ve got easy Visible Stat from Google Analytic. If you wish to show other data such as Unique Visits you can do so by follow instruction from my old post Extract data from google analytic with PHP