Add Privatus Analytics to Craft CMS
Add cookieless analytics to Craft CMS 5 with one snippet in your Twig layout that loads in production only, with no cookies and no banner.
Open your layout template, usually templates/_layout.twig, and add this
inside <head>:
{% if getenv('CRAFT_ENVIRONMENT') == 'production' %}
<script defer src="https://privatusstats.com/js/pa.js" data-site="pa_YOURSITEID" data-modules="engage,auto,vitals,clicks,ask"></script>
{% endif %}
CRAFT_ENVIRONMENT is the environment variable Craft reads for the
current environment, and Craft's getenv() Twig function returns it. Set it
to production in your live .env file. If your live site uses another
name, change the comparison.
Our Craft plugin#
We also have an optional Craft plugin. It is not in the Plugin Store. Don't install a plugin called Privatus Analytics from the Plugin Store: it is not ours, whoever published it. Contact us if you would like it. The template snippet above does the same job.
Craft pages are full page loads, so each page view is counted once. Add other options as attributes.