Recent Posts
- 10 Things To Do When Launching A Site
- Using PHP to connect to SFTP
- Asynchronous Virtual Pageviews with Google Analytics
- 5 Advanced Text Editing Keyboard Shortcuts
- Get the headers of a HTTP request with PHP
- How-to: Create PDF preview images in PHP – Part 2
- How-to: Create PDF preview images in PHP
- Quick Code: Get the domain name in JS
- Things to think about when designing a logo
- Javascript Array Functions
Topics
ImageXY
ImageXY - Mac OS X Batch Photo Resizer

Quickly and painlessly bulk resize images, change image formats and create web-friendly photos for your website.
Available on the Mac App Store!
Asynchronous Virtual Pageviews with Google Analytics
If you have moved over to the new Asynchronous Google Analytics (GA) tracking code you may have trouble finding how to create virtual pageviews as the manual seems to push you more towards using Events instead.
How do I tell if I’m using the new code?
Google provides a good step by step guide to work out which tracking code you’re using. The gist of it comes down to looking for the following piece of code in your <head> section:
var _gaq = _gaq || [];
If you see that piece of code, or any reference to ‘_gaq‘, then you’re using the newer asynchronous code.
New Asynchronous Virtual Pageview Code
Now that you know you’re using the newer asynchronous code, you will need to use the following snippet in your links to track virtual pageviews.
<a href="" onClick="javascript: _gaq.push(['_trackPageview', '/virtual-page']);">My Link</a>
If you’re not a fan of embedding JavaScript directly into the page (for graceful degradation) then you can call the same method within your external function:
function trackVirtualPageview(strPage){
_gaq.push(['_trackPageview', strPage]);
}