dingoblog / dingo

Blog engine written in Go
MIT License
284 stars 34 forks source link

Proposal: Tracking website activity #58

Open dinever opened 8 years ago

dinever commented 8 years ago

It would be great if we can show some web analytics information on the dashboard. For example:

To implement this, we need two new endpoints. For, example:

track.js is a simple JS script that request the 1 pixel GIF image from the backend server, with URL, page title and referrer(URL of the previous webpage) as parameters.

(function(){
    var d = document, i = new Image, e = encodeURIComponent;
    i.src = '/track/track.gif&url=' + e(d.location.href) + '&ref=' + e(d.referrer) + '&t=' + e(d.title);
    }
)()

track.gif is a 1 pixel GIF image, hard-coded in the backend server. When track.gif is requested, the server takes the parameters described above as well as the request header information, and insert an entry in the table page_views of the database:

CREATE TABLE "pageview" (
    "id" INTEGER NOT NULL PRIMARY KEY,
    "url" TEXT NOT NULL,
    "timestamp" DATETIME NOT NULL,
    "title" TEXT NOT NULL,
    "ip" VARCHAR(255) NOT NULL,
    "referrer" TEXT NOT NULL,
    "headers" TEXT NOT NULL,
    "params" TEXT NOT NULL
);
CREATE INDEX "pageview_timestamp" ON "pageview" ("timestamp");