Skip to main content

Config

Struct Config 

Source
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

Source

pub fn new() -> Self

Settings with every default. The site id then comes from the PRIVATUS_SITE_ID environment variable.

Source

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.

Source

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.

Source

pub fn modules<I, S>(self, modules: I) -> Self
where I: IntoIterator<Item = S>, S: Into<String>,

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.

Source

pub fn default_modules(self) -> Self

Goes back to the tracker’s default modules.

Source

pub fn excluded_paths<I, S>(self, paths: I) -> Self
where I: IntoIterator<Item = S>, S: Into<String>,

Path globs the tracker never counts (data-exclude), for example ["/admin/*"].

Source

pub fn domains<I, S>(self, domains: I) -> Self
where I: IntoIterator<Item = S>, S: Into<String>,

Count only these hostnames (data-domains). Not set counts every host.

Source

pub fn spa(self, spa: Spa) -> Self

Single-page app mode (data-spa). Only modes other than Spa::Auto are printed.

Source

pub fn manual(self, manual: bool) -> Self

true turns off the automatic pageview (data-manual="true").

Source

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.

Source

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.

Source

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.

Source

pub fn props<I, K, V>(self, props: I) -> Self
where I: IntoIterator<Item = (K, V)>, K: Into<String>, V: Into<Value>,

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.

Source

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.

Source

pub fn tag(&self) -> Tag<'_>

The tag for these settings. Change any setting for one page on the returned Tag.

Source

pub fn resolved_site_id(&self) -> Option<String>

The site id in use: the configured one, else PRIVATUS_SITE_ID, else None.

Source

pub fn resolved_script_host(&self) -> String

The script host in use, without a trailing slash.

Source

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).

Source

pub fn is_auto_inject(&self) -> bool

Whether the middleware should add the tag. Defaults to true.

Trait Implementations§

Source§

impl Clone for Config

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Config

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Config

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl PartialEq for Config

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Config

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more