[][src]Function gtm_js::push

pub fn push(vars: &impl Serialize) -> Result<()>

Push variables and/or events.

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 PageviewEvent {
    event: String,
    page_path: String,
}

impl PageviewEvent {
    fn new(path: String) -> Self {
        PageviewEvent {
            event: "custom-page-view",
            page_path: path,
        }
    }
}
json!({
    "event": "custom-page-view",
    "page_path": "/path",
})