Laravel

Build your own google analytics dashboard with Laravel

2019-03-07

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

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.

As a developer, I always see the problem for creating images/banners whenever I post some content online.

Even for simple designs I always needed to open figma or search online, so I thought of automating it.

I've build BannerPot to solve this problem, would you like to give it a try?

Ramesh from BannerPot

Ramesh Mhetre

Maker of BannerPot