NAME
Dancer2::Plugin::PrivatusAnalytics - add Privatus Analytics to a Dancer2 app
SYNOPSIS
# config.yml
plugins:
PrivatusAnalytics:
site_id: pa_YOURSITEID
auto_inject: 1
# MyApp.pm
use Dancer2;
use Dancer2::Plugin::PrivatusAnalytics;
# In a Template Toolkit layout
<head>
[% privatus_analytics_tag() %]
</head>
<button [% privatus_event('Report exported', { format => 'csv' }) %]>Export</button>
<a href="/pricing" [% privatus_click('pricing.cta') %]>See plans</a>
DESCRIPTION
Adds the cookieless Privatus Analytics script to a Dancer2 app. It only prints HTML. It never sends anything from your server and sets no cookies.
The plugin takes every setting of PrivatusAnalytics from plugins: PrivatusAnalytics: in your config. The tag is on when the environment is production, or when you set enabled.
KEYWORDS
- privatus_analytics_tag(%options)
-
The script tag HTML. Takes any setting as an override, plus
props. Also available in templates. Thenoncesetting may be a code ref that gets the request. Without one, thecsp_noncevar is used. - privatus_event($name, \%props)
-
Event attributes as HTML. Also available in templates.
- privatus_event_data($name, \%props)
-
The same attributes as a list of pairs.
- privatus_click($name)
-
The click map attribute as HTML. Also available in templates. Prints nothing (and logs a warning outside production) when the name is not valid.
- privatus_click_data($name)
-
The click map attribute as a list of pairs.
- privatus_analytics
-
The PrivatusAnalytics settings object.
AUTO INJECT
With auto_inject: 1, an after hook adds the tag just before </head> in HTML responses with status 200. It skips Ajax requests, encoded responses, pages without a <head> and pages that already load /js/pa.js.
SEE ALSO
PrivatusAnalytics, https://privatusanalytics.com/docs
LICENSE
MIT. Copyright (c) 2026 Two Phase LLC.