..
Google Analytics is the most popular service to monitor the performance of a website.
Google Analytics provides detailed statistics - packaged in an elegant user interface that makes extensive use of AJAX technology - thanks to which we can access a range of data about who visits our websites.
This is supported also by a huge number of search options and filters through which traffic analysis of our web-site will be incredibly accurate and detailed.
The requests are fulfilled using REST services, then just implement a simple HTTP call to receive a response as XML.
One way to make requests to the API is to use the PHP cURL extension and then parse the resulting XML with the most useful and powerful class SimpleXML xpath syntax.
For those who did not have the time or inclination to implement a customized class that can authenticate and parse the data, I report the existence of an open-source can do all the work for us.
The project is called GAPI (which stands for Google Analytics PHP interface) and you can get, with lots of documentation and usage examples to this page on Google Code.
GAPI is a great class, thanks to which we astrarci the atomic operations required to connect, authenticate and retrieve data from our Google Analytics profile.
The core of the package - you can download from here - GAPI is the class that takes as good practice, we find in the file gapi.class.php. Complete the endowment of this version (1.3 at the time of writing) 4 sample files and a readme file.
The code is well written, robust and ordered as required. We see, briefly, its main features:
Now that we have a rough idea of what it offers, let us integrate the class in a GAPI our simple application.
The structure that I propose is quite simple: our application is composed of only three files:
Let's see the contents of our configuration file:
; Application properties google_username = "google_username" google_password = "google_password" ga_id_profilo = "id_profilo"
It 'important to remember to protect the file so that it is conf.ini accessed from the Web (eg using a htaccess file)
Let us analyze the file process.php (which contains the actual instructions of our web application):
require_once 'gapi.class.php';
$ Properties = parse_ini_file ("conf.ini");
$ GapiObj = new GAPI ($ properties ["google_username"], $ properties ["google_password"]);
Currently we have done is include the class GAPI, load our properties in an array variable and instantiate our "clients". The second part of our small application that will, I assure you, much more interesting ...
| |
Linux (Course)
Complete guide to open-source system. From 49 €. |
| |
MySQL (Course)
Management of open-source database. From 39 €. |
| |
PHP (Course)
Full course for creating dynamic Web sites. From 49 €. |