NAME

Mojolicious::Plugin::PrivatusAnalytics - add Privatus Analytics to a Mojolicious app

SYNOPSIS

# Mojolicious
$self->plugin(PrivatusAnalytics => { site_id => 'pa_YOURSITEID' });

# Mojolicious::Lite
plugin PrivatusAnalytics => { site_id => 'pa_YOURSITEID', auto_inject => 1 };

# In a template
<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 Mojolicious app. It only prints HTML. It never sends anything from your server and sets no cookies.

The plugin takes every setting of PrivatusAnalytics. Settings in the app config under privatus_analytics are read too. The tag is on when the app mode is production, or when you set enabled.

HELPERS

privatus_analytics_tag(%options)

The script tag, as a Mojo::ByteStream. Takes any setting as an override, plus props. The nonce setting may be a code ref that gets the controller. Without one, the csp_nonce stash value is used.

privatus_event($name, \%props)

Event attributes as safe HTML.

privatus_event_data($name, \%props)

The same attributes as a list of pairs, for the tag and link_to helpers:

%= link_to Guide => '/guide', privatus_event_data('Guide opened')
privatus_click($name)

The click map attribute as safe HTML. 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_render hook adds the tag just before </head> in HTML pages with status 200. It skips Ajax requests, 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.