The metrics namespace sends analytics events to metatell's measurement
backend (Google Analytics gtag). The current user id is attached
automatically when available.
import { metrics } from "@urth/metatell-sdk";
If gtag is not present on the page, the calls are no-ops and log a warning, so
they are safe to call unconditionally.
Record a click on a target. Sent as the mt-click event with the target in the
target parameter. target is reserved: a target key in params overrides
the first argument.
metrics.click("click_button", {
button_name: "help",
});
Record a screen / page transition. Sent as the mt-transition event with the
URL in the destination parameter. destination is reserved: a destination
key in params overrides the first argument.
metrics.transition("https://example.com", {
position: { x: 100, y: 100, z: 100 },
});
Record a custom event with an arbitrary name and parameters.
metrics.sendEvent("custom_event", {
event_param: "foo",
});
params argument is optional and accepts any
Record<string, unknown>.user_id field is added to every event automatically when the current user
id is known; you do not need to pass it yourself. When the id is known, it
overrides any user_id you pass in params.params: target (for click) and destination
(for transition) replace the method's argument, and user_id is replaced by
the SDK when the current user id is known.