# Click tracking for external links

**URL:** <https://www.ruby-forum.com/t/click-tracking-for-external-links/159577>\
**Category:** Rails\
**Created:** [February 5, 2009, 11:52pm UTC](https://www.ruby-forum.com/t/click-tracking-for-external-links/159577 "2009-02-05T23:52:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shannon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e19adc/32.png) [@Shannon](https://www.ruby-forum.com/u/Shannon)\
**Post date:** [February 5, 2009, 11:52pm UTC](https://www.ruby-forum.com/t/click-tracking-for-external-links/159577/1 "2009-02-05T23:52:01Z")

</div>

I’m new to Rails. I have an application with a group of external  
links . 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

---

<div class="post-metadata">

**Author:** ![Shannon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e19adc/32.png) [@Shannon](https://www.ruby-forum.com/u/Shannon)\
**Post date:** [February 6, 2009, 1:24am UTC](https://www.ruby-forum.com/t/click-tracking-for-external-links/159577/2 "2009-02-06T01:24:25Z")

</div>

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:  
blah

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.

---

<div class="post-metadata">

**Author:** ![Shannon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e19adc/32.png) [@Shannon](https://www.ruby-forum.com/u/Shannon)\
**Post date:** [February 6, 2009, 3:02am UTC](https://www.ruby-forum.com/t/click-tracking-for-external-links/159577/3 "2009-02-06T03:02:04Z")

</div>

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/](http://random8.zenunit.com/)  
Learn rails: [http://sensei.zenunit.com/](http://sensei.zenunit.com/)
