Forum: Ruby on Rails Click tracking for external links

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Shannon (Guest)
on 2009-02-06 00:52
(Received via mailing list)
I'm new to Rails.  I have an application with a group of external
links <a href="www.externalsite.com">.  I would like to track the
first time someone clicks on one of those links in my DB.  What is the
standard "Rails" way to do something like this?
Thank you in advance
Andrew B. (Guest)
on 2009-02-06 02:24
(Received via mailing list)
no standard exists as far as i know. you have 2 options as i see it.

1.) run each link through a redirect. something like:
<a href="mysite.com/tracker?url=www.externalsite.com">blah</a>

2.) or use some javascript and implement an onclick handler on the
link to fire an ajax request back to your application

at work i had to implement something similar, ive used both options
successfully, each has its advantages/disadvantages. for example, #2
wont provide tracking if the user disables javascript.
Julian L. (Guest)
on 2009-02-06 04:02
(Received via mailing list)
There's no standard way :)

The way I use is to link to an action which retrieves the lonk, adds
one to a link counter in the db and does a redirect. Go and try to do
that. Come back if you have issues and show your working.

Blog: http://random8.zenunit.com/
Learn rails: http://sensei.zenunit.com/
This topic is locked and can not be replied to.