Skip to main content

Tag

Struct Tag 

Source
pub struct Tag<'a> { /* private fields */ }
Expand description

The script tag for one page. Get one with Config::tag.

Every setting can be changed for this page only, and page props set here are merged over the configured ones. A Value::Null (or None) removes one.

use privatus_analytics::{props, Config};

let config = Config::new().site_id("pa_YOURSITEID").enabled(true);
let html = config
    .tag()
    .modules(["engage", "auto"])
    .props(props! { "plan" => "pro" })
    .nonce("r4nd0m")
    .to_html();
assert!(html.as_str().contains(r#"data-modules="engage,auto""#));

Tag implements Display, so format!("{tag}") and {{ tag }} style templates print the HTML without escaping it again.

Implementations§

Source§

impl<'a> Tag<'a>

Source

pub fn new(config: &'a Config) -> Self

The tag for these settings.

Source

pub fn site_id(self, site_id: impl Into<String>) -> Self

Uses another site id on this page.

Source

pub fn script_host(self, host: impl Into<String>) -> Self

Uses another script host on this page.

Source

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

Loads these modules on this page.

Source

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

Uses these excluded paths on this page.

Source

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

Uses these domains on this page.

Source

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

Uses this single-page app mode on this page.

Source

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

Turns manual mode on or off on this page.

Source

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

Forces the tag on or off on this page.

Source

pub fn extra_attribute( self, name: impl Into<String>, value: impl Into<String>, ) -> Self

Adds or replaces one extra attribute on this page.

Source

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

Prints the queue stub on this page, or not.

Source

pub fn nonce(self, nonce: impl Into<String>) -> Self

The Content Security Policy nonce for the scripts.

Source

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

Merges page props over the configured ones. A Value::Null (or None) removes a prop. Can be called more than once.

Source

pub fn config(&self) -> &Config

The settings this tag uses, with the per-page changes.

Source

pub fn will_render(&self) -> bool

Whether the tracker prints: there is a site id and the tag is on. When this is false, Tag::to_html prints at most the queue stub.

Source

pub fn page_props(&self) -> Vec<(String, Value)>

The configured props with the per-page props merged on top. Keys are cleaned. Null values are still in the list.

Source

pub fn attributes(&self) -> Vec<(String, Option<String>)>

The tracker tag’s attributes in order. None is an attribute with no value (defer).

Source

pub fn to_html(&self) -> SafeHtml

The HTML: the queue stub (when on), the page props script (when there are props), then the tracker tag, one per line.

When the tag is off or there is no site id, it is only the queue stub (when on, with the nonce), so privatus.track calls in your own JavaScript never fail; or empty when the stub is off. No tracker and no page props script print then.

Trait Implementations§

Source§

impl<'a> Clone for Tag<'a>

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<'a> Debug for Tag<'a>

Source§

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

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

impl Display for Tag<'_>

Source§

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

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

impl From<Tag<'_>> for SafeHtml

Source§

fn from(tag: Tag<'_>) -> SafeHtml

Converts to this type from the input type.
Source§

impl HtmlSafe for Tag<'_>

Available on crate feature askama only.
Source§

impl Render for Tag<'_>

Available on crate feature maud only.
Source§

fn render_to(&self, buffer: &mut String)

Appends a representation of self to the given buffer. Read more
Source§

fn render(&self) -> PreEscaped<String>

Renders self as a block of Markup.

Auto Trait Implementations§

§

impl<'a> Freeze for Tag<'a>

§

impl<'a> RefUnwindSafe for Tag<'a>

§

impl<'a> Send for Tag<'a>

§

impl<'a> Sync for Tag<'a>

§

impl<'a> Unpin for Tag<'a>

§

impl<'a> UnsafeUnpin for Tag<'a>

§

impl<'a> UnwindSafe for Tag<'a>

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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