Google Analytics is good at what it does. I mean really good. So good that I’ve been using it for over five years (exactly how long is a mystery to me but I know it’s been at least this long) and I haven’t ever thought about switching. The thing I like most about it is how brain dead simple it is to setup. It’s basically a three step process:
- Get Google Analytics Tracking Number
- Paste Code Into Site
- Browse Reddit for a couple hours
But what if you need to track something a little more complicated? Like a Zend application that has URLs like this:
GA sees that as three different pages instead of being the UserController’s viewAction(). Which is annoying because if you don’t care about specific items then it’s a little misleading about what the “top” pages are on your site.
var _gaq = _gaq || ; _gaq.push(['_setAccount','GA-123445-01']); _gaq.push(['_trackPageview']);
This setups the various settings used on the page including the account (
_trackPageview setting is what actually sets the page your tracking. If you leave this setting blank it uses the current URI. But you can set it to anything you want:
I have the Google Analytics code in my layout so I just add the following to my Generic Controller (the controller all my other Controllers extend).
$params = $this->getRequest()->getParams(); $this->view->controller = $params['controller']; $this->view->action = $params['action'];
Then in my layout.phtml I add:
_gaq.push(['_trackPageview', '/<?php echo $this->controller;?>/<?php echo $this->action;?>']);