Add the analytics script to an HTML site
Add privacy-friendly analytics to a hand-written or server-rendered HTML site with one script tag, turn on engagement and auto events, and track custom events.
Paste the snippet just before </head> on every page. With a shared
layout or header template you only need to do this once.
html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>My site</title>
<script defer src="https://privatusanalytics.com/js/pa.js" data-site="pa_YOURSITEID"></script>
</head>
<body>
…
</body>
</html>
Recommended options#
html
<script defer src="https://privatusanalytics.com/js/pa.js"
data-site="pa_YOURSITEID"
data-modules="engage,auto"
data-exclude="/admin/*,/preview/*"></script>
engagemeasures time on page and scroll depth.autotracks outbound links, file downloads,mailto:/tel:links, form submissions and 404 pages as events. See Modules.
Track events in your own code#
Add the queue stub before the
tracker if you call the API early (for example in inline scripts that run
before pa.js has loaded):
html
<script>
window.privatus = window.privatus || { q: [] };
['track', 'pageview', 'props', 'optOut', 'optIn', 'ready'].forEach(function (m) {
window.privatus[m] = window.privatus[m] || function () {
window.privatus.q.push([m, Array.prototype.slice.call(arguments)]);
};
});
</script>
<script defer src="https://privatusanalytics.com/js/pa.js" data-site="pa_YOURSITEID"></script>
Then anywhere on the page:
js
privatus.track('Newsletter signup', { list: 'weekly' })
Or with no JavaScript at all:
html
<button data-privatus-event="Newsletter signup" data-privatus-prop-list="weekly">Subscribe</button>
No JavaScript?#
Add the pixel inside a <noscript> tag to count
visitors with JavaScript disabled.