I am using a simple bit of PHP code in my header file which increments a counter in my SQL database by 1 once per PHP session. I've tested this and it works fine.

However when I leave it for a day the counter has gone up by way more than I believe it should, and comparing this to the pageview counter in my Google Analytics it is far too high.

What could be happening and how could I stop this?

有帮助吗?

解决方案

Google-analytics has a very different way of counting visits than a simple session based counter. I can't tell you exactly how it counts it because it is very closed source on that aspect but there is definitely cookies, sessions and javascript involved.

If you want my opinion. I built my own stat system once and it was hell with all those robots detection, trends, false visits. I switched to GA and it was worse because the client then started complaining that the numbers werent the same in both sites.

IMO? Don't use both, make up your own or use GA only, but not the two, you'll probably NEVER hit the same numbers.

Good luck

其他提示

What do you mean by "once per session"?

You need to do a start_session() and then set a variable to ensure you are only counting unique sessions:

if(!isset($_SESSION['started'])) {
    doHitCounter();
    $_SESSION['started']=true;
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top