NAME

Plack::Middleware::PrivatusAnalytics - add the Privatus Analytics tag to HTML responses

SYNOPSIS

# app.psgi
use Plack::Builder;

builder {
    enable 'PrivatusAnalytics', site_id => 'pa_YOURSITEID';
    $app;
};

DESCRIPTION

Adds the cookieless Privatus Analytics script just before </head> in HTML responses from any PSGI app. It only changes HTML. It never sends anything from your server and sets no cookies.

It changes responses with status 200, a text/html content type and no Content-Encoding header. It skips Ajax requests (X-Requested-With: XMLHttpRequest), streamed responses, pages without a <head> and pages that already load /js/pa.js. It fixes the Content-Length header.

The tag is on when PLACK_ENV is deployment or production, or when you set enabled. Add the middleware inside (after) Plack::Middleware::Deflater so it sees the page before it is compressed.

OPTIONS

Every setting of PrivatusAnalytics. props may be a code ref that gets a Plack::Request. nonce may be a code ref that gets the PSGI env. Without one, $env->{'plack.csp_nonce'} is used. auto_inject is on by default here. The settings object is also put in $env->{'privatus.analytics'}, so your app can print event attributes with the same settings.

SEE ALSO

PrivatusAnalytics, https://privatusanalytics.com/docs

LICENSE

MIT. Copyright (c) 2026 Two Phase LLC.