File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Groovy and the fly likes Tracking Clicks in a Grails App Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » Groovy
Bookmark "Tracking Clicks in a Grails App" Watch "Tracking Clicks in a Grails App" New topic

Tracking Clicks in a Grails App

Juan Marcos

Joined: Apr 05, 2011
Posts: 12

I have a min ProgramController which dictates the overall application, including direction to each URL within the application itself (i.e., def homePage, def movieNight, etc.).

What I am trying to do is put an incrementing variable within each method listed above to track clicks, then update and persist that variable to the database which my ClickTracker domain
class has generated. I have two variables within my ClickTracker domain.

I'm working with a MySQL Database.
What I want to do is create ONE row per URL and update only the "visits" variable in the database each time it's navigation button is clicked without having to create and
persist a new URL instance within the database, i.e.;
url_name: HomePage Visits: 150
URL Name: Fireside Chat Visits: 45

Any recommendations?

Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15302

My recommendation would be to not use a home grown solution and go with something like google analytics. It's pretty simple to add some junk to your links that then propagate to GA every time one of them is clicked.

GenRocket - Experts at Building Test Data
Juan Marcos

Joined: Apr 05, 2011
Posts: 12

Thanks for the input Gregg. I'm actually interning at a company right now, and those were the instructions that my boss gave me. I know that Grails has some really useful plugins as well for what I'm trying to do.

It took me a number of hours to come up with a solution

But what I ended up doing was creating a general domain class to track the event, then I increment each event method that calls the specific URL I need to track within the main ProgramController, thus persisting and updating my MySQL database.

I'm not quite sure if that's what he wants, but I'm sure I'll find out once he comes back from the trade show.
I agree. Here's the link:
subject: Tracking Clicks in a Grails App
It's not a secret anymore!