0

I am using a really simple FAST caching technique. I just implemented this techniuqe and it is great.

I have a row on my database that counts page views. This is also a very simple technique.

$query_rs_update = sprintf("UPDATE table SET views = views+1 WHERE id = %s", GetSQLValueString($colname_DetailRS1, "int"));

I can not find a way to use this technique and COUNT the VIEWS at the same time. Since the Page is being Cached .. ?

Anyone have a better technique? Can you turn a Query to Javascript so it will work using Caching ?

Thanks!

eberswine
  • 1,224
  • 3
  • 20
  • 39

3 Answers3

1

You could have some javascript on your page that makes an AJAX request to a separate page that records the page view. This is similar to how most site statistic engines (i.e. Google Analytics) work.

Eric Petroelje
  • 59,820
  • 9
  • 127
  • 177
  • I am curious about this method too. Any examples ? Thanks Eric! – eberswine Mar 21 '12 at 20:52
  • @eberswine - Easiest way (doesn't even require javascript) would be to have an `img` tag on your page where the `src` attribute points to a php page. That PHP page would then record the page view and return a one pixel transparent image. – Eric Petroelje Mar 22 '12 at 12:42
  • Interesting approach. So I can just attach a couple of GET variables to it and then point it to a .php page? What is with the return? – eberswine Mar 26 '12 at 21:14
  • @eberswine - the return would be a single pixel transparent image, or it could be nothing as well (this may cause errors in some browsers though) – Eric Petroelje Mar 27 '12 at 18:12
  • Hey eric, thanks for the comment back. I am still struggling with the concept. I found other questions http://stackoverflow.com/questions/8138473/count-image-views but still pretty vague answers, do you have any sample code you could write from my 'sample code from above' ? – eberswine Apr 09 '12 at 20:37
  • @ErikPetroelje I am back to this question. Sorry to bring this up again. But I am still baffled ? Can you expand your answer please!!!! – eberswine May 13 '14 at 05:08
1

There might be specific reasons to do it way you're doing, but it's generally considered bad practice to track pageviews or activity via MySQL. Your two problems now are that pages are cached, and the tracking ability will be severely underpowered. For example, you'll be missing an ability to separate organic vs robot traffic.

It's best to allow an independent, trusted and capable metrics vendor to do that tracking as they do it for a living - and they can provide a rich dataset to explore.

Warning: check your host's TOS

Note that some hosting companies explicitly forbid forms of 'performance tracking' for managed SQL uses in their terms of service (count increment might apply here, since it can alter index information.) Unless you're using InnoDB storage engine, the performance will always be bad because the table is locked for all reads until the update is finished.

Use Google Analytics

There are limitations to GA, but the positives are that:

  • CACHING: it bypasses any local caching schemas
  • EFFICIENCY: offloads tracking overhead resources onto the client
  • PRICE: it's free to use
  • FILTER: robot traffic is removed from human activity
  • BROWSE: reports can be neatly organized, shared and explored
  • WRITE: has virtual page tracking (so your unique Ajax-dynamic page interaction can still be tracked)
  • READ: there is an API you can use to retrieve the data; ex: most viewed (see http://www.electrictoolbox.com/google-analytics-api-php-class-most-popular-pages/)
pp19dd
  • 3,625
  • 2
  • 16
  • 21
0

You can use Javascript! Just download Node.js, type the following into your terminal: npm install --save express and npm install --save socket.io. Then, follow this tutorial: https://gist.github.com/Squiva/0eabc2ca5080fd2e4de5

Squiva
  • 21
  • 1