A while ago I was looking for a free alternative to Google Analytics for a side project of mine.
I tried Countly but it uses MongoDB which I could not make it work easily for an ARM 32bit, to try it with on my Raspberry Pi 3.
So I stumble upon Matomo (ex Piwik).
It uses MySQL which can easily run on the Raspberry.
However I could not find a simple Docker to try it out.
So I wrote a docker compose for Matomo, you can find it on my github: https://github.com/manhluong/matomo_docker
Just clone the repo, then run:
docker-compose -f x86/docker-compose.yml --project-director ./matomo up
And you will see the service coming up.
At that point if you go to http://localhost:8080/ you should see the initial Matomo setup screen:
To try on an arm v7 32 bit architecture (the Raspberry Pi 3), just run the docker-compose contained in the other folder:
docker-compose -f arm32v7/docker-compose.yml --project-director ./matomo up
During the setup, as “Database Server”, use whatever is defined in the docker-compose:
Otherwise you might see an error:
I put some default test credentials in the docker-compose, you can change them as fit.
I also installed Matomo geolocation, but you will have to enable it via the settings:
How to test it
In order to test it, I have to figure out the parameters to send to the request.
So I look at the source code of the Android SDK.
The starting point is the README.
From there I understood that the Tracker concept is the entry point of the analytics flow: https://github.com/matomo-org/piwik-sdk-android/blob/master/piwik-sdk/src/main/java/org/piwik/sdk/extra/TrackHelper.java#L66
Tracker that will call a Dispatcher to send a TrackMe object.
The DefaultDispatcher convert a TrackMe to a lower level abstraction Event object.
Those Events are used by PacketFactory to create Packets.
DefaultPacketSender finally open the internet connection and send the Packets.
The query params that we were looking for are these ones: https://github.com/matomo-org/piwik-sdk-android/blob/master/piwik-sdk/src/main/java/org/piwik/sdk/QueryParams.java
So to test, just do these curl
commands:
curl http://localhost:8080/piwik.php?idsite=1&uid=67890&url=http://localhost&action_name=Test%20uid&rec=1
curl http://localhost:8080/piwik.php?idsite=1&uid=12345&url=http://localhost&action_name=Test%20another%20uid&rec=1
After a couple of calls, you should see the events in the Matomo dashboard:
Matomo also offers iOS and Android apps.
Just point the app to your Matomo deployment and you should see the events:
About the Docker image
I built and published a Docker image containing the Matomo code: https://hub.docker.com/r/luongbui/matomo/
It extends another one I made that has PHP7, Nginx and MySQL: https://hub.docker.com/r/luongbui/php-7-fpm-mysql/
I also made an arm v7 32bit version of the Matomo Docker image: https://hub.docker.com/r/luongbui/arm32v7-matomo/
Which extends the arm version of the one that contains PHP7, Nginx and MySQL: https://hub.docker.com/r/luongbui/arm32v7-php-7-fpm-mysql/
Also the docker-compose uses volumes.