Analytics data are an important success factor for any plugin. Understanding how people are using your plugin is essential. Unfortunately WordPress does not provide an easy way to track usage statistics of plugins, this is where my library comes to the rescue. Thanks to the integration with Keen.io you can now start tracking data from your own plugins.
This is a tutorial aimed at plugin developers.
There are many different services out there providing a developers friendly api to track analytics. I've picked Keen.io because it has an SDK to build my own dashboard for displaying collected data. This tutorial will only show you how to track data, you'll then need to build the dashboard yourself.
How does it work?
The WP Plugin Usage Tracker library, will display an admin notice asking permission to start tracking data. If the user approves, collected data will be sent to your own Keen.io account once a month via WP Cron.
I personally hate bloating the admin panel with too many admin notices, so the library will display the notice after a certain amount of days from the plugin's installation date.
Open up a terminal and run
composer install to install the required libraries.
Initialize the class
You're done. The above configuration is saying to display the notice 10 days after the installation date being "16 July 2016". Your own plugin must somehow store the installation date somewhere (perhaps an option on plugin activation).
All parameters are described here.
It is recommended that you extend the
WP_Plugin_Usage_Tracker class so you can customize the admin message and the data collected. By default the class doesn't collect any sensitive data.
The class already provides methods to track:
If needed you can also change the event schedule from once a month to what you prefer.
If you've done everything correctly, you'll see your data into your Keen.io account ready to be manipulated.
Hope you'll find this library useful, if you have any suggestions, feel free to post them on Github.