Zar
Zar

Reputation: 6882

Processing statistics: upon page request or by pixel-tracking

I'm currently in the process of developing a statistics module for my pages. I'm currently considering the following two techniques to enable page-specific statistics:

  1. Querying the database directly upon request. This increases the time it takes to generate the page by about 100-200ms, which increases the overall time it takes to generate a page = bad.

  2. Using a technique like tracking pixel. Inserting a 1x1 image at the bottom of my content, ensuring it gets loaded after all the content has been loaded. This doesn't directly **affect page generation times. <img src="tracking.php?pageID=391" width=1 height=1 />

I'm not stupid – I do realize that somewhere it will take the server 200ms to handle the information (gather, structure and insert), however, this shouldn't affect the user.

One adventage I can see by using method one is that the statistics are updated BEFORE content is served, as opposed to method two – meaning that half-a-second visits counts too. Sometimes good, sometimes bad.

What's the prefered way, preformance and smoothness wise to process statistics data? I'm open to other techniques aswell.

Upvotes: 1

Views: 273

Answers (3)

Stewie
Stewie

Reputation: 3121

Use asynch monitoring. Deploy a javascript listener on each page and that can fire an ajax call to the remote stats collector with all the details you want to capture. This does not affect page load time.

Upvotes: 1

LTME
LTME

Reputation: 1126

I would think that updating a database with statistical information on a per-hit basis would be too expensive, not necessarily from the perspective of load time, but also in doing an extra database call on every single page hit. I suppose that cost does depend on your expected traffic, but I would think the tracking pixel would be much better.

Upvotes: 1

Xesued
Xesued

Reputation: 4167

My perfered way: Awstats. It uses the apache log files to gather statics. But it really depends on what you want to gather.

Awstats will gather the number of requests, time of day, what brower, IP address. Anything that is in the apache logs. Best of all, it has zero impact on page loads and doesn't require adding additional mark up to your pages.

Upvotes: 2

Related Questions