Skip to content

Installation

The Latch JavaScript SDK handles access checks, paywall display, identity management, and event tracking in browser environments.

The SDK is intended for bundled JavaScript applications.

  • it is not currently published to npm
  • the API does not currently expose a hosted /sdk/latch.js asset

If you need a browser integration today, start with Plain HTML or WordPress.

import { init } from '@latch/sdk';

Call init() once when your page loads.

import { init } from '@latch/sdk';
init({
apiKey: 'pk_your_publishable_key',
apiUrl: 'https://your-latch-api',
});

The SDK will auto-init if your bundle sets window.__LATCH_CONFIG__ before loading the SDK code:

<script>
window.__LATCH_CONFIG__ = {
apiKey: 'pk_your_publishable_key',
apiUrl: 'https://your-latch-api',
};
</script>
OptionTypeRequiredDescription
apiKeystringYesYour publishable key (pk_...).
apiUrlstringNoBase URL of your Latch API. Defaults to "".
userIdstringNoKnown logged-in reader ID.
anonymousIdstringNoOverride the stored anonymous ID.
debugbooleanNoEnable console logging.
onPaywallfunctionNoCustom callback for denied access.
onCheckoutfunctionNoCalled when the built-in Subscribe button is clicked.
paywallSelectorstringNoCSS selector used by the inline template.

When you call init():

  1. the SDK creates or loads an anonymous ID
  2. it queues an initial pageview event
  3. it starts a 5-second flush timer for queued events
  4. it registers a beforeunload flush