PHPackages                             winnipass/google-analytics-php - 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. winnipass/google-analytics-php

ActiveLibrary[API Development](/categories/api)

winnipass/google-analytics-php
==============================

Winnipass Google Analytics Is A PHP Library For Making Google Analytics And OAuth Requests

1936PHP

Since May 8Pushed 8y ago1 watchersCompare

[ Source](https://github.com/winni4eva/google-analytics-php)[ Packagist](https://packagist.org/packages/winnipass/google-analytics-php)[ RSS](/packages/winnipass-google-analytics-php/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependenciesVersions (1)Used By (0)

google-analytics-php Installation
=================================

[](#google-analytics-php-installation)

```
composer require winnipass/google-analytics-php

use Winnipass\Analytics;
use Winnipass\Period;

$token = [
    "access_token"=>"your-access-token",
    "refresh_token"=>"refresh-token",
    "token_type"=>"Bearer",
    "expires_in"=>3600,
    "id_token"=>"TOKEN",
    "created"=>1320790426
];

$secret_json_path = realpath(__DIR__) .'\path-to-your-secret-json-file.json' ;

$analyticsService = new Analytics;

$service = $analyticsService->setClient( $token, $secret_json_path )
            ->setViewId( '1234567' );

$visitorsAndPageViews = $service->fetchVisitorsAndPageViews( '2016-08-20', '2017-01-31' );

$totalVisitorsAndPageViews = $service->fetchTotalVisitorsAndPageViews( '2016-08-20', '2017-01-31' );

$mostVisitedPaged = $service->fetchMostVisitedPages( '2016-08-20', '2017-01-31' );

$topReferrers = $service->fetchTopReferrers( '2016-08-20', '2017-01-31' );

$topBrowsers = $service->fetchTopBrowsers( '2016-08-20', '2017-01-31' );

```

Custom Query
============

[](#custom-query)

```
$startDate = new DateTime( date( 'Y-m-d', strtotime( '2016-08-20' ) ) );

$endDate = new DateTime( date( 'Y-m-d', strtotime( '2016-08-20' ) ) );

$visitorsAndPageViews = $service->performQuery( new Period($startDate, $endDate), 'ga:pageviews' );

//Iterate over response using Laravel Collection Helper method collect()

$pageViews = collect($visitorsAndPageViews['rows'] ?? [])->map(function ($pageViews) {
    return $pageViews;
});

var_dump($pageViews);

//for more info about Laravel Collections visit https://laravel.com/docs/5.4/collections

```

OAuth
=====

[](#oauth)

```
use Winnipass\OAuth\Google\GoogleOAuth;

$secret_json_path = __DIR__ .'/credentials/secret.json';

$client = new GoogleOAuth(
    $secret_json_path,
    "http://localhost:8000/redirect/url",
    ['https://www.googleapis.com/auth/analytics']//scopes
);

if( isset($_GET['error']) )
{
    var_dump($_GET['error']);
}
elseif(!isset($_GET['code']))
{
    $client->redirect();
}
else
{
    $tokens = $client->authenticate( $_GET['code'] )->getTokens();

    if($tokens)
    {
        $client->setAccessToken( $tokens );

        if ( $client->isAccessTokenExpired() )
        {
            $client->refreshToken( $tokens['refresh_token'] );

            $tokens = $client->getAccessToken();
        }

        $response = $client->makeRequest('https://www.googleapis.com/analytics/v3/management/accounts');

        var_dump($response->getBody()->getContents());

    }else{
        echo "No tokens Found !!!";
    }
}

```

###  Health Score

23

—

LowBetter than 26% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/8088536?v=4)[adam winnipass](/maintainers/winnipass)[@winnipass](https://github.com/winnipass)

---

Top Contributors

[![winni4eva](https://avatars.githubusercontent.com/u/6095748?v=4)](https://github.com/winni4eva "winni4eva (57 commits)")

---

Tags

google-analyticsgoogle-analytics-phpgoogle-oauthwinnipass-analytics

### Embed Badge

![Health badge](/badges/winnipass-google-analytics-php/health.svg)

```
[![Health](https://phpackages.com/badges/winnipass-google-analytics-php/health.svg)](https://phpackages.com/packages/winnipass-google-analytics-php)
```

###  Alternatives

[exsyst/swagger

A php library to manipulate Swagger specifications

35916.4M7](/packages/exsyst-swagger)[hubspot/api-client

Hubspot API client

24016.2M19](/packages/hubspot-api-client)[pocketmine/bedrock-protocol

An implementation of the Minecraft: Bedrock Edition protocol in PHP

172445.0k12](/packages/pocketmine-bedrock-protocol)[botman/driver-telegram

Telegram driver for BotMan

93459.5k6](/packages/botman-driver-telegram)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
