Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I am trying to add google analytics to a web application built in asp.net c# that is already pretty mature. The requirement is to have all sorts of event tracking on buttons clicks, breaking up page views into different sections, based on which view gets displayed, etc. I am wondering if there is a way to build a framework that does this, because the asp.net web application is already working, with many button events, and onlick events already present. I didn't want to have to wire up each and every button with specific trackers, etc.... I know I have to do some of it, but if I can make a framework that can be used everywhere, then thats what I want to do - unless there is a framework already present that integrates this.

share|improve this question
add comment

1 Answer

For the button clicks and other actions generated by user interaction you probably want to look at a convention-based approach. You would first apply appropriate CSS classes -- and perhaps other metadata -- to the buttons. Then add a script that looks for your CSS classes and wires them to fire off analytics events before returning true and letting processing continue. This is relatively painless to implement while also being easy to extend.

I'm not quite following the bit about "which view gets displayed", you might want to elaborate a bit there.

share|improve this answer
Thanks - in regards to the view, I have an asp.net multiview, which shows a view at a time, but its all part of the same page - but they want to view stats for each one separately. –  M.R. Dec 10 '11 at 8:37
Ah. Number of ways to cause that problem, but you can use the same general idea -- pick a html element, decorate with special class then find that class and denote event to GA. –  Wyatt Barnett Dec 16 '11 at 0:40
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.