User-Authenticated Event Tracking with jQuery + Google Analytics

You probably already know about Google Analytics, and if you use it enough you may even know about Event Tracking with Google Analytics , but haven’t quite figured out an easy and useful way to put it to use, so here’s an idea.

I typically use an MVC framework like Ruby on Rails or Asp.Net MVC to build web apps. However, any framework that allows you to authenticate a user (maybe PHP, Node.js, or Python) and return the username to your html view\page will work for this solution.

Once you have Google Analytics & jQuery working on your page, all you have to do is put this little jQuery nugget on your page:

*example uses ASP.Net Razor syntax to include the authenticated user’s username*

Now, you can easily create a custom report in GA, that looks like this:


Obviously, this can be pretty useful, since you’re now able to track the users that are logged onto your site and even try to understand user’s behavior flow.

Btw, I should disclose that storing “personally identifiable information” is against the GA terms of use, so storing a username could result in getting your GA account banned