views:

118

answers:

1

I'm creating a video embed page for a real estate site, where a user can go to watch a video tour of a given home. There is no other reason to visit that particular page, so I figured that I could use a simple MySQL Update to a "video view tally" column for that homes's row, which will update views=views+1 each time the page is loaded.

That's easy enough, but I want to give as realistic a "view" count as possible, so I'm trying to come up with a way to have that view tallied ONLY once the page has been loaded for a set number of seconds (say, 30).

Any thoughts on a good way to handle the timing aspect? I'd like to avoid javascript, if possible, but I'm open to if it it's handled simply enough.

A: 

Unfortunately the only way you will ever know if the page is still active is to have a client-side technology (like JavaScript) tell you that it is.

You can add a "counter" page that isn't meant to be viewed directly, but instead is accessed via JavaScript after a 30 second page timer has expired. The act of JavaScript accessing that page will trigger the counter logic.

Eric J.
Regarding the "counter" page: So I would set up the MySQL update on <em>that</em> page instead, and that page load is what would actually trigger the update... I think I've got it.Just to be clear, though... the user won't see any disruption through this process, correct? (You'll have to excuse my lack of JS experience)
Distill
Yes, that should do it. FYI, the trick is borrowed from something spammers used to do: They would define an "image" in an HTML email but the image source would point back to a counter page. The counter page was passed your email address. If that "image" was loaded, the counter page recorded the email address passed back to it as a valid address. That's why modern email clients block images from unknown senders.
Eric J.