Build your own google analytics dashboard with Laravel

Build your own google analytics dashboard with Laravel

Mar 10, 2019 / Ramesh Mhetre

Using google analytics dashboard on a regular basis can be a cumbersome for people like me, especially when you just need to check a few metrics regularly. I made my own mini dashboard to only show required data from google analytics the way I wants to see it.

We have fetched data from Google Analytics API using package spatie/laravel-analytics. Like all other packages from spatie, this package is also well documented & updated. It took me a time of one nice coffee to build highcharts graph with this API which becomes really handy at the end.

Check out the documentation on GitHub to learn more about how you can set up this package.

Some handfull functions from this package:

  • Fetch pageviews data for last 30 days
$analyticsData = Analytics::fetchVisitorsAndPageViews(Period::days(30));

  • This package also has set of handull functions like
public function fetchMostVisitedPages(Period $period, int $maxResults = 20): Collection;

public function fetchTopReferrers(Period $period, int $maxResults = 20): Collection;

public function fetchTopBrowsers(Period $period, int $maxResults = 10): Collection;

To perform all other queries on the Google Analytics resource you can call performQuery.

public function performQuery(Period $period, string $metrics, array $others = [])

// Query example
$analyticsData = Analytics::performQuery(
    Period::years(1),
    'ga:sessions',
    [
        'metrics' => 'ga:sessions, ga:pageviews, ga:users',
        'dimensions' => 'ga:yearMonth'
    ]
);

Google Core Reporting API provides more information about which metrics & dimensions can be used to build your own query.

Laravel

Similar Articles

What is new in Laravel 5.8.4

What is new in Laravel 5.8.4

Here is what is new in Laravel v5.8.4
Read more...
Build your own google analytics dashboard with Laravel

Build your own google analytics dashboard with Laravel

Using google analytics dashboard on regular basis can be a cumbersome for people like me, specially when you just need to check few metrics regularly
Read more...
Vue.js Packages(1) Vue.js News(1) Vue.js(3) Laravel Packages(2) Laravel News(3) Laravel(3) Angular Packages(0) Angular News(0) Angular(3)