Google Analytics Real Time Statistics using a Javascript Bookmarklet

There are many companies which develop web analytics software suites, hoping that they would upstage Google Analytics (some day). Their main claim being that they are ‘real-time’, while Google analytics is not. However that’s not true, because Google Analytics does collect stats in near real-time, but for some reason they never show the latest stats by default, it’s always a day old. If you want to see your latest stats, you can use the date selector combo-box to change the date range to include today’s stats. Here’s a tutorial which shows how. However its cumbersome to do that all the time. So I created (mostly stole) a bookmarklet to always include the latest stats. Continue reading

Patch for YOURLS: WordPress to Twitter – Filter Hook to Control the URL that is Fed into Yourls

Yourls: WordPress to Twitter is a wonderful plugin which bridges yourls with wordpress. In addition to yourls statistics, I also wanted to track the clicks on the shortened link using Google Analytics. This requires addition of Google Analytics tags to the permalink URL which then gets shortened by yourls. Hence I modified the plugin code so that the URL that is fed into yourls can be modified the wordpress way – using a filter hook. Here’s the patch that I made.

diff -aurN yourls-wordpress-to-twitter/inc/core.php /home/pratikmsinha/
--- yourls-wordpress-to-twitter/inc/core.php  2010-03-09 12:37:14.000000000 -0800
+++ /home/pratikmsinha/  2010-07-01 18:23:39.000000000 -0700
@@ -61,7 +61,8 @@
  global $wp_ozh_yourls;
  $post_id = $post->ID;
- $url = get_permalink( $post_id );
+ //$url = get_permalink( $post_id );
+ $url = apply_filters('yourls_blog_post_url', get_permalink($post_id));
  if ( $post->post_type != 'post' && $post->post_type != 'page' )
@@ -71,7 +72,8 @@
  $title = get_the_title($post_id);
- $url = get_permalink ($post_id);
+ //$url = get_permalink ($post_id);
+ $url = apply_filters('yourls_blog_post_url', get_permalink($post_id));
  $short = wp_ozh_yourls_get_new_short_url( $url );
  // Tweet short URL ?
diff -aurN yourls-wordpress-to-twitter/plugin.php /home/pratikmsinha/
--- yourls-wordpress-to-twitter/plugin.php  2010-03-09 12:37:14.000000000 -0800
+++ /home/pratikmsinha/  2010-07-01 18:26:14.000000000 -0700
@@ -68,7 +68,8 @@
  if ( !$short && !is_preview() ) {
    // short URL never was not created before, let's get it now
-   $short = wp_ozh_yourls_get_new_short_url( get_permalink($id), $id );
+   $url = apply_filters('yourls_blog_post_url', get_permalink($id));
+   $short = wp_ozh_yourls_get_new_short_url( $url, $id );
  return $short;

To use the above patch, copy-paste the code into a file, lets say yourls.patch. Go into the yourls plugin directory (wp-content/plugins/yourls-wordpress-to-twitter/) and execute the following command.

patch -p1 < yourls.patch

Do ensure that you use the correct path to yourls.patch.