Frage

Was ist der beste Weg, Seitenaufrufe zu verfolgen? Zum Beispiel: SO hat, wie viele Ansichten eine Frage hat, noch refresh trifft nicht auf die Ansicht Zahl

.

Ich habe gelesen, dass Cookies ist eine ziemlich gute Möglichkeit, mit so zu tun, aber ich bin ratlos, wie man dies nicht von Hand nicht raus.

Ich habe alle über gesucht und kann nicht eine gute Antwort für diese finden.

EDIT:

Ich sehe auch, dass eine andere Option (wieder einmal konnte ich schrecklich falsch sein) ist Google Analytics API verwenden Seite Ansichten zu erhalten. Ist das auch ein gangbarer Weg? Wie funktioniert Stackoverflow, youtube und andere verfolgen ihre Ansichten?

War es hilfreich?

Lösung

You can track them in a database if you're rolling your own. Every time a page loads, you call a method that will decide whether or not to up the page views. You can add whatever criteria you like.

IF IP is unique
OR IP hasn't visited in 20 minutes based on a session variable
ETC
THEN add a page view record

| ID | IPAddress | ViewDateTime |
| 1  | 1.2.3.4   | Oct 18 ...   |

However, session variables can get pretty load intensive on sites with as many visitors as SO. You might have to get a little more creative.

Now, if you don't want to code it, the I would suggest looking into SmarterStats as it reads your server logs and is more robust than analytics.

note: i'm not sure about a similar Apache software

Andere Tipps

I set a session variable with the address I'm checking, then toggle it if it's been hit by that browser. In my page template I then check the var for that page and handle as appropriate.

A simple, hacky method:

Create local MySQL table for tracking:

CREATE TABLE pageviews ( pageview_count int(9) default NULL )

Then, on the index.php page, or wherever the user is going to be landing, you can run an update query on that field.

<php
$link = mysql_connect('localhost','root',''); 
if (!$link) {
    die('could not connect ' .mysql_error());
}
$mysql = mysql_select_db($database_name,$link);
$query = mysql_query('UPDATE pageviews set pageview_count = pageview_count + 1;');
mysql_close();
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top