# Best way to access audio downloads / audio listen statistics

**URL:** <https://www.ruby-forum.com/t/best-way-to-access-audio-downloads-audio-listen-statistics/170489>\
**Category:** Rails\
**Created:** [June 18, 2009, 3:15am UTC](https://www.ruby-forum.com/t/best-way-to-access-audio-downloads-audio-listen-statistics/170489 "2009-06-18T03:15:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![e\_deleflie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/858c86/32.png) [@e\_deleflie](https://www.ruby-forum.com/u/e_deleflie)\
**Post date:** [June 18, 2009, 3:15am UTC](https://www.ruby-forum.com/t/best-way-to-access-audio-downloads-audio-listen-statistics/170489/1 "2009-06-18T03:15:41Z")

</div>

All,

I’ve got a rails application that allows people to publish audio files.  
The  
files are stored on Amazon S3.

I would like to publish statistics on the number of listens … and have  
those statistics close to real time.

I’m wondering if I should use a URL redirect WITHIN rails to redirect a  
RAILS URL to an S3 audio URL … then I could save the hit to the  
database  
(through RAILS) … or I could just scour the log files (I’d need to  
scour  
both S3 log files and Rails log files).

Scouring the log files is going to be messy … but having a URL  
redirect  
(within RAILS) that logs the hit is going to be perhaps expensive …

… does anyone have any ideas/thoughts/recommendations.

Etienne

---

<div class="post-metadata">

**Author:** ![e\_deleflie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/858c86/32.png) [@e\_deleflie](https://www.ruby-forum.com/u/e_deleflie)\
**Post date:** [June 18, 2009, 12:25pm UTC](https://www.ruby-forum.com/t/best-way-to-access-audio-downloads-audio-listen-statistics/170489/2 "2009-06-18T12:25:23Z")

</div>

e deleflie wrote:

> All,
> 
> I’ve got a rails application that allows people to publish audio files.  
> The  
> files are stored on Amazon S3.
> 
> I would like to publish statistics on the number of listens … and have  
> those statistics close to real time.
> 
> I’m wondering if I should use a URL redirect WITHIN rails to redirect a  
> RAILS URL to an S3 audio URL … then I could save the hit to the  
> database  
> (through RAILS) … or I could just scour the log files (I’d need to  
> scour  
> both S3 log files and Rails log files).
> 
> Scouring the log files is going to be messy … but having a URL  
> redirect  
> (within RAILS) that logs the hit is going to be perhaps expensive …
> 
> … does anyone have any ideas/thoughts/recommendations.
> 
> Etienne

Directing to an action on your app first would be much easier than  
logging.

Depending on how much info you want you could either create a new model  
called LinkClick and create a new record each time a link is clicked.  
This way you could store dates and times, ip\_addresses etc. - info that  
may be useful in future if not atm.

Otherwise, id just add an extra column the table you use for your audio  
files called clicks, default it to 0 and create a model method called  
add\_click.

def add\_click  
increment clicks  
end

Then you simply have to call add\_click from your controller before  
redirecting to amazon.

Gavin

> **[Ruby on Rails tips & Tutorials](https://handyrailstips.com)**
>
> Ruby on Rails tips and tutorials
