PHPackages                             ersah/ga-bundle - 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. ersah/ga-bundle

ActiveSymfony-bundle[API Development](/categories/api)

ersah/ga-bundle
===============

Integration of Google Analytics API v4 to Sonata Admin Bundle

11981PHP

Since Apr 25Pushed 9y ago1 watchersCompare

[ Source](https://github.com/ersah123/ga)[ Packagist](https://packagist.org/packages/ersah/ga-bundle)[ RSS](/packages/ersah-ga-bundle/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependenciesVersions (1)Used By (0)

Google Analytics API v4 Integration for Sonata Admin bundle
===========================================================

[](#google-analytics-api-v4-integration-for-sonata-admin-bundle)

It is a simple package that uses Google Analytics Api v4 to give you all the information available by Dimensions &amp; Metrics. It has default Sonata Admin Bundle 'list' functionality. Meaning, you can sort, search, date filter your Google Analytics report.

To be able to use it, you have to setup a project on Google Console for Google Analytics, get the json key, then configure this package by setting the path for it. You'll have to add the developer email defined into the Google Console to the GA views to authorize it, otherwise the view won't be accessible through the API.

Requirements
============

[](#requirements)

SonataAdminBundle:

[https://sonata-project.org/bundles/admin/3-x/doc/getting\_started/installation.html](https://sonata-project.org/bundles/admin/3-x/doc/getting_started/installation.html)

Add this lines to app/config/routing.yml

```
_sonata_admin:
    resource: .
    type: sonata_admin
    prefix: /admin

```

installation
============

[](#installation)

```
composer require ersah/ga-bundle=dev-master

```

add to /app/AppKernel.php :

```
$bundles = [
    ...
    new Ersah\GABundle\ErsahGABundle(),
];

```

configuration
=============

[](#configuration)

```
  ersah_ga:
      view_id: ''
      google_analytics_json_key: "%kernel.root_dir%/../"
      limit: 15 # results per page
      from: "30daysAgo" # also YYYY-MM-DD
      to: "today"       # also YYYY-MM-DD
      sortBy: "ga:totalEvents"
      sorting: "DESCENDING"
      list:
          dimensions:
              - { value: 'ga:dimension1', label: 'Asset ID' }
              ...
          metrics:
              - { value: 'ga:totalEvents', label: 'Total Events' }
              ...
      #ga metrics and dimensions :

```

You can find available dimensions and metrics from here:

Click check boxes items you want to use to see the possible combinations of dimensions and metrics.

Google Api Key
==============

[](#google-api-key)

Generate the json file from [https://console.developers.google.com/start/api?id=analyticsreporting.googleapis.com&amp;credential=client\_key](https://console.developers.google.com/start/api?id=analyticsreporting.googleapis.com&credential=client_key) by creating a project, check the documentation : .

Set relative path for your json key (set it on your server, better not into your repository) from execution path, ex:

/app/config/config.yml

```
ersah_ga:
    google_analytics_json_key: "%kernel.root_dir%/../" #root of the project

```

You can see repost here: /admin/ga/list

Google Analytics API v4
=======================

[](#google-analytics-api-v4)

Samples :

errors
======

[](#errors)

In that 403 error case, follow the link and authorize the API v4.

Creating API for same configuration
===================================

[](#creating-api-for-same-configuration)

Install FosRestBundle:

[http://symfony.com/doc/master/bundles/FOSRestBundle/1-setting\_up\_the\_bundle.html](http://symfony.com/doc/master/bundles/FOSRestBundle/1-setting_up_the_bundle.html)

Enable Serializer in /app/config/config.yml:

```
framework:
    ...
    serializer: { enable_annotations: true }

```

and:

```
fos_rest:
    param_fetcher_listener: true
    body_listener:          true
    format_listener:        true
    view:
        view_response_listener: force
    body_converter:
        enabled: false
        validate: true

```

Add to app/config/routing.yml:

```
ersah_api_ga:
    type:         rest
    prefix:       /api/ga
    resource:     "@ErsahGABundle/Controller/ApiController.php"

```

Install JMSSerializerBundle:

Install NelmioApiDocBundle:

You can see API endpoints and documentations in /api/doc

Bonus: Use Sonata Block Bundle for Main report
==============================================

[](#bonus-use-sonata-block-bundle-for-main-report)

In app/config/config.yml

```
ersah_ga:
...
    main:
        metrics:
            - { value: 'ga:sessions', label: 'Sessions' }
            - { value: 'ga:bounceRate', label: 'Bounce Rate' }
            - { value: 'ga:avgTimeOnPage', label: 'Average Time On Page' }
            - { value: 'ga:pageviewsPerSession', label: 'Page Views Per Session' }
            - { value: 'ga:percentNewVisits', label: 'Percent New Visits' }
            - { value: 'ga:pageviews', label: 'Page Views' }
            - { value: 'ga:avgPageLoadTime', label: 'Average Page Load Time' }

```

In app/config/config.yml

```
sonata_admin:
    dashboard:
        blocks:
            -
                position: left
                type: sonata.admin.block.admin_list
            -
                position: right
                type: ersah.block.service.ga

```

You can so your GA block on your /admin/dashboard

###  Health Score

22

—

LowBetter than 21% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community5

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

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

### Embed Badge

![Health badge](/badges/ersah-ga-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/ersah-ga-bundle/health.svg)](https://phpackages.com/packages/ersah-ga-bundle)
```

###  Alternatives

[exsyst/swagger

A php library to manipulate Swagger specifications

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

Hubspot API client

24015.5M18](/packages/hubspot-api-client)[pocketmine/bedrock-protocol

An implementation of the Minecraft: Bedrock Edition protocol in PHP

172437.8k11](/packages/pocketmine-bedrock-protocol)[botman/driver-telegram

Telegram driver for BotMan

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

PHPackages © 2026

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