PHPackages                             kudobuzz/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. [HTTP &amp; Networking](/categories/http)
4. /
5. kudobuzz/google-analytics-php

ActiveLibrary[HTTP &amp; Networking](/categories/http)

kudobuzz/google-analytics-php
=============================

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

02.6k1PHP

Since Nov 7Pushed 6y ago5 watchersCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

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

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

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

use Kudobuzz\Analytics;
use Kudobuzz\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 Kudobuzz\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

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity35

Early-stage or recently created project

 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/17567105?v=4)[Kudobuzz](/maintainers/Kudobuzz)[@kudobuzz](https://github.com/kudobuzz)

---

Top Contributors

[![toneymutinda](https://avatars.githubusercontent.com/u/22909665?v=4)](https://github.com/toneymutinda "toneymutinda (2 commits)")

### Embed Badge

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

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

###  Alternatives

[friendsofsymfony/rest-bundle

This Bundle provides various tools to rapidly develop RESTful API's with Symfony

2.8k73.3M319](/packages/friendsofsymfony-rest-bundle)[php-http/discovery

Finds and installs PSR-7, PSR-17, PSR-18 and HTTPlug implementations

1.3k309.5M1.2k](/packages/php-http-discovery)[nyholm/psr7

A fast PHP7 implementation of PSR-7

1.3k235.4M2.4k](/packages/nyholm-psr7)[pusher/pusher-php-server

Library for interacting with the Pusher REST API

1.5k94.8M293](/packages/pusher-pusher-php-server)[spatie/crawler

Crawl all internal links found on a website

2.8k16.3M52](/packages/spatie-crawler)[react/http

Event-driven, streaming HTTP client and server implementation for ReactPHP

78126.4M414](/packages/react-http)

PHPackages © 2026

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