PHPackages                             ozankurt/google-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. [API Development](/categories/api)
4. /
5. ozankurt/google-analytics

ActiveLibrary[API Development](/categories/api)

ozankurt/google-analytics
=========================

Laravel Google Analytics

v2.0.1(9y ago)7616.7k↓50%9[1 issues](https://github.com/OzanKurt/google-analytics/issues)MITPHPCI failing

Since Jul 9Pushed 7y ago5 watchersCompare

[ Source](https://github.com/OzanKurt/google-analytics)[ Packagist](https://packagist.org/packages/ozankurt/google-analytics)[ RSS](/packages/ozankurt-google-analytics/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (2)Versions (5)Used By (0)

Google Analytics
================

[](#google-analytics)

[![Latest Stable Version](https://camo.githubusercontent.com/c80f64da5658a5c279ed24a2ea0a3e8ef62d76400f4623c3b4613466ebb7f9b2/68747470733a2f2f706f7365722e707567782e6f72672f6f7a616e6b7572742f676f6f676c652d616e616c79746963732f762f737461626c65)](https://packagist.org/packages/ozankurt/google-analytics) [![Total Downloads](https://camo.githubusercontent.com/21f21c5114f87d8094ba23b3d0360dc5d815ed6d42b93bdcbc64c98245babdc2/68747470733a2f2f706f7365722e707567782e6f72672f6f7a616e6b7572742f676f6f676c652d616e616c79746963732f646f776e6c6f616473)](https://packagist.org/packages/ozankurt/google-analytics) [![Latest Unstable Version](https://camo.githubusercontent.com/dce47cbb3391b6ca66c2f1505b9b7600bc6ded2262db3fd6f434e89bd42b1d66/68747470733a2f2f706f7365722e707567782e6f72672f6f7a616e6b7572742f676f6f676c652d616e616c79746963732f762f756e737461626c65)](https://packagist.org/packages/ozankurt/google-analytics) [![License](https://camo.githubusercontent.com/940ef37cb82e223e1eda7d2abcd730a01f8b1b21bbe21616b4fe8a73085b82b4/68747470733a2f2f706f7365722e707567782e6f72672f6f7a616e6b7572742f676f6f676c652d616e616c79746963732f6c6963656e7365)](https://packagist.org/packages/ozankurt/google-analytics)

Connecting to your analytics account and getting whatever data you need was never this easy. 😎

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

[](#installation)

### Step 1

[](#step-1)

Add `ozankurt/google-analytics` to your composer requirements.

```
composer require ozankurt/google-analytics
```

### Step 2

[](#step-2)

Configure `ozankurt/google-core` package by following its [README](https://github.com/OzanKurt/google-core/blob/master/README.md).

### Step 3

[](#step-3)

Select the Analytics API

[![Select the Analytics API](https://camo.githubusercontent.com/7263b2d8eede77e011dd56282794c5f7c82a9f5ff2f57ff4c2d79a66258664a4/687474703a2f2f692e696d6775722e636f6d2f7438527168564e2e706e67)](https://camo.githubusercontent.com/7263b2d8eede77e011dd56282794c5f7c82a9f5ff2f57ff4c2d79a66258664a4/687474703a2f2f692e696d6775722e636f6d2f7438527168564e2e706e67)

Enable it

[![Enable It](https://camo.githubusercontent.com/b1fde75835056f7980465e50d2d58a33a2c74e403117282f82bea717f2258315/687474703a2f2f692e696d6775722e636f6d2f77324230594b422e706e67)](https://camo.githubusercontent.com/b1fde75835056f7980465e50d2d58a33a2c74e403117282f82bea717f2258315/687474703a2f2f692e696d6775722e636f6d2f77324230594b422e706e67)

### Step 4

[](#step-4)

Add analytics scope to your scopes array to the configurations in `ozankurt/google-core` package.

```
'scopes' => [
	'https://www.googleapis.com/auth/analytics.readonly',
],
```

Usage (Laravel)
---------------

[](#usage-laravel)

#### Step 1

[](#step-1-1)

Add `analytics.viewId` to your `config/google.php`.

```
    /**
     * View ID can be found in `http://google.com/analytics` under the `Admin` tab on navigation.
     *
     * Select `Account`, `Property` and `View`. You will see a `View Settings` link.
     */
    'analytics' => [
        'viewId' => 'ga:12345678',
    ],
```

#### Controller Example

[](#controller-example)

```
use Kurt\Google\Analytics\Analytics as GoogleAnalytics;

class GoogleController extends Controller
{
    private $ga;

    function __construct(GoogleAnalytics $ga) {
        $this->ga = $ga;
    }

    public function index()
    {
        $results = $this->ga->getUsersAndPageviewsOverTime();

        var_dump($results);
    }
}
```

Usage (Pure PHP)
----------------

[](#usage-pure-php)

#### Example

[](#example)

```
