All Projects → panakour → google-analytics

panakour / google-analytics

Licence: MIT license
Get data from google analytics (API v4) using PHP

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to google-analytics

roku-libs
Compilation of utilities for Roku development
Stars: ✭ 47 (+113.64%)
Mutual labels:  google-analytics
analytics
A Flarum extension that provides your forum piwik's and google's analytics features
Stars: ✭ 32 (+45.45%)
Mutual labels:  google-analytics
thvu-blog
My digital home on the internet.
Stars: ✭ 51 (+131.82%)
Mutual labels:  google-analytics
Trackie
A Chrome extension to enhance debugging of some frequently-used tag management platforms (Google Tag Manager, Tealium, Commanders Act, DTM) in combination with some frequently-used tags (Google Analytics, Google Analytics 4, GA Audiences, Ddm, Criteo, Adobe Analytics/Omniture, Floodlight, Comscore, Facebook, Bluekai, Youbora, Kinesis, Webtrekk, …
Stars: ✭ 23 (+4.55%)
Mutual labels:  google-analytics
scripts
Open Source Public Scripts for Simple Analytics
Stars: ✭ 62 (+181.82%)
Mutual labels:  google-analytics
vue-seo-friendly-spa-template
Vue.js PWA/SPA template initially scaffolded with vue-cli and configured for SEO. Makes use of prerendering and other techniques/packages in order to achieve a perfect "Lighthouse Score".
Stars: ✭ 41 (+86.36%)
Mutual labels:  google-analytics
hubot-analytics
📈 A hubot script to get google analytics reports
Stars: ✭ 16 (-27.27%)
Mutual labels:  google-analytics
hyde-hyde
A cool theme inspired by spf13's Hyde theme
Stars: ✭ 234 (+963.64%)
Mutual labels:  google-analytics
ping
📊 Your very own Google Analytics replacement, without all of the Google. Simple as pie.
Stars: ✭ 93 (+322.73%)
Mutual labels:  google-analytics
analytics-js-without-segment
A toolset to use Segments open-source analytics library (analytics.js) WITHOUT using the paid Segment service (segment.com). To be used with your favorite analytics-tools like Google Analytics, Mixpanel, Hotjar, etc.
Stars: ✭ 47 (+113.64%)
Mutual labels:  google-analytics
django-sitemetrics
Reusable application for Django that offers easy integration with different site metrics service providers.
Stars: ✭ 41 (+86.36%)
Mutual labels:  google-analytics
nextsss
Next.js static site starter including full setup for TypeScript, Tailwind CSS, Google Analytics, Next SEO, etc.
Stars: ✭ 80 (+263.64%)
Mutual labels:  google-analytics
Nebula
Nebula is a WordPress theme framework that focuses on enhancing development. The core features of Nebula make it a powerful tool for designing, developing, and analyzing WordPress websites consistently, yet its deliberately uncomplicated code syntax also serves as a learning resource for programmers themselves.
Stars: ✭ 120 (+445.45%)
Mutual labels:  google-analytics
Google-Analytics-for-OS-X
Google Analytics SDK for OS X
Stars: ✭ 51 (+131.82%)
Mutual labels:  google-analytics
auto-analytics
UNMAINTAINED! - Complete Google Analytics, Mixpanel, KISSmetrics (and more) integration for JavaScript applications.
Stars: ✭ 28 (+27.27%)
Mutual labels:  google-analytics
react-native-base-project
Base react native application for scalable project using Redux + React Navigation + Code Push + Realm + Axios + i18n + Google Analytics + Facebook login with fbsdk...
Stars: ✭ 31 (+40.91%)
Mutual labels:  google-analytics
universal-ga
Universal Google Analytics module for node
Stars: ✭ 13 (-40.91%)
Mutual labels:  google-analytics
google-analytics-with-angular
Using Google Analytics with Angular
Stars: ✭ 17 (-22.73%)
Mutual labels:  google-analytics
streamlit-analytics
👀 Track & visualize user interactions with your streamlit app
Stars: ✭ 92 (+318.18%)
Mutual labels:  google-analytics
android-aop-analytics
Demo application that implements Google Analytics tracking in an aspect-oriented way using AspectJ.
Stars: ✭ 31 (+40.91%)
Mutual labels:  google-analytics

StyleCI Latest Stable Version Total Downloads License

Get easily whatever data you want from google analytics API V4 using laravel php framework.

This package helps php developers to use Google Analytics API V4 with convenient way. The code is clean and was written with good OOP practices. Any help to improve this package would be appreciated.

The package is compatible with laravel framework.

Installation

Install the package via composer:

composer require panakour/analytics

To use it with laravel add the GoogleAnalyticsServiceProvider to the config/app.php:

'providers' => [
...
Panakour\Analytics\GoogleAnalyticsServiceProvider::class
]

If you want to use the facade of the package add it to the config/app.php:

'aliases' => [
...
'Analytics' => Panakour\Analytics\Facades\Analytics::class
]

Copy the analytics config file with the command:

php artisan vendor:publish --provider="Panakour\Analytics\GoogleAnalyticsServiceProvider"

For those who have a credential with google analytics api continue here otherwise look at how to create credential with google analytics api.

Be sure that you have service-account-credentials.json file within storage\app\google-analytics\.

Add the view id to .env file:

GOOGLE_ANALYTICS_VIEW_ID=324235464

Usage

You can get analytics data simply using the facade

Panakour\Analytics\Facades\Analytics

To get all sessions of the last week

Analytics::get();

To get all sessions depends on the specific date range
Analytics::setDateRange('2016-10-01', '2016-11-25');
Analytics::get();
To get whatever data you want
Analytics::setDateRange('2016-10-01', '2016-11-25');
Analytics::setMaxResults(20);
Analytics::setMetrics(['ga:entrances', 'ga:pageviews', 'ga:bounceRate']);
Analytics::setDimension(['ga:pagePath', 'ga:pageTitle']);
Analytics::setDimensionFilter('ga:pagePath', 'REGEXP', '/i-want-to-get-all-data-that-has-this-page-path');
Analytics::setOrder('ga:pageviews', 'VALUE', 'DESCENDING');
return Analytics::get();

setMetrics and setDimension methods accept an array containing the wanted metrics and dimension. Available metrics and dimensions

setDimensionFilter accept 3 parameters. First parameter get the dimension name in which you want to filter analytics data. Second parameter get the operator (REGEXP, BEGINS_WITH, ENDS_WITH and more) you want. Third parameter get the expression. For example if you want to get all analytics data in which the page path include play or simple words you can use: Analytics::setDimensionFilter('ga:pagePath', 'REGEXP', '(\/play\/|\/simple\/)');

If you want to get analytics data for multiple pages in a single request by their exact paths, you can use the 'IN_LIST' operator and pass an array of paths as the third parameter. E.g. Analytics::setDimensionFilter('ga:pagePath', 'IN_LIST', ['/i-want-data-for-this-path', '/and/this-path-too']);

setOrder method accept 3 parameters. First parameter get the name in which you want to order the data. Second get OrderType usually VALUE. Third get the SortOrder usually ASCENDING or DESCENDING.

Get data using Analytics contract

Panakour\Analytics\Contracts\Analytics

Instead of facade you can get analytics data using the Analytics interface:

use Panakour\Analytics\Contracts\Analytics;

class GoogleAnalyticsController
{
    //inject analytics interface
    public function get(Analytics $analytics)
    {
        $analytics->setDateRange('2016-12-01', '2016-12-20');
        $analytics->setMaxResults(11);
        $analytics->setMetrics(['ga:pageviews', 'ga:uniquePageviews', 'ga:avgTimeOnPage', 'ga:entrances', 'ga:bounceRate']);
        $analytics->setDimension(['ga:pagePath', 'ga:pageTitle']);
        $analytics->setDimensionFilter('ga:pagePath', 'REGEXP', '(\/this-value-in-path\/|\/or-this-value-in-path\/)');
        $analytics->setOrder('ga:pageviews', 'VALUE', 'DESCENDING');
        return $analytics->get();
    }
}    

Create credential with google analytics api v4

Guide from google analytics api v4: https://developers.google.com/analytics/devguides/reporting/core/v4/quickstart/service-php

  • Create a project using Google API Console:
  • Open the Service accounts page. If prompted, select your project that you have created and click open.
  • Click Create service account.
  • In the Create service account window, type a name for the service account, and select Furnish a new private key. In the key type select JSON and then click create. If you want to grant G Suite domain-wide authority to the service account, also select Enable G Suite Domain-wide Delegation.
  • Copy Service account ID you have created and then go to google analytics admin panel select User Management and add the account you have copied with the permissions that you want.
  • Your new public/private key pair is generated and downloaded to your machine; it serves as the only copy of this key. You are responsible for storing it securely.
  • Rename the json file to service-account-credentials.json.
  • To get the view id you can use the account explorer or from google analytics view settings from admin panel.
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].