Blog

A blog from Brandon Moser, a Senior Web Developer. Mostly code, sometimes I post about drumming, UX and/or loyalty.

Tracking Page Views in CFWheels w/Google Analytics

Today I was tasked with tracking page views and email campaigns in Google Analytics (GA) within our CFWheels application. I found a great option in GA to track events. Thinking about how the framework is designed, we essentially are using Events (like most frameworks) to control the application. Within Event Tracking in GA, you define a Category (controller) for the Event. Then,  define the Action (action). The _trackEvent() method also accepts 2 other parameters, opt_label, which is an option descriptor for the event and opt_value, which is a number (positive integer).

To add this to your GA script snippet, just add the following line:

_gaq.push(['_trackEvent', '<cfoutput>#params.controller#</cfoutput>', '<cfoutput>#params.action#</cfoutput>']);

Once you have added this snippet to your GA script you will find the report under Content >> Event Tracking. From here you will be able to determine the usage of your app without having to create Custom Reports.