Your Members and Real Time Stats
Woopra is a real time stats tracking software aimed at bloggers, Your Members is a WordPress membership plugin. Combine the two you got some pretty impressive member stats.
Caution – Remember any implementation like this will have implications on your users privacy, after all we are deliberately identifying individual users and tagging them. Make sure your privacy polices are current and accurate. Also bare in mind Woopra is a third party when it comes to user collection policies check with the information governor within your country as to what info you can and can’t send to them.
Woopra – Real time stats

Woopra is a real time stats service for your site, aimed at bloggers. Woopra tracks all sorts of interesting things and displays them on their web interface or via their software client that if nothing else looks impressive. One of the key features for Woopra is their live view which allows you to see users as they are on the site and interacting with it.
Woopra and WordPress
Woopra has a WordPress plugin but since the vast majority of blogs have one user and don’t require users to log in the Woopra plugin ignores logged in users. Great for blogs terrible for membership sites. So what are we going to do? Well lets write our own Woopra WordPress Plugin! We will be keeping it simple but introduce Woopra but also how you can pass YM variables outside of Your Members own pages.
Why use a plugin?
Wordpress offers several locations for putting your own code without resorting to a plugin including functions.php but on the whole a plugin is a good place to store your own code.
- Its centralised
- When you update WordPress you don’t loose it
- When you make theme changes you don’t loose it
Plugins normally live in wp-content → plugins so lets start by creating a simple plugin.
<?php
/*
Plugin Name: Woopra for Your Members
Version: 0.1
Plugin URI: http://www.newmedias.co.uk
Description: Real time stats with enhanced info from Your Members
Author: Cambridge New Media Services
Author URI: http://www.newmedias.co.uk
*/
//Put Into the Footer
add_action('wp_footer','woopra_stats_display');
?>
The most important bit of code is ‘add_action’ which tells WordPress to run our function within the footer on all pages outside of the admin area.
add_action('wp_footer','woopra_stats_display');
Checking for Your Members
since this plugin is primarily using Your Members we probably should check its activated and working. Otherwise our plugin may cause an error when it tries to pull data that is not there.
Thankfully we can identify if Your Members is running easily using:
function woopra_stats_display(){
if(!get_option('ym_sys')) //check if Your Members is installed
{
function1(); //run if Your Members is not installed
}
else
{
function2(); //run if Your Members is installed
}
}
Understanding the Woopra Javascript code
Woopra uses javascript for tracking like most analytical systems including google Analytics and the basic code looks like
<script type="text/javascript">
var woopra_id = '000000000';
</script>
<script src="http://static.woopra.com/js/woopra.js" type="text/javascript"></script>
Where the var woopra is a user id to associate site to stats, this code alone tells us a lot of information, including browser details, indviduals ip, where they have been and going. But we can also augment the information with additional Visitor information and Events.
Visitor Info – Woopra allows us to add other information related to the user what that information is up to it is important to note barring some reserved values this data is not stored on Woopra servers and is only shown on live view (which is a shame but it may change).
To add additional visitor info:
var woopra_visitor = new Array(); woopra_visitor['my_key'] = 'my_value';
The var woopra_visitor generates a new temporary holding array and then the values are assigned into this array. Woopra has reserved 3 special array keys these are:
- name
- avatar
Unlike other visitor data collected in the array this info is stored on Woopra servers and can be filtered for, name in effect becomes a tag (just like you would normally tag a user).
Woopra Events – Events are short notes that appear in the live view when triggered a good example is you might have a Woopra event set up on a thankyou screen after purchase to notify you in real time that a sale has occured.
Like collecting visitor data events are handled by a javascript array:
var woopra_event = new Array(); woopra_visitor['my_event'] = 'Something Happened';
Both arrays can be used together so for example:
<script type="text/javascript">
var woopra_id = '00000000';
var woopra_visitor = new Array();
var woopra_event = new Array();
woopra_visitor['name'] = 'Joe';
woopra_event['purchase'] = 'Joe just bought something!';
</script>
<script src="http://static.woopra.com/js/woopra.js" type="text/javascript"></script>
Integrating Your Members Data with Woopra
We can populate the Javascript array with data from WordPress and Your Members using PHP so for example with name and email we can pull username and email directly from the db. First we need to know who the user is so:
get_currentuserinfo(); global $current_user, $user_data;
Finds the current user and makes their data available to us which allows us to add username and email to the javascript array:
echo 'woopra_visitor["name"] = "'. $userdata->user_login .'";'; echo 'woopra_visitor["email"] = "'. $email = $current_user->user_email .'";';
We could choose to use a Your Members Custom Field for name (see later) but for now username is name and will be stored on the Woopra servers. Next it might be useful to know what account type the user is. To do this we call the Your Members function $ym_current_account_type() which returns oddly enough the account type:
$ym_current_account_type = ym_get_user_account_type($user->ID); echo 'woopra_visitor["account_type"] = "'. $ym_current_account_type .'";';
Remember unlike the previous two because account_type is not a reserved key name it won’t be stored on Woopra servers and so will only be available in live view.
Adding Your Members Custom Profile Fields
Your Members allows you to capture information from users either at registration or from the user profile. To add or change custom profile fields login into your admin area.
wp-admin -> Your Members – Custom Profile Fields

once there you can add fields at the bottom of the screen to make them active drag the new field from the blue box to the green box and click update.
Then within the Woopra Plugin we can call these active custom fields by:
ym_custom_fields = ym_get_custom_field_array($user->ID); echo 'woopra_visitor["my_field"] = "'. $ym_custom_fields['customfieldname'] .'";';
where customfieldname is the name of the custom Field you want to display, if you set up a custom field called name you could for example use that as the name kek value instead of username.
Woopra/Your Members Plugin
You can download the example code in this tutorial from here

Your Members / Woopra Analytics Plugin by Cambridge New Media Services is licensed under a Creative Commons Attribution-Share Alike 2.0 UK: England & Wales License.
, Don’t forget to change your Woopra ID in the define.
Ways to expand? Well how about adding events on after purchase of a Pay Per Post or notification of a new member so you can say hi. The possibility are pretty open for more information on Woopra Javascript code check out the Woopra Developers Section and if your after help why not try our own Developers Section in the forums.