mod_analytics

Site Analytics provides lightweight local analytics for site traffic, popular content, email activity and module-defined events. Enable mod_analytics and open Content → Site Analytics. Configure recordings under System → Analytics configuration. The default Languages recording starts paused and can be resumed there.

Permissions and privacy

Reports require use mod_analytics. Configuration and recording mutations require site administrator access (use mod_admin_config); the two permissions are independent. Request events exclude users with use mod_admin and requests marked analytics_exclude. DNT and GPC headers do not exclude requests from aggregate analytics. With require_consent enabled, the context must contain analytics_consent = true. Ordinary logged-in users are otherwise eligible. No visitor identifiers, tracking cookies or raw request logs are stored.

Recordings and storage

Each recording selects one event, fixed filters and at most one breakdown dimension. Counters are aggregated asynchronously into capped minute, quarter-hour, hour and day slots in the site's PostgreSQL database. Popular content uses bounded approximate rankings over moving periods. These are event counts, not unique visitors. Ingestion is best-effort: overload can drop events, and reports indicate incomplete data. Pausing preserves history and its storage reservation; deleting releases the reservation.

Per-site configuration:

KeyDefaultMeaning
row_budget1000000Maximum reserved group/time slots across recordings.
require_consentfalseRequire explicit context consent for request-associated events.

Integration

controller_page and controller_template default to the page dispatch analytics type; controller_api defaults to api. Override with {analytics, Type}, or disable a route with {analytics, false}. Page events count successful public HTML GET responses. Other classified requests can include errors and expose HTTP status for filters or breakdowns. SMTP observers count sent, retry, failed and bounced notifications independently of requests.

Modules declare namespaced events using the analytics_events fold notification and call m_analytics:record_event/3 for background events or /4 with the current request. See m_analytics and the application README for calling conventions and schema examples.

Edit on GitHub

Configuration

Configuration keys declared by this module. The defaults below are from the source code.

Module Key Type Default Description
mod_analytics row_budget integer 1000000 Maximum reserved group/time slots across all retained recordings.
mod_analytics require_consent boolean false Only collect request events when analytics_consent is true in the request context.

Observes

Notifications

observe_email_failed/2

Notify that we could NOT send an e-mail (there might be a bounce later...) The Context is the depickled z_email:send/2 context.

Notifications

observe_email_bounced/2

Bounced e-mail notification. The recipient is the e-mail that is bouncing. When the the message_nr is unknown the it is set to ‘undefined’. This can happen if…

Notifications

observe_email_sent/2

Notify that we could NOT send an e-mail (there might be a bounce later...) The Context is the depickled z_email:send/2 context.

Defined notifications

Models

Models

analytics

Read Site Analytics reports, manage recordings and submit trusted server-side events.

Controllers

Controllers

controller_admin_analytics

Serve the Site Analytics dashboard and its separate recording configuration page. Responses disable caching and search-engine indexing.

Dispatch rules

Dispatch rules

mod_analytics dispatch rules

URL dispatch rules defined by mod_analytics in apps/zotonic_mod_analytics/priv/dispatch/dispatch.