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>
impl<'a> Tag<'a>
Sourcepub fn script_host(self, host: impl Into<String>) -> Self
pub fn script_host(self, host: impl Into<String>) -> Self
Uses another script host on this page.
Sourcepub fn excluded_paths<I, S>(self, paths: I) -> Self
pub fn excluded_paths<I, S>(self, paths: I) -> Self
Uses these excluded paths on this page.
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 or replaces one extra attribute on this page.
Sourcepub fn queue_stub(self, queue_stub: bool) -> Self
pub fn queue_stub(self, queue_stub: bool) -> Self
Prints the queue stub on this page, or not.
Sourcepub fn nonce(self, nonce: impl Into<String>) -> Self
pub fn nonce(self, nonce: impl Into<String>) -> Self
The Content Security Policy nonce for the scripts.
Sourcepub fn props<I, K, V>(self, props: I) -> Self
pub fn props<I, K, V>(self, props: I) -> Self
Merges page props over the configured ones. A Value::Null (or
None) removes a prop. Can be called more than once.
Sourcepub fn will_render(&self) -> bool
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.
Sourcepub fn page_props(&self) -> Vec<(String, Value)>
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.
Sourcepub fn attributes(&self) -> Vec<(String, Option<String>)>
pub fn attributes(&self) -> Vec<(String, Option<String>)>
The tracker tag’s attributes in order. None is an attribute with no
value (defer).
Sourcepub fn to_html(&self) -> SafeHtml
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§
impl HtmlSafe for Tag<'_>
askama only.