pub struct Config { /* private fields */ }Expand description
Settings for the tracking script.
Every setting is optional except the site id. Build it once at start up and share it, for example in your app state.
use privatus_analytics::{props, Config, Spa};
let config = Config::new()
.site_id("pa_YOURSITEID")
.modules(["engage", "auto"])
.excluded_paths(["/admin/*", "/preview/*"])
.spa(Spa::History)
.props(props! { "app_version" => "2.4" });§When the tag prints
The tag prints nothing without a site id. When Config::enabled is not
set, the tag is on in release builds and off in debug builds. The check is
cfg!(not(debug_assertions)), so cargo run and cargo test print
nothing, and cargo build --release does. Set enabled(true) or
enabled(false) to choose yourself.
Implementations§
Source§impl Config
impl Config
Sourcepub fn new() -> Self
pub fn new() -> Self
Settings with every default. The site id then comes from the
PRIVATUS_SITE_ID environment variable.
Sourcepub fn site_id(self, site_id: impl Into<String>) -> Self
pub fn site_id(self, site_id: impl Into<String>) -> Self
The site id, which starts with pa_. You find it under Site settings,
Tracking. Without it, falls back to PRIVATUS_SITE_ID.
Sourcepub fn script_host(self, host: impl Into<String>) -> Self
pub fn script_host(self, host: impl Into<String>) -> Self
Where /js/pa.js is served. Falls back to PRIVATUS_SCRIPT_HOST, then
https://privatusstats.com. A trailing slash is removed. Change it
only if you host your own copy.
Sourcepub fn modules<I, S>(self, modules: I) -> Self
pub fn modules<I, S>(self, modules: I) -> Self
Tracker modules to load (data-modules), for example
["engage", "auto"]. Setting it replaces the tracker default, so keep
engage for time on page and scroll depth. An empty list loads none.
Sourcepub fn default_modules(self) -> Self
pub fn default_modules(self) -> Self
Goes back to the tracker’s default modules.
Sourcepub fn excluded_paths<I, S>(self, paths: I) -> Self
pub fn excluded_paths<I, S>(self, paths: I) -> Self
Path globs the tracker never counts (data-exclude), for example
["/admin/*"].
Sourcepub fn domains<I, S>(self, domains: I) -> Self
pub fn domains<I, S>(self, domains: I) -> Self
Count only these hostnames (data-domains). Not set counts every host.
Sourcepub fn spa(self, spa: Spa) -> Self
pub fn spa(self, spa: Spa) -> Self
Single-page app mode (data-spa). Only modes other than
Spa::Auto are printed.
Sourcepub fn manual(self, manual: bool) -> Self
pub fn manual(self, manual: bool) -> Self
true turns off the automatic pageview (data-manual="true").
Sourcepub fn enabled(self, enabled: bool) -> Self
pub fn enabled(self, enabled: bool) -> Self
true or false forces the tag on or off. Not set means on in release
builds and off in debug builds.
Sourcepub fn auto_inject(self, auto_inject: bool) -> Self
pub fn auto_inject(self, auto_inject: bool) -> Self
Whether the axum and actix-web middleware add the tag. Adding the
middleware turns it on, so this defaults to true. Set false to
keep the middleware in place but switched off.
Sourcepub fn extra_attribute(
self,
name: impl Into<String>,
value: impl Into<String>,
) -> Self
pub fn extra_attribute( self, name: impl Into<String>, value: impl Into<String>, ) -> Self
Adds any other attribute to the tracker tag, for example
("data-mask", "/orders/*->/orders/:id"). A name set twice keeps the
later value.
Sourcepub fn props<I, K, V>(self, props: I) -> Self
pub fn props<I, K, V>(self, props: I) -> Self
Page props sent with every pageview and event. For props that change
per request, see the middleware’s props_fn or Tag::props.
Never put names, emails, user ids or anything else that points to one person here.
Sourcepub fn queue_stub(self, queue_stub: bool) -> Self
pub fn queue_stub(self, queue_stub: bool) -> Self
true prints the tracker’s queue stub first, so privatus.track
calls made before pa.js loads are kept and sent later.
Sourcepub fn tag(&self) -> Tag<'_>
pub fn tag(&self) -> Tag<'_>
The tag for these settings. Change any setting for one page on the
returned Tag.
Sourcepub fn resolved_site_id(&self) -> Option<String>
pub fn resolved_site_id(&self) -> Option<String>
The site id in use: the configured one, else PRIVATUS_SITE_ID, else
None.
Sourcepub fn resolved_script_host(&self) -> String
pub fn resolved_script_host(&self) -> String
The script host in use, without a trailing slash.
Sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Whether the tag is on: the enabled setting when set, else
cfg!(not(debug_assertions)) (on in release builds).
Sourcepub fn is_auto_inject(&self) -> bool
pub fn is_auto_inject(&self) -> bool
Whether the middleware should add the tag. Defaults to true.