Google Analytics Realtime thin client.
Author
Piotr 'Athlan' Pelczar
Created with ❤ for majsterkowo.pl to support the Analogue Counter of Active Users on the website.
- Clone repository.
composer install
- Go to configuration section.
- (optional) Upload to the server where you want to host the script.
- Make
/var/cache
writable for web server process (chmod 777 or proper write access)
- Create Project in Google Console (skip if you have one) and enable Google Analytics API. (link to the wizard)
- Create the Service Account and select the Project when prompted. (link to the wizard)
- Type the name of the account and select Furnish a new private key.
- Download the .json credentials file. Remember the client email like your-client-name@your-project-id.iam.gserviceaccount.com
- Login to the Google Analytics
- Go to the Administration and add the new read-only user which email is as the Service Account email you just created (email from step 2).
- Go to the your webpage administration, and copy the View ID from View Settings. Write it down.
- Copy the
/config/config.php.diff
to the/config/config.php
- Copy the downloaded .json credentials file to the
/config/credentials
and point this file inconfig.php
.
- Copy the downloaded .json credentials file to the
- Your service is configured. You can access the stats by invoking address:
Where
http://localhost/your-path-of-this-project/rt-visitors.php?profileId=XYZ`
profileId
is your View ID from Google Analytics.
In configuration file you can configure caching:
- Change TTL of cache (0 to disable).
- Change cache driver (default is Filesystem) options like a directory to store cache.
- Change cache driver to another one (list of drivers).
-
cURL error 60: SSL certificate problem: unable to get local issuer certificate
You are not accepting the Google certificate.
Possible solutions:
- Update your certificates on the on the operating system.
- Override your
curl.cainfo
property on the runtime or in php.ini file and point to the downloaded cacert.pem. - Just uncomment
cacert
settings in the config file and. Point to the downloaded cacert.pem file.This file is bundled in/config/cacert.pem
.
Read more: googleapis/google-api-php-client#1011