Setting up Google Analytics on a website is super simple. One line of code, copy and paste it in to the site and away you go. Slightly more complicated tasks such as tracking goal completions and interactions with dynamic content is more difficult but certainly not impossible.
Something I had not yet done, until today, was to track interactions with embedded YouTube videos. By interactions I mean playing videos, stopping them before the end and of course watching the video all the way to the end.
The site in question was a WordPress site. Initially I thought this was going to be fairly simple, just swap the existing YouTube plugin for a more advanced offering that will have Google Analytics built in. However, my search for such a plugin was fruitless and the best I could find was a now defunkt (it even had defunkt in the title) Wordpress plugin that claimed it would add YouTube video tracking, and it did not.
Now one thing I love about web development, and indeed most disciplines of software development is sharing. For almost any problem you can think of, someone, somewhere has already solved it and has been kind enough to share their solution.
And by fantastic I don't mean the code is of great quality (I'm sure it is) or it does anything gimmicky. I mean it just works!
Lo and behold, it detects you Google Analytics code and any YouTube videos on the page and then sends off the data to your Google Analytics account. Brilliant!
Debug Google Analytics
How do you know that it's working for sure without waiting for the data to turn up in Google Analytics? Luckily I've got just the ticket. Grab yourself a copy of this Google Chrome Add-on:
It's called the Google Analytics Debugger and does exactly what it says on the tin. When enabled, open up your Chrome developers console and you'll see all the information your site is firing off to Analytics. Try it for yourself with the YouTube solution above and you'll see it telling Google what video you're watching, how much you've watched and when you've paused it. Fantastic!