Categories
Advanced Tutorials

Monitor WordPress Plugin Statistics

How to track your WordPress.org plugins statistics and display them as a widget within your own theme.

In this quick tutorial, I will show you how to track your WordPress.org plugins statistics and display them as a widget within your own theme.

Readers also enjoyed our detailed post on Extend EDD Invoices in your Language

The code below will be included in your functions.php but you can easily create a plugin using the same approach. Also, if you store the data into your database you can display daily, weekly or monthly trends for downloads, ratings, and trends.

In addition, there is an array with 1, 2, 3, 4, 5-star ratings which can be used and displayed as well.

Let us get started.

The Code

First, we need to add a couple of actions; the first one is to add some basic styling to our dashboard widget layout. And the second one creates and positions our widget within the Dashboard area.

Next, we have a plugin_tracker() function that will handle the actual data gathering from the WordPress plugin API and then display the HTML with formatted data for each plugin from the query.

Here is the URL we use to get the plugin data (this will give us the last 10 plugins from the author) https://api.wordpress.org/plugins/info/1.2/?action=query_plugins&request[author]=automattic

You can also use request[page]=2 if you want to get the next 10 results and so on.

For additional information, you can visit the older WordPress.org API page https://codex.wordpress.org/WordPress.org_API

Explore this highly recommended read on Time Investment Overview for Development

What’s next?

You can improve and modify the code above to get daily/weekly results, have pagination and track your plugin statistics within your own site.

Hope this was a useful quick tutorial.

‘Til the next one.

If you found this helpful, our comprehensive guide on Add License Key to Premium Theme/Plugin (1/3) has even more.

Leave a Reply

Your email address will not be published. Required fields are marked *