atlasmobile/yii2-ga

yii2 google analytics component

Installs: 424

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 5

Forks: 0

Open Issues: 0

Type:yii2-extension

1.0.4 2016-03-10 14:12 UTC

This package is not auto-updated.

Last update: 2024-11-07 01:33:56 UTC


README

Google analytics component for Yii2

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist atlasmobile/yii2-ga "*"

or add

"atlasmobile/yii2-ga": "*"

to the require section of your composer.json file.

Application params

To use this extension, add the following code in your application params:

return [
    ...
    'googleAnalytics' => [
        'developerKey' 		 => '', // Public key
        'clientId' 			 => 'xxx.apps.googleusercontent.com', // Client ID
        'analyticsId'        => 'ga:xxxxxxxxx', //(It is the number at the end of the URL starting with p: https://www.google.com/analytics/web/#home/a33443w112345pXXXXXXXX/)
        'serviceAccountName' => 'xxx@xxx.gserviceaccount.com', // Email address
        'privateKeyPath'	 => '', //path to private key in p12 format
    ],
];

Add the serviceAccountName (xxx@dxxx.gserviceaccount.com) as a new user to your Analyics property.

Usage

use atlasmobile\analytics\Analytics;

class Test
{
	public function example()
	{
		$analytics = new Analytics();
		$analytics->startDate = '';
		$analytics->endDate = '';
		
		$sessionsData = $analytics->getSessions();
		$visitorsData = $analytics->getUsers();
		$pageViewsData = $analytics->getPageViews();
		$avgSessionsDurationData = $analytics->getAvgSessionDuration();
		$countriesData = $analytics->getCountries();
	}
}

Parameters 'startDate' and 'endDate' are set by default for yesterday

Useful links

Analytics Core Reporting API
Google API Php Client