DocsSDKsWeb SDK
SDKsOfficial

Web SDK

Integrate Sankofa into your web applications with support for event tracking and identity resolution via NPM or CDN.

Source of truthhttps://github.com/Sankofa-HQ/sankofa_sdk_web

The Sankofa Web SDK is the core integration layer for browser-based applications. View source on GitHub. It provides a high-level API for tracking user behavior, capturing identity profile updates, and recording user sessions via session replay.

Integration Methods

You can integrate Sankofa using either the NPM package (recommended for modern frameworks) or via a direct Script tag (ideal for simple sites or CMS integrations).

1. Script Tag (CDN)

Copy and paste this snippet into the <head> or at the end of the <body> of your website. This method makes the Sankofa global object available immediately.

<script src="https://cdn.jsdelivr.net/npm/@sankofa/[email protected]/dist/sankofa.min.js"></script>
<script>
  Sankofa.init({
    apiKey: "your-api-key",
    endpoint: "https://api.sankofa.dev"
  });
</script>

2. NPM / Yarn

For projects using React, Vue, or other modern frameworks:

npm install @sankofa/browser

Initialize the SDK once in your application entry point:

import { Sankofa } from "@sankofa/browser";

await Sankofa.init({
  apiKey: "your-api-key",
  endpoint: "https://api.sankofa.dev",
});

Core Functionality

Tracking Events

Track user actions with custom properties to build your event analytics.

Sankofa.track("purchased_item", {
  item_id: "sku_123",
  price: 49.99,
  currency: "USD",
  category: "electronics"
});

Identity and People

Sankofa uses a dual-method approach to manage user identity: identify for internal IDs and setPerson for human-readable profile traits.

Identifying Users

Use identify when a user logs in to link their anonymous history to their persistent internal ID.

await Sankofa.identify("user_987");

Setting Profile Traits

Use setPerson to enrich user profiles with information that appears in the Sankofa dashboard.

await Sankofa.setPerson({
  name: "John Doe",
  email: "[email protected]",
  avatar: "https://example.com/avatars/john.jpg",
  // You can also add custom attributes
  plan: "premium",
  signup_date: "2024-03-17"
});

Default Properties

The Web SDK automatically collects the following properties with every event:

  • $current_url: The full URL of the page.
  • $host: The domain name.
  • $pathname: The URL path.
  • $referrer: The referring URL.
  • $browser: Browser name (e.g., Chrome, Firefox).
  • $os: Operating system.
  • $screen_height / $screen_width: Device resolution.

Advanced Configuration

OptionTypeDefaultDescription
apiKeystringRequiredYour project API key.
endpointstringRequiredYour Sankofa engine URL (e.g., https://api.sankofa.dev).
debugbooleanfalseEnable console logging.
flushIntervalMsnumber5000How often to batch and send events.
autocapturebooleantrueAutomatically track pageviews.

🎥 Session Replay

Web Session Replay uses the industry-standard rrweb engine to capture DOM changes and user interactions.

1. Register the Plugin

Add the rrwebReplayPlugin to your initialization options.

import { Sankofa } from '@sankofa/browser';
import { rrwebReplayPlugin } from '@sankofa/replay-rrweb';

Sankofa.init({
  apiKey: 'YOUR_PROJECT_API_KEY',
  endpoint: 'https://api.sankofa.dev',
  plugins: [
    rrwebReplayPlugin({
      flushIntervalMs: 5000,
      maxEventsPerChunk: 250,
    })
  ]
});

2. Privacy & Masking

By default, the plugin enables maskAllInputs, which replaces all text entered into input fields with asterisks. You can fine-tune privacy using specific CSS selectors.

OptionDescription
blockSelectorElements matching this selector will be completely removed from the recording.
maskSelectorText content inside these elements will be replaced with generic characters.
ignoreSelectorPrevents recording events (like clicks) on these elements.

🛠 Advanced Configuration

OptionTypeDefaultDescription
apiKeystringRequiredYour project API key.
endpointstringRequiredYour Sankofa engine URL.
debugbooleanfalseEnable console logging.
flushIntervalMsnumber5000How often to batch and send events.
autocapturebooleantrueAutomatically track pageviews.

📑 Next Steps