4

I've created a website where users will be able to add entries, associate rows in different tables and so on. I need to track what actions users are doing for a score table.

I also need to keep track on page views.

I'm trying to figure out what is the most efficient way for tracking / logging this.

Is it best to:

  • create a new DB and add records here?
  • Add records on same DB as website?
  • Use javascript to send parameters by URL to a logging server?

Any other methods that is good?

I don't know how many users I will have on my website when I launch this, but hopefully I will have a bit of trafic.

Steven
  • 19,224
  • 47
  • 152
  • 257

4 Answers4

1

You can make DB table with rows:

  • Date and time
  • IP address
  • Current URL
  • Referrer URL
  • Serialized $_GET
  • Serialized $_POST
  • Serialized $_COOKIE

It's very useful if you want track your traffic.

Pseudocode:

if(!$bot) { 
   $visit = Array(
     'date' => date("Y-m-d H:i:s"),
     'ip'   => $_SERVER['REMOTE_ADDR'],
     etc ...
   );
   $sql = "INSERT INTO visits (`".join("`,`",array_keys($visit)."`) VALUES ('".join("','",array_values($visit)."')";
   ...
}

Use same DB, so you will have less connections to mysql server.

Do it in PHP script (after mysql_connect is quite good idea), I believe one INSERT per visit is not big challenge for your machine.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Peter
  • 16,453
  • 8
  • 51
  • 77
  • Yes, but should this be on same DB as website? Or on another DB for reducing CPU? Shoud I just javascript og just PHP/SQL? – Steven Nov 02 '11 at 17:57
0

Have you considered using HTML5 webstorage: http://www.w3schools.com/html5/html5_webstorage.asp

you could use javascripts sessionstorage object(data is stored in key/value pairs) to store all the page activities as properties of this object, then POST this information alongwith the logout action to the backend script which in turn maintains the corresponding database entries, I believe this way you can avoid uneccessary http requests with all the overheads, by sending the page activity information in one final request.

you should re-initialize the object on every user login.

ajish
  • 183
  • 2
  • 8
0

I wouldn't use Javascript if you want reliable results as users may have that disabled or may try and manipulate it to cheat somehow.

Ideally I would use a separate schema as that will scale the best (you may in the future want to split that schema off onto a separate server for processing) although it will make it hard to join data between the two schemas. You could start with a new table in the same schema (as long as your code is nicely encapsulated you could always break the logging out into a separate table at a later date).

liquorvicar
  • 6,081
  • 1
  • 16
  • 21
0

I advise looking for a solution that is asynchronous (to minimize the performance impact for end users) and integrated with an overall visitor data solution (so that reporting on various metrics can be combined). For example, Google Analytics offers Event Tracking so that you can add to its standard metrics on visitors, page views etc, arbitrary user-action data like those you describe.

weir
  • 4,521
  • 2
  • 29
  • 42
  • I've been looking at `Google Analytics API`, but not sure how to use it to get what I want. Imidiate concerns are tracking most viewed stores and brands on my site. Typical URL would be http://www.mysite.com/store/?storeid=23&name=some_name – Steven Nov 02 '11 at 18:58
  • I was only using GA as an example. But it does have a solution tailor-made for stores and brands: [Custom Variables](http://code.google.com/apis/analytics/docs/tracking/gaTrackingCustomVariables.html). – weir Nov 02 '11 at 19:20