All Projects → mediafigaro → Google Analytics Api Symfony

mediafigaro / Google Analytics Api Symfony

Licence: mit
Google Analytics API Symfony Bundle

Projects that are alternatives of or similar to Google Analytics Api Symfony

Generates documentation for your REST API from annotations
Stars: ✭ 2,009 (+4572.09%)
Mutual labels:  api, symfony, symfony-bundle
Symfony Jsonapi
JSON API Transformer Bundle for Symfony 2 and Symfony 3
Stars: ✭ 114 (+165.12%)
Mutual labels:  api, symfony, symfony-bundle
Implements a Refresh Token system over Json Web Tokens in Symfony
Stars: ✭ 425 (+888.37%)
Mutual labels:  api, symfony, symfony-bundle
The server component of API Platform: hypermedia and GraphQL APIs in minutes
Stars: ✭ 2,004 (+4560.47%)
Mutual labels:  api, symfony, symfony-bundle
OAuth client integration for Symfony. Supports both OAuth1.0a and OAuth2.
Stars: ✭ 2,150 (+4900%)
Mutual labels:  api, symfony, symfony-bundle
Use the Google Analytics API from R
Stars: ✭ 213 (+395.35%)
Mutual labels:  api, google, analytics
Api Platform
Create REST and GraphQL APIs, scaffold Jamstack webapps, stream changes in real-time.
Stars: ✭ 7,144 (+16513.95%)
Mutual labels:  api, symfony, symfony-bundle
Api Example
WIP: Just sample app with API
Stars: ✭ 12 (-72.09%)
Mutual labels:  api, symfony
Simple, open-source, lightweight (< 1 KB) and privacy-friendly web analytics alternative to Google Analytics.
Stars: ✭ 9,469 (+21920.93%)
Mutual labels:  analytics, google-analytics
Enables ICU message formatting for translations in Symfony applications.
Stars: ✭ 27 (-37.21%)
Mutual labels:  symfony, symfony-bundle
Vendor-agnostic analytics for Angular2 applications.
Stars: ✭ 963 (+2139.53%)
Mutual labels:  analytics, google-analytics
Fathom Lite. Simple, privacy-focused website analytics. Built with Golang & Preact.
Stars: ✭ 6,989 (+16153.49%)
Mutual labels:  analytics, google-analytics
Symfony Crawler Bundle
Implements the crawler package into Symfony
Stars: ✭ 8 (-81.4%)
Mutual labels:  symfony, symfony-bundle
Yunmai Data Extract
Extract your data from the Yunmai weighing scales cloud API so you can use it elsewhere
Stars: ✭ 21 (-51.16%)
Mutual labels:  api, google
🌎 GoLang package that provides an easy way to use the Google Geocoding API
Stars: ✭ 23 (-46.51%)
Mutual labels:  api, google
Aurelia Google Analytics
An plugin that adds Google Analytics page tracking to your project.
Stars: ✭ 28 (-34.88%)
Mutual labels:  analytics, google-analytics
Symfony bundle which provides integration of Sphinx search engine with Symfony using SphinxQL
Stars: ✭ 18 (-58.14%)
Mutual labels:  symfony, symfony-bundle
Generates Symfony2 documents, forms and CRUD for MongoDB documents
Stars: ✭ 27 (-37.21%)
Mutual labels:  symfony, symfony-bundle
LexikPayboxBundle eases the implementation of the Paybox payment system
Stars: ✭ 42 (-2.33%)
Mutual labels:  symfony, symfony-bundle
☁️ A distributed cloud based lazy drive to files integrated with Dropbox, Google Drive.
Stars: ✭ 36 (-16.28%)
Mutual labels:  api, google

Google Analytics API v4 Symfony bundle


Latest Stable Version Total Downloads Latest Unstable Version License Monthly Downloads Daily Downloads composer.lock


At MEDIA.figaro, the advertising department of the french newspaper Le Figaro and part of the Figaro Group (CCM Benchmark), we use this bundle to monitor our digital platforms with Google Analytics.

It's a simple package that wraps the Google Analytics API version 4, and that gives you all the information to go straight to the point of getting some main metrics from GA.

Development by Kendrick

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.

You can use the debug routes to go live and test a profile (ex id : 111111111, here with Docker) :



composer require mediafigaro/google-analytics-api-symfony

without Flex, add to /app/AppKernel.php :

$bundles = [
    new MediaFigaro\GoogleAnalyticsApi\GoogleAnalyticsApi(),



Adding filterMetric and filterDimension to getDataDateRangeMetricsDimensions method which is a simple wrapper to Google Api Client ex :

$analyticsService = $this->get('google_analytics_api.api');

$data = $analyticsService->getDataDateRangeMetricsDimensions(
    'myanalyticsviewid',    // viewid
    '2018-01-01',   // date start
    'today',        // date end
    ['sessions','users','percentNewSessions','bounceRate'],             // metric
    ['source','campaign','fullReferrer','sourceMedium','pagePath'],     // dimension
    [   // order metric and/or dimension
        'fields'    =>  ['sessions'],
        'order'     =>  'descending'
    [   // metric
        'metric_name'       =>  'sessions',
        'operator'          =>  'LESS_THAN',
        'comparison_value'  =>  '100'
    [   // dimension
        'dimension_name'    =>  'sourceMedium',
        'operator'          =>  'EXACT',
        'expressions'       =>  [
            'trading / native'


Symfony 4 simple adaptation with a public service and a new public method that takes in charge metrics and dimensions with sorting options :


Query explorer to build your query.

$viewId :

$dateStart :


$metrics: (without the 'ga:', array or string)

$dimensions: (without the 'ga:', array or string)


without the 'ga:', array or string, eg. :

    'fields'    =>  ['pagePath','sessions'], // or : 'sessions'
    'order'     =>  'descending'

example :

$analyticsService = $this->get('google_analytics_api.api');

$data = $analyticsService->getDataDateRangeMetricsDimensions(
        'fields'    =>  ['pagePath','sessions'],
        'order'     =>  'descending'

$data :

array(329) {
  array(2) {
    array(4) {
      string(5) "16738"
      string(5) "15602"
      string(17) "88.39168359421676"
      string(17) "83.95268251881946"
    array(5) {
      string(7) "trading"
      string(7) "my-campaign"
      string(7) "trading"
      string(16) "trading / native"
      string(50) "/my-url"
  array(2) {
    array(4) {
      string(4) "6506"
      string(4) "6200"
      string(17) "87.05810021518599"
      string(17) "87.74976944359054"
    array(5) {
      string(7) "trading"
      string(7) "my-campaign-2"
      string(7) "trading"
      string(19) "trading / 320x480-1"
      string(50) "/my-url-2"

Session - Dimensions & Metrics Explorer :


First version with a quick connector to consume Google Analytics v4 with Google API client with getDataDateRange private method (that handles only metrics), wrapped with some public methods to get a quick access to main metrics such as sessions (eg. getBounceRateDateRange($viewId,$dateStart,$dateEnd)), bounce rate, average time on page, page view per session, new visits, page views and average page load time. Debug route included for a simple setup and test.



Set the relative path for your json key (set it on your server, better not into your repository) from execution path, ex: /data/analytics/analytics-27cef1a4c0fd.json.


google_analytics_json_key: "../data/analytics/analytics-27cef1a4c0fd.json"


    google_analytics_json_key: "%google_analytics_json_key%"

Google API key

Generate the json file from by creating a project, check the documentation :

Google Analytics API v4

List of metrics for report building with search engine : eg. ga:sessions, ga:visits, ga:bounceRate ...

Objects :

(example : ReportData object :

Samples :


Add the debug routes for development purposes :


    resource: "@GoogleAnalyticsApi/Resources/config/routing_dev.yml"

000000000 = profile id that you can find in the analytics URL, p000000000 :

Result of this debug page :



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

    "message": "Google Analytics Reporting API has not been used in project xxxxxx-xxxxxx-000000 
    before or it is disabled. Enable it by visiting 
    then retry. If you enabled this API recently, wait a few minutes for the action to propagate 
    to our systems and retry.",
    "domain": "global",
    "reason": "forbidden"


Call the service :

$analyticsService = $this->get('google_analytics_api.api');
$analytics = $analyticsService->getAnalytics();

Use the method helpers to get the main metrics within a date range :

$viewId = '000000000'; // set your view id

// get some metrics (last 30 days, date format is yyyy-mm-dd)
$sessions = $analyticsService->getSessionsDateRange($viewId,'30daysAgo','today');
$bounceRate = $analyticsService->getBounceRateDateRange($viewId,'30daysAgo','today');
$avgTimeOnPage = $analyticsService->getAvgTimeOnPageDateRange($viewId,'30daysAgo','today');
$pageViewsPerSession = $analyticsService->getPageviewsPerSessionDateRange($viewId,'30daysAgo','today');
$percentNewVisits = $analyticsService->getPercentNewVisitsDateRange($viewId,'30daysAgo','today');
$pageViews = $analyticsService->getPageViewsDateRange($viewId,'30daysAgo','today');
$avgPageLoadTime = $analyticsService->getAvgPageLoadTimeDateRange($viewId,'30daysAgo','today');


You are welcome to contribute to this small Google Analytics v4 wrapper, to create more helpers or more.

More tools

Try the Symfony Debug Toolbar Git : and the docker Service Oriented Architecture for Symfony :


French tutorial by Jérémy PERCHE, SUPINFO student.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].