Docs
Browse the docs

Add Privatus Analytics to Hexo

Add cookieless analytics to a Hexo blog with a small script that injects the tracker before the closing head tag, whichever theme you use.

View as Markdown

Create scripts/privatus.js in your Hexo project. Hexo loads every file in scripts/ when it starts:

js
hexo.extend.injector.register(
  'head_end',
  '<script defer src="https://privatusstats.com/js/pa.js" data-site="pa_YOURSITEID" data-modules="engage,auto,vitals,clicks,ask"></script>'
)

head_end inserts the snippet right before </head>. This works with any theme, so a theme update doesn't remove it.

Run hexo clean && hexo generate, then deploy. The tracker ignores localhost while you run hexo server, so previews are not counted.

If you would rather edit the theme, add the tag to the theme's head layout instead, for example layout/_partial/head.ejs (the name varies by theme). Hexo pages are full page loads, so each page view is counted once.