问题
I am using Google Analytics on my single page HTML5 application. Though Google Analytics shows Visits as 16k, the number of hits in the server log says the figure is around 3 lac.
I am using the following tracking code in the head section of my page:
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-xxxxxxxx-x', 'example.com');
ga('send', 'pageview');
</script>
What could be the reason for such anamoly or how can I track if the Google Analytics results are correct (using server logs etc) ?
回答1:
I assume that by "3 lac" you mean three hundred thousand.
First of all visits in GA and hits in a server log file are not comparable since "visits" is an aggregate number that usually includes multiple hits.
Secondly the server log tracks requests to the server (including requests for assets like images, css file, js file etc. as well as error pages). Since a page comprises multiple files (html and assets) every pageview will result in multiple hits to the server. Also the server log will track bots and crawlers.
On the other hand Google will track only the request to the page itself (the part that includes the tracking code) and not the assets, and it will no track (in the standard implementation) user agents that do not use javascript. It also won't track users that have opted out from tracking.
Since by now the majority of web traffic is caused by such user agents (search engine crawlers etc.) server logs will show significant more traffic than Google Analytics.
To compare the two you first need to remove calls to asset files and all traffic that is caused by crawlers from the log file. Then you need to compare the correct metric (i.e. Analytics pageviews vs. server log hits, not visits).
来源:https://stackoverflow.com/questions/22979824/anamoly-between-google-analytics-and-server-hits