pub struct DataLayer { /* private fields */ }
Expand description
A wrapper around Google’s gtag.js framework.
Implementations§
Source§impl DataLayer
impl DataLayer
Sourcepub fn new(id: impl Into<String>) -> Self
pub fn new(id: impl Into<String>) -> Self
Create a DataLayer
object that can be used to push data with the given ID.
Sourcepub fn push_simple(&self, cmd: &str)
pub fn push_simple(&self, cmd: &str)
Push data with no parameters.
Sourcepub fn push(&self, cmd: &str, params: &impl Serialize) -> Result<()>
pub fn push(&self, cmd: &str, params: &impl Serialize) -> Result<()>
Push data with the given parameters.
This function can fail if there is an error serializing the data to a JsValue
.
As a parameter value, this accepts any type that can be serialized to Json using Serde.
This can be done by deriving Serialize
from serde
or using the json!
macro from
serde_json
.
#[derive(Serialize)]
struct Pageview {
page_title: Option<String>,
page_location: Option<String>,
page_path: Option<String>,
}
json!({
"page_title": "index.html",
"page_path": "/",
})
Auto Trait Implementations§
impl Freeze for DataLayer
impl RefUnwindSafe for DataLayer
impl Send for DataLayer
impl Sync for DataLayer
impl Unpin for DataLayer
impl UnwindSafe for DataLayer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more