The new Analytics module

People following the development of Fork CMS probably noticed that we recently introduced a new Analytics module. We started from scratch to be able to use all the most recent Fork features.

What has been changed?

Since we were doing a full rewrite, we were able to change everything we wanted. Below are the most important changes:

Less features

We noticed that a lot of the features in the Analytics module were never used. The code was overly complex to provide all this functionality. We decided to throw away all this stuff and return to a single page dashboard and some widgets. It only contains the code needed to fetch data from Google Analytics and display it in graphs. This makes the module more maintainable and easier to keep bugfree.

New Google API

The old Google API version was not supported anymore by Google, so we needed to move on to Google API v3. We now use the official PHP Wrapper class for Google Analytics, which again makes sure we have to maintain less code ourselves. This is loaded through composer, so fetching new updates is really easy now!

New caching system

The old Analytics module used the "Loading" action and a cronjob to fetch data in the background from Google Analytics. Then some calculations were done on it and the result was eventually stored it in a cache file. This was not always working great, so we decided to use a completely different approach. Since we fetch less data, we can just do it in the action class itself, so no code is run in the background anymore. By fetching this data synchronously, we reduced the possible points of failure. We still cache the data, but using a new reusable Cache system that will be explained in an upcoming blogpost.

No more Classic Analytics

Since Google deprecated Classic Analytics, we decided to only support Universal Analytics.

Google Service Account

The new coupling uses a Google Service Account. This makes the authentication system a lot easier in our code. It only requires a one time authentication, so no more refresh tokens needed. The steps to couple your Analytics account are written out step by step in the Settings action, so it's easy to start using this module!

Cleaner code

The code has been fully cleaned up and makes great use of the newer functionalities of Fork CMS like module specific services, unit tests, the new fork.settings service and a lot more. This will make it easier  to extend the module if you want to add new functionality. We wanted our code to be understandable and inspiring to other developers.