Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
XP is just a number
 
PerlMonks

Another page view tracking question

by Analog (Novice)
 | Log in | Create a new user | The Monastery Gates | Super Search | 
 | Seekers of Perl Wisdom | Meditations | PerlMonks Discussion | 
 | Obfuscation | Reviews | Cool Uses For Perl | Perl News | Q&A | Tutorials | 
 | Poetry | Recent Threads | Newest Nodes | Donate | What's New | 

on Nov 05, 2009 at 23:47 UTC ( #805363=perlquestion: print w/ replies, xml ) Need Help??
Analog has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks

I'm looking for any advise on doing something which is pretty much impossible to guarantee (and also a subject that has been beaten to death, so sorry for bring it up again).

We have a custom "forums type" application where we want to try to track the truly unique page views per person/machine as we plan to give incentives to those that are the most popular/most viewed.

Right now I'm planning on starting with just IP's and cookies (will probably be looking at flash shared objects soon).

I'm interested in anyone's opinions on a better approach then what I'm currently doing and also if anyone has any ideas on how to best deal with cookie size.

The plan so far is this

1. Have a table created that stores a page view, the table will have the message id, IP address, date viewed and a user id (if the person is logged in).

for example:

create table Views ( id int(11), UserId int(11), IPAddress varchar(15), DateAdded timestamp default current_timestamp )
Then when viewing a page I would start with
if ($session_data->{'LoggedIn'}) { $existing_view = $db->selectall_arrayref(qq|Select DateAdded from +Views where Id = ? and (IPAddress = ? or UserId = ?)|,undef,($id,$r-> +connection->remote_ip,$userid)); } else { $existing_view = $db->selectall_arrayref(qq|Select DateAdded from +Views where Id = ? and IPAddress = ?|,undef,($id,$r->connection->remo +te_ip)); }
From there the plan would be
unless (@$existing_view) { # get our cookie of id's if ($cookie) { unless ( grep { $_ == $id } @cookieids ) { if ($user_session_data->{'LoggedIn'} == 1) { $db->do(qq|Insert into Views (thread_id,IPAddress,UserId) values ( +?,?,?)|,undef,($id,$r->connection->remote_ip,$userid)); } else { $db->do(qq|Insert into Views (thread_id,IPAddress) values (?,?)|,u +ndef,($id,$r->connection->remote_ip)); } $cookie = $existing_cookie . $new_cookie; } else { $cookie = $id; } # set the new cookie
That is about it, I know this code isn't copy/paste/run but its more to explain the flow then test anything. Like I said, I'd like to hear if anyone has any issues to the approach and/or if anyone has any comments on the cookie.

Right now what bothers me most about the above is there is no real limit to the size of the cookie as it could kept getting added to forever, which means at some point it will be too big.

TIA for any help!

Comment on Another page view tracking question
Select or Download Code

Back to Seekers of Perl Wisdom


Login:
Password
remember me
What's my password?
Create A New User

Node Status
node history
Node Type: perlquestion [id://805363]
Approved by GrandFather
Front-paged by planetscape
help
Community Ads
Chatterbox
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users
Others meditating upon the Monastery: (13)
GrandFather
jmcnamara
atcroft
herveus
Eyck
NodeReaper
SFLEX
biohisham
djp
goeb
gnosti
im2
darkman0101
As of 2009-11-21 10:05 GMT
Sections
The Monastery Gates
Seekers of Perl Wisdom
Meditations
PerlMonks Discussion
Categorized Q&A
Tutorials
Obfuscated Code
Perl Poetry
Cool Uses for Perl
Perl News
Information
PerlMonks FAQ
Guide to the Monastery
What's New at PerlMonks
Voting/Experience System
Tutorials
Reviews
Library
Perl FAQs
Other Info Sources
Find Nodes
Nodes You Wrote
Super Search
List Nodes By Users
Newest Nodes
Recently Active Threads
Selected Best Nodes
Best Nodes
Worst Nodes
Saints in our Book
Leftovers
The St. Larry Wall Shrine
Offering Plate
Awards
Craft
Snippets Section
Code Catacombs
Quests
Editor Requests
Buy PerlMonks Gear
PerlMonks Merchandise
Planet Perl
Perlsphere
Use Perl
Perl.com
Perl 5 Wiki
Perl Jobs
Perl Mongers
Perl Directory
Perl documentation
CPAN
Random Node
Voting Booth

Future historians will find that the material characteristic of the current era is...

Aluminium
Plastic
Oil
Water
Carbon dioxide
Copper
Iron
Silicon
Salt
Uranium
Hydrogen
Other

Results (729 votes), past polls