Count of site visits
-
Hello
I am looking for a hits counters plugin that has functionality to record a cumulative count of the number of user visits to a site, irrespective of page or whether the user has logged in, and display this general count on site pages. Can you please advise if Independent Analytics can offer this functionality?
Many thanks!
-
Hi there,
Thanks for getting in touch about this.
The view counter in Independent Analytics is page-specific, so it doesn’t show the overall stats for the whole site. However, we do have a developer API with a couple of simple PHP functions that can be used to get stats for the whole site.
@bensibley Many thanks for this kind response. Would it be possible to get some guidance on the code required to achieve the outcome I am looking for, which includes the site hits total appearing at the top or bottom of individual pages? Also, would it be possible to start the count from a chosen, figure? The site hits counter plugin I had used previously is not compliant with more recent PHP versions, and therefore, I am not longer able to use it. I have a very full schedule, so it really is a case of me dipping into my WordPress site to add enhancements, only when time allows.
This PHP would output the site’s total views recorded since January 1st, 2025:
$analytics = iawp_analytics(new DateTime('2025-01-01'), new DateTime());
echo $analytics->views;It could be modified to output visitors or sessions instead.
If you want to manually adjust the value, here’s how you could add 2,000 more views to the total:
$analytics = iawp_analytics(new DateTime('2025-01-01'), new DateTime());
echo $analytics->views + 2000;I would recommend using the WPCode plugin and adding this to a PHP code snippet set to run on the front-end. You can then get a shortcode for this code snippet, and the shortcode can then be added anywhere you want on your site.
@bensibley Thanks for providing some code. From previous counts, I estimate that the current hits total exceeds 12,000, so it would be good not to have to revert back to zero. Thanks also for suggesting the WPCode plugin. From grappling with some of the detail in your last message, it looks like I need to get to grips with the ‘PHP code snipper’ lingo, but from a brief look at the link you provide, this should be an integral part of learning about how this plugin works. I will try to find some time for making best use of this plugin to address my current site issue.
Okay sounds good! Feel free to post here if you get stuck.
Many thanks, @bensibley!
Hello again, @bensibley
I am reviewing the options available via my WordPress site dashboard after installing WPCodeLite. After selecting ‘Code Snippets’, I have selected ‘Add Snippet’. The list of next available options is extensive. Are you able to advise me, please, on how best to proceed in choosing options that will enable me to create a display of the total number of visits to my site in real time? I recognise that you have already provided some code and I am keen to make best use of it. However, I am not clear on how to move forward.
Many thanksIt is a little confusing, but on the the Add Snippet menu, you’ll want to click the first option there called Add Your Custom Code. You can then copy the same configuration displayed in this screenshot: https://d.pr/i/rThKq6
That will get you a shortcode that you can add anywhere on the site to display the total number of views.
Many thanks, @bensibley. I am not going to find time to work on the code this week, but I will aim to get started next week.
Happy weekendHi @bensibley
On applying your suggestions, I encoutered the following error message after using the button Save:Edit SnippetSave to Library
Snippet Status:Inactive Update
We encountered an error activating your snippet, please check the syntax and try again. Error message:
Call to undefined function iawp_analytics()
Have you any suggestions as to the best way forward?
Here is the code I had included in the code preview:$analytics = iawp_analytics(new DateTime(‘2025-05-24’), new DateTime());
echo $analytics->views + 140000;Where was the shortcode added to the site? This could only happen if the shortcode was added programmatically very early in the WP load cycle and called with
do_shortcode()or if the Independent Analytics plugin is not activated.@bensibley, I followed the instructions in the screenshot you provided with tweaks to reflect the current date and the prior estimated count. When I install the plugin Independent Analytics, the error message is resolved, thank you, but the top menu of my pages now displays “0 views”, which suggests that the code
$analytics = iawp_analytics(new DateTime(‘2025-05-26’), new DateTime());
echo $analytics->views + 140000;isn’t being read in as desired.
I am sorry that I don’t know how to address this, and I don’t see what the additional code is achieving.-
This reply was modified 1 year ago by
margmacd.
When editing the snippet, you should see a shortcode below the code editor that looks something like this:
[wpcode id="1243"]. Screenshot here.You can add that shortcode into a post, page, or shortcode widget, and that is where you’ll see the number of views show up.
Thanks, @bensibley. For some reason, the editing area for the snippet will not allow me to change the shortcode entry [wpcode id=”4103″]. Also, even if I create a new snippet to circumvent this issue, how will this address the problem that there is a top menu, created by the plugin Independent Analytics that specifies the start count very clearly as 0? Isn’t this displayed for all users to see? I’d prefer not to be displaying conflicting counts.
You don’t need to edit the shortcode given to you by WPCode. You can just copy and paste it wherever you’d like and it will run the code that outputs the number of views. If you add it into a post or page, make sure to use a Shortcode block.
Could you share a screenshot of where you’re seeing the other view count that says “0 views?”
-
This reply was modified 1 year ago by
The topic ‘Count of site visits’ is closed to new replies.