Wordpress (using varnish + apc + w3tc): Do the statistics get updated when the data is being retrieved from the cache?

StackOverflow https://stackoverflow.com/questions/21680773

Question

If the data is served to the client from the varnish cache, does it still get registered as a hit in the statistics (could be derived from nginx logs or might be google analytics)? I believe that the apc doesn't affect the statistics as it caches only the PHP and the rest of the content is still derived from the nginx. Similarly what about browser cache?

Was it helpful?

Solution

Varnish affects analytics based on access logs since cache hits do not result in a request to the nginx backend, and therefore they are not logged by the backend. For that you need to setup Varnish logging.

Google Analytics, however, is not affected by Varnish, since the tracking is based on Javascript executed within the browser. Even if the browser caches the page HTML and the Javascript, the script would still be executed and statistics logged by Google Analytics (or other Javascript based analytics services, such as Piwik).

OTHER TIPS

well yes and no, It depends on what page and what varnish rules, and what exactly counts, lets try to group them

we have backend counters like access logs, and frontend counters like google analytics.

backend counters: you need a request to hit the backend to actually record a hit, if you get a total varnish hit and the cache was served totally from the varnish cache, the backend won't even know a visit came by, and you'll get confusing numbers because each vcl_fetch would count a hit but vcl_hit wouldn't.

But if the counter is stored in a page that varnish vcl_pass then that hit would be recorded, and you don't need to do any thing special, like pages that include cookies.

frontend counters: (like google analytics and all javascript analytic libraries) Those counters should not be affected by caching, because the analytics code is still served from cache, and the counting happens to their servers, so even if your nginx server is totally dead, and varnish is serving from it's cache, your counts will still be counted normally without any interruptions.

PS about wordpress total cache: Honestly I haven't really used it before and I don't know how it exactly works, but I assume it compiles HTML pages to serve directly instead of querying the database on each hit, if we assume there's no varnish, the hits would count on access log but if you have some sort of database counter that runs on the article.php for example then you might have a problem, because there's a possibility that that file isn't run each time a new hit comes, so you need to double check that if you use php to count the hits.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top