Getting StartedOverview
Getting Started

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 capture and page views with pageview
  • Identify users with identify and create aliases with alias
  • 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>

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.

keystring
Required

Publishable project key starting with pk_.

configobject

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,
});