We have set up all possible caching including optimization for WP and cache on edge nodes. But when we enabled the latest we faced the issue that counters of how many people read it are much lower than our analytics. We think that a static copy of the site that is created does not have any scripts that can increment this counter. Do you guys know what would be the fix for this? We are happy with static pages generated otherwise as they give great performance in google insights.
This is a problem I’m struggling with too. Never found a solution besides getting the data from the Google Analytics API.
From my experience where I run W3 Total Cache with Page Cache (and all the other caches) + Cache Level: Cache Everything.
But, in terms of a counter, I have “most read” section which does work with the count (article veiw / refresh page) via Ajax.
That way I get really good performance + I still get the views counted so I could display “most read in past 7 days” news
Not the best possible solution, but with page cache + cache everything, works like a charm as far for now.
Otherwise, I was thinking to re-write it and experiment a bit and do something with Cloudflare Workers, so I could get less “query jobs” to-do on the database itself when I get a lot of visitors per day (~20k or more), where the MySQL has to do a lot of “update/alter” queries (as my counter works as +1 for a pageview of an article)
Otherwise, I could save the “pageviews” in some log file and gather that from my server, rather than do the MySQL work.
Was thinking about it, but never implemented.
If interested to test out, but could be out of scope for this forums, sharing code here:
To display count on public post/article, just call the
<?php echo get_PostViews(get_the_ID());?>, but again you might need to use Ajax to GET the value of the “read counter” for the article in a real-time as far as if you use above PHP code placed into the
single.php file, and the article is cached as a “static HTML” page, the counter wouldn’t update so soon (the number may not be changed as far as it would be cached at the time when the post/article is being cached/generated).
This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.