Forum: Ruby on Rails Counting unique viewers?

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.
Jeff C. (Guest)
on 2007-02-07 00:30
I'm building an app where I'd like to track the number of views of each
item, but I'd like to keep it from being spammable, so it counts unique
viewers rather than just the number of pageviews.

What's a good way to go about this?  Should I build a database to record
the IP addresses and save the request.remote_addr for each viewer in the
database, associated with each item?  And then check each viewer against
that item's database of IPs to see if they're unique before incrementing
the view counter?

Are there other ways of doing it?

Thanks,
Jeff
Philip H. (Guest)
on 2007-02-07 00:40
(Received via mailing list)
> I'm building an app where I'd like to track the number of views of each
> item, but I'd like to keep it from being spammable, so it counts unique
> viewers rather than just the number of pageviews.
>
> What's a good way to go about this?  Should I build a database to record
> the IP addresses and save the request.remote_addr for each viewer in the
> database, associated with each item?  And then check each viewer against
> that item's database of IPs to see if they're unique before incrementing
> the view counter?

IP address won't work.. all the machines at my company appear as a
single
public IP, but there's 50 of us...

About the only thing you can do is set a cookie and hope your viewers
don't bother to delete it.

Or force them to login, but that might not be an option...

-philip
Greg D. (Guest)
on 2007-02-07 00:48
(Received via mailing list)
On 2/6/07, Jeff C.man <removed_email_address@domain.invalid> wrote:
> Are there other ways of doing it?
You have to take into consideration the ISPs who force user requests
through their proxy servers.  Those users will appear to have the same
IP address a lot of the time, AOL users for example.  I usually go
with checking that the UP address isn't new in the last 24 hours or
so, since dial up users stand a good chance of getting assigned a
different proxy their next session.

If you're using MySQL I wouldn't store raw IP addresses.  That will
cost you a varchar(15) field which may be up to 16 bytes.  Instead
convert the IP to a signed integer before storing it.  That will only
cost you 4 bytes, until ipv6 gets more love anyway.

def ip2long( ip )
  long = 0
  ip.split( /\./ ).reverse.each_with_index do |x, i|
    long += x.to_i << ( i * 8 )
  end
  long
end


--
Greg D.
http://destiney.com/
This topic is locked and can not be replied to.