PHPackages                             infoweb-internet-solutions/yii2-cms-analytics - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. infoweb-internet-solutions/yii2-cms-analytics

ActiveYii2-extension[Utility &amp; Helpers](/categories/utility)

infoweb-internet-solutions/yii2-cms-analytics
=============================================

Analytics module for Yii2

1.0.0(11y ago)112.4k12[6 issues](https://github.com/infoweb-internet-solutions/yii2-cms-analytics/issues)1MITPHP

Since Jan 5Pushed 4y ago4 watchersCompare

[ Source](https://github.com/infoweb-internet-solutions/yii2-cms-analytics)[ Packagist](https://packagist.org/packages/infoweb-internet-solutions/yii2-cms-analytics)[ RSS](/packages/infoweb-internet-solutions-yii2-cms-analytics/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (2)Versions (2)Used By (1)

Google analytics
================

[](#google-analytics)

Google analytics

Installation
------------

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
php composer.phar require --prefer-dist infoweb-internet-solutions/yii2-cms-analytics "*"

```

or add

```
"infoweb-internet-solutions/yii2-cms-analytics": "*"
```

to the require section of your `composer.json` file.

Go to the [Google developers console](https://console.developers.google.com)

Create a new project (or use an existing project)

Open the project

Go to 'API &amp; Auth -&gt; API's' and enable the 'Analytics API'

Go to 'API &amp; Auth -&gt; Credentials' and under 'OAuth' click 'Create new Client ID'

Choose 'Service account' and click 'Create client id'

Save the certificate to 'backend\\assets\\certificate\\certificate.p12' (don't forget to rename the file)

Write down the 'private key's password' somewhere

Add the credentials to your backend params

```
return [
    ...
    'analytics' => [
        'developerKey' => '', // Public key fingerprints
        'serviceAccountName' => 'xxx@developer.gserviceaccount.com', // Email address
        'clientId' => 'xxx.apps.googleusercontent.com', // Client ID
    ],
];
```

Go to [Google analytics](https://www.google.com/analytics/), open your property and get your 'Profile ID'

(It is the number at the end of the URL starting with p: )

Add the 'Profile ID' to your params

```
return [
    ...
    'analytics' => [
        ...
        'analyticsId' => 'ga:XXXXXXXX',
    ],
];
```

Add the serviceAccountName () as a new user to your Analyics property

Create the alias '@google/api' in the bootstrap file in common/config like so:

```
Yii::setAlias('google/api', dirname(dirname(__DIR__)) . '/vendor/google/apiclient/src');
```

Import the translations and use category 'infoweb/analytics':

```
yii i18n/import @infoweb/analytics/messages

```

If you can't access the `/tmp` folder on your server (shared hosting), change line 94 in `vendor\google\apiclient\src\Google\`

```
'directory' => dirname(Yii::getAlias('@webroot')) . '/runtime/Google_Client'
```

Usage
-----

[](#usage)

Once the extension is installed, replace the contents of `backend/views/site/index.php` with the following:

```

```

```
