JavaScript SDK
Integrate the Mythic Analytics JavaScript SDK to track events, page views, and user identity from the browser with automatic batching, session management, and privacy controls.
Overview
The Mythic Analytics JavaScript SDK captures events, page views, and user identity data from the browser. It manages batching, sessions, attribution, and remote configuration automatically.
Key capabilities:
- Initialize with a publishable key (
pk_prefix, safe for client-side use) - Track custom events with
captureand page views withpageview - Identify users with
identifyand create aliases withalias - Manage super properties that attach to every event
- Control consent, opt-in/opt-out, and HIPAA compliance
- Auto-capture page views, page leaves, UTM parameters, and click IDs
- Remote configuration for tags, snippets, and transformers
The SDK uses a publishable key starting with pk_. This key is safe to expose in client-side code. Never use admin or secret keys in the browser.
Install or load the SDK
Load the script or install from npm
Use a script tag for quick embeds:
<script
src="https://cdn.mythic-analytics.com/sdk/latest/mythic.min.js"
crossorigin="anonymous"
></script>
Or install from npm for bundlers:
npm install @mythic/analytics
# or
yarn add @mythic/analytics
Import or reference the global
<script>
window.mythic = window.Mythic.init("pk_your_publishable_key");
</script>
import { init } from "@mythic/analytics";
const mythic = init("pk_your_publishable_key");
const { init } = require("@mythic/analytics");
const mythic = init("pk_your_publishable_key");
After this step, you have a mythic instance you can call methods on.
Initialize the SDK
init(key, config?)
Create a configured Mythic client instance.
Publishable project key starting with pk_.
Optional configuration overrides. See the full config reference below.
import { init } from "@mythic/analytics";
const mythic = init("pk_your_publishable_key", {
api_host: "https://analytics.yourdomain.com",
debug: true,
batch_size: 20,
autocapture: true,
capture_pageview: true,
hipaa: false,
});
Last updated today