Quick Hits: WordPress and Universal Analytics

Universal Analytics is an upgrade to the Google Analytics we’ve all been using for years, a welcome one at that. You can read more about it here and the KissMetrics blog also has a good write-up here. The gist is, we have more flexibility, in particular for pushing custom data (we had a limit of 5 before, now we have 40).

Whilst I don’t dig into the data on my blog too much, I do use it as a sandbox or place to experiment with new things, especially something like Universal Analytics. So if you’re already adding Custom Dimensions & Metrics¬†to your site, here are a few more (in this case, 3 metrics):

<?php if ( is_single() ) { ?>
 ga('set', 'metric1', <?php echo nt_ga_word_count(); ?>);
 ga('set', 'metric2', <?php echo nt_ga_post_age(); ?>);
 ga('set', 'metric3', <?php echo nt_ga_comment_count(); ?>);
<?php } ?>

As you can see, they’re specific to posts too. That’s the majority of my traffic, so I’ll start there.

Word Count

Is there a magic word count for articles? Does long copy work well? Why not find out? It certainly won’t give you definite answers, but this little snippet may help get you there quicker (rounded to the nearest 100th):

function nt_ga_word_count() {
 global $post;
 $id = $post->ID;
 $count = str_word_count( get_post_field( 'post_content', $id ) );
 return ceil( $count / 100 ) * 100;

Age of a Post

How evergreen is your content? Will the bounce rate increase and the average reading time decrease after a few months? This will count the age in months:

function nt_ga_post_age() {
 global $post;
 $id = $post->ID;
 $now = date('Y-m-d');
 $then = get_the_time('Y-m-d', $id);
 return (int)abs((strtotime($now) - strtotime($then))/(60*60*24*30));

Comment Count

Does social proof matter? Do more comments increase¬†trustworthiness? A similar concept could be applied to the amount of retweets or other social “counters”. Here’s the snippet (works with 3rd party providers that store comments to WP too, i.e. Disqus):

function nt_ga_comment_count() {
 global $post;
 $id = $post->ID;
 $comments = wp_count_comments( $id );
 return $comments->approved;

Here’s the gist with all 3. Are you using any others? Feel free to link them up.