How to Count ​
First of all, in the plugin settings, enable Site Counter
for the sites on which you want to count visits.
Set site timezone and other plugin settings
Please ensure that you set the site's timezone in the Craft's general settings and the Start of the week
in the plugin settings before using this plugin.
Changing these settings may affect some pre-calculated statistics (for example, new visitors, maximum online users, page visit statistics, etc.).
Now depending on your Craft setup, you can count automatically, manually or count when your frontend is decoupled.
Count Automatically ​
- Go to the plugin settings page
admin/counter/settings/general
. - Change the
Register counter automatically
setting to enable.- Enabling this setting will add a JavaScript script to the end of all site pages if the counter is enabled for the site, which sends a request to the backend on every visit.
- If you want to support outdated browsers like IE11 in your site's front end, enable
Support outdated browsers
in plugin settings. Disabling this item makes requests faster and lighter on the front end.
Good to know
- All frontend pages are counted when you use this option.
- When
Register counter automatically
is enabled, we disable counting by calling thecount()
service in Twig to prevent counting a visit twice.
Count Manually ​
By using this option you can control which pages are counted.
- If your site is statically cached, add this to the end of your frontend pages:
{% do view.registerAssetBundle("vnali\\counter\\assets\\CounterAsset") %}
- If your site is not statically cached, you can call the count service directly in twig:
{% set fullUrl = craft.app.request.getAbsoluteUrl() %}
{% do craft.counter.count(fullUrl) %}
Advanced Tip
- If you count visits by calling the count service directly in Twig, you can enable
Prevent access to counter via HTTP request
in plugin settings. In this case, requests to the backend counter via HTTP requests are ignored.
Count on Decoupled Sites ​
Info
This documentation site is built with VitePress and is decoupled from Craft CMS.
Guides on counting visits with this plugin in a decoupled frontend are coming soon.