Tracking Methods
Track custom events, page views, user identity, and manage session state with the Mythic Analytics SDK core methods.
Core tracking methods
All examples assume you have created const mythic = init(...).
capture(event, properties?)
Track a custom event with optional properties.
Event name, such as Signup started or Checkout completed.
Additional properties. Merged with super properties and auto-captured context.
mythic.capture("Signup started", {
plan: "pro_monthly",
referrer: document.referrer,
experiment_variant: "landing_b",
});
pageview(properties?)
Send a page view event. The SDK auto-includes URL, title, referrer, and performance metrics.
Optional additional properties.
// On initial load
mythic.pageview({ page: "/pricing", campaign: "spring_promo" });
// In a SPA router hook
router.afterEach((to) => {
mythic.pageview({ page: to.fullPath });
});
By default the SDK auto-captures page views on load and SPA navigation (History API). You only need to call pageview() manually if you disable capture_pageview or capture_spa_pageview.
identify(userId, properties?)
Associate the current session with a known user ID.
Stable identifier for the user, e.g., usr_a1b2c3d4.
User properties such as email, plan, or role. Sent as a $identify event.
mythic.identify("usr_7f3c92d8", {
email: "jane@acme.com",
full_name: "Jane Chen",
plan: "enterprise",
team_id: "team_b84f21e7",
});
alias(alias)
Create an alias linking the current distinct ID to another identifier.
The alias to create. Sends a $create_alias event.
mythic.alias("user_email@acme.com");
reset(options?)
Clear local user identity and session state. Typically called on logout.
Optional flags. Pass { resetInitialAttribution: true } to also clear first-touch attribution data.
// Standard reset on logout
mythic.reset();
// Full reset including attribution
mythic.reset({ resetInitialAttribution: true });
After reset, calls to capture use a new anonymous distinct ID until you call identify again.
flush()
Force-send all queued events immediately. Use before page unload.
window.addEventListener("beforeunload", () => {
mythic.flush();
});
Last updated today