Question
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.
Solution
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.
OTHER TIPS
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 ;)
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:
- Get the referrer using
$_SERVER['HTTP_REFERER
] - 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
Why don't you want to use Google Analytics?