tags:

views:

69

answers:

4

What will be the best way to go about getting the referrer details like say google 20%, msn 10%, internal 70%. Its for finding out how each article posted on the site was viewed or accessed or referred. Not in google analytics. But its for the bloggers to check after they have posted a technical article. The app is in php and also uses Zen framework.

A: 

Why don't you want to use Google Analytics?

alex
This info is to be displayed to them on the site itself.
zapping
+2  A: 

make table with referers:

id | referer | article_id | count

and:

id | article_id | total_count

and every time someone accesses your article, increnment total_count for the article, and proper count.

And when you show it, just divide these two counters.

sorry for my English ;)

radex
Is there a way to handle refreshes or post back? Like on posting a comment on the article on the page.
zapping
hmm... if(referrer == this_site) refreshed!
radex
May be something with start of a session can do it? Is there a way to know? Like in asp.net you have the session start event in the global.ascx file.
zapping
I don't understand - can't you just check if [this site address] == [referrer]? Of course you can also use sessions for this...
radex
+1  A: 

How real-time do the results have to be?

Approach 1 -- modify your app so that when it serves up a post, it stores the referer info. (Available to your PHP app, check the cgi library). Advantage: can give real-time stats, but slows down your app and adds extra complexity.

Approach 2 -- save the log files and analyze them offline. Probably better all-around. Note that Apache can store its logs directly into a database (rather than to log files). That'd make it easier to then query and analyze for reports back to your authors.

Added--another advantage of storing the log info in a database (either on the fly or in batch) is that "one report leads to another" -- today the authors want to know referer info. Tomorrow they'll want cross-tabs by browser type and country.

Larry K
+1  A: 

I am not sure how your app is set up, but lets assume that each post is stored in the database with a unique id. Your script would look something like this:

  1. Get the referrer using $_SERVER['HTTP_REFERER]
  2. Store that in the database using the original post id as the foreign key and a normalized version of the domain

Then, when you want to show stats, run a query like this:

SELECT `domain`, COUNT(*) as `total` FROM post_referrers WHERE `post_id` = 5 GROUP BY `domain`

You could then calculate percentages against the total number returned.

The post_referrers table would look like this:

id, domain, post_id, full_url

And if the referring URL is http://google.com/?q=whatever you would want to store:

domain: google.com
post_id: 5
full_url: http://google.com/?q=whatever
Doug Neiner