Feb 25 2012

How to Track Your WordPress Plugin’s users?

Category: PHP,Programming,WordPressksg91 @ 7:59 pm

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. 🙂

Tags: , , , ,


Feb 23 2012

Tweet My Post 1.0 Available

Category: PHP,Programmingksg91 @ 11:11 pm

I have just released an update for Tweet My Post plugin for wordpress. If you are already using it, update it from Plugin menu. You can try plugin by searching for “Tweet My Post” in plugin directory or visit http://wordpress.org/extend/plugins/tweet-my-post/

New version doesn’t have changes to end user but I have updated code internally and added tracking system for me, so that I can analyze plugin usage.

Let me know if you face some problem or issue with this new update. Suggestions are most welcomed.

It’s really nice to see around 400 downloads in just 2 days. Thanks for the support guys. 🙂

 

Tags: , , , ,


Feb 19 2012

Tweet My Post – A WordPress Plugin

Category: PHP,Programmingksg91 @ 10:16 am

I also run a blog at http://NokiaTips.in and we have many authors there. I always wanted a plugin which auto-tweet our new post to our Twitter account @NokiaTips. There are several WordPress plugin available but I wanted more out of that. I wanted that, that tweet should also contain the twitter handle of Author, so that readers can know that post is authored by whom. I searched WordPress’ Plugin directory but couldn’t find one. So, I thought, better to create one, myself.

I have almost finished the plugin. Find its Git repo at Github – https://github.com/ksg91/Tweet-My-Post

I may have some bug. It’s beta release for now tagged 0.9.

If you have any suggestion, please let me know. You can also contribute to Plugin by forking the repo.

Feel free to try the plugin, after all, it’s free. 😉

Tags: , , , ,