Let me clear this straight, this post isn’t about to create WordPress plugin, but how to track your plugin users (blogs).
I have recently published my first plugin on WordPress’ repository at http://wordpress.org/extend/plugins/tweet-my-post/ and I felt really happy to see the downloads. However, what I was missing was, who are using my plugin. I am not sure if tracking the plugin users prohibited or not by WordPress but I am just tracking the url of blogs, that uses my plugin.
Let’s get back to the point – how to track our plugin’s users. This is a simple thing, but main thing is, this should strike your mind. I am posting this for those who haven’t thought (or not able make this happen). Useful also if you’re planning to make one too.
Plugin has a plugin_activation and plugin_deactivation hook, that means, you can register your functions that are executed every time, your plugin is activated and deactivated.
You need to add following code in your plugin file:
As I mentioned earlier, I have added log_operation($op) in the functions that are called while activation and deactivation. $op is operation, either activate or deactivate. Use appropriate operation in functions. Then whenever plugin is activated or deactivated, log_operation will be called. That function will create a cURL session and post the data of blog url and activation status to the page on our server. Now, what you need to do is to put following code in a page, let’s call it service.php, which is hosted at your server. What it will do is, add the status in our database. You need to put link to this page in above code as a value of $url variable.
The code is relatively simple to understand so I’m not explaining it at all. Just replace the database name and user details with yours. You will now need the database. Use following table:
Well, you are not ready to see, who are using your plugin. You can look into your database table and enjoy! 😀
If you’re lazy to open PhpMyAdmin and browse the database, simply make a file which fetches the data and display it. 😉
I have not added this in my initial release of plugin, so I can only track the users who are using it after Tweet My Post 1.0. Actually, I should be able to track old users too, because WordPress first deactivate plugin, update it and the reactivate it, so I should have the data of old users who have update the plugin but WordPress doesn’t execute activation and deactivation hook while updating plugin. I’m not sure if this is a bug or intentional, but I can’t know my old users unless they deactivate and reactivate the plugin.
Anyways, if you have any problem or query, please let me know in comments below or ping me @ksg91 on Twitter. 🙂
May 31st, 2012 12:59 am
Howdy! I would really hate for your plugin to get removed from the WordPress repository for violation of the rules, so I would highly suggest that you remove this code from your plugin, ASAP.
Tracking people without asking them is not cool.
June 1st, 2012 7:48 pm
That depends, plugin is already updated fixing the issue. And I am not spamming or tracking people for any other activity. I only gather their link and their activation status, means no harm to their privacy. Thank you for reporting it to wordpress!
December 6th, 2013 2:56 am
Even if you aren’t spamming, you have to ask the user for their permission before sending any information to your own server. See the WordPress rules here: http://wordpress.org/plugins/about/guidelines/
Specifically Rule 7 Part 1:
“No unauthorized collection of user data. For example, sending the admin’s email address back to your own servers without permission of the user is not allowed; but asking the user for an email address and collecting if they choose to submit it is fine. All actions taken in this respect MUST be of the user’s doing, not automatically done by the plugin.”
January 6th, 2014 5:20 pm
Hi Tyler,
Thanks for the heads up. That tracking code was already removed once I came to know about that guideline.