It would be great if we can show some web analytics information on the dashboard. For example:
How many page views I had during the last week?
What are the top pages of my blog?
Where are the visitors from?
To implement this, we need two new endpoints. For, example:
/track/track.js
/track/track.gif
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");
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/track.js
/track/track.gif
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.track.gif
is a 1 pixel GIF image, hard-coded in the backend server. Whentrack.gif
is requested, the server takes the parameters described above as well as the request header information, and insert an entry in the tablepage_views
of the database: