athlan / google-analytics-rt

Google Analytics Realtime API client

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

google-analytics-rt

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.

Installation

  1. Clone repository.
  2. composer install
  3. Go to configuration section.
  4. (optional) Upload to the server where you want to host the script.
  5. Make /var/cache writable for web server process (chmod 777 or proper write access)

Configuration

Create Google API Console application

  1. Create Project in Google Console (skip if you have one) and enable Google Analytics API. (link to the wizard)
  2. Create the Service Account and select the Project when prompted. (link to the wizard)

Configure Google Analytics account

  1. 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.

Configure the script

  1. 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 in config.php.
  2. Your service is configured. You can access the stats by invoking address:
    http://localhost/your-path-of-this-project/rt-visitors.php?profileId=XYZ`
    
    Where profileId is your View ID from Google Analytics.

Additional configuration

Caching

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).

Known issues

  1. 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

About

Google Analytics Realtime API client


Languages

Language:PHP 100.0%