Event Tracking With Google Analytics
Monday, November 30th, 2009Google Analytics is a very popular tool for tracking visits, pageviews, and lots of other metrics for your website. Here’s a handy little trick which allows you to track any event you want on your site, a click on a specific link for example, and have it integrated into your analytics data.
1) First, make sure you are already using Google Analytics on your site (or the page that you want to track events).
2) Second, add this snippet just below the Google Analytics code:
<script type=”text/javascript”>
function trackEvent(category,url,description) {
try {
pageTracker._trackEvent(category, description, document.location.pathname);
setTimeout(’document.location = “‘ + url + ‘”‘, 100);
} catch(err){}
}
</script>
4) Whenever you want to track something, you need to add a call to trackEvent, for example:
<a onclick=”trackEvent(’Outbound Links’,'http://google.com’,'Google’);return false;” href=”http://google.com”> Google </a>
5) Now log into Google Analytics, click on ‘Content’ -> ‘Event Tracking’ you will be able to see clicks on the above link to Google (you might not see it right away!)
Happy tracking!
Displaying code in posts
Tuesday, November 10th, 2009Assuming you write posts in the HTML view (as opposed to Visual), a quick trick for displaying code in your Wordpress posts is to switch to Visual view, enter the code, and then switch back to HTML view. This will automatically translate the code into non-executable code which will be displayed in your post. Try it out by creating a new post, then switching to Visual view and copy/paste this code:
<link rel=”pingback” href=”<?php bloginfo(’pingback_url’); ?>” />
Then switch back to HTML and you will see all the characters are properly escaped, that’s how I wrote this post.
Happy escaping!
