Gleap JavaScript SDK
The Gleap JavaScript SDK, currently at version 15.2.8, offers an AI-native platform for comprehensive customer support, feedback collection, and bug reporting within web applications. It integrates a range of features including an autonomous AI agent (Kai) designed for resolving customer inquiries and automating workflows, a built-in Help Center, outbound messaging, product roadmapping tools, and a unified multichannel inbox. The package maintains an active development pace with frequent minor releases, addressing features like video calling capabilities, improved platform/device detection, and updates to cookie management defaults. Its key differentiators lie in its holistic approach to customer engagement, extending beyond basic feedback forms to include advanced AI assistance and a full suite of support tools.
Common errors
-
ReferenceError: Gleap is not defined
cause The Gleap SDK was not imported correctly, or the script tag for the SDK was not loaded before its usage in a non-module context.fixEnsure `import Gleap from 'gleap';` is at the top of your module, or if using a script tag, place it before any code that references `Gleap`. -
Gleap.initialize is not a function
cause This usually indicates that `Gleap` was imported incorrectly (e.g., as a named import instead of default) or that the imported object does not expose an `initialize` method.fixVerify that you are using `import Gleap from 'gleap';` and then calling `Gleap.initialize(...)` directly on the default-imported object. -
No Gleap feedback button or widget is visible on the page.
cause The SDK might not have been initialized or the provided SDK token is incorrect/inactive, or the widget is hidden by configuration.fixCheck if `Gleap.initialize('YOUR_SDK_TOKEN')` is called with the correct token. Confirm the Gleap dashboard settings don't have the widget disabled or restricted by page rules.
Warnings
- gotcha As of v15.2.2, Gleap enabled cookie mode by default. This change affects session management, particularly on shared subdomains, potentially altering existing behavior if you had specific cookie configurations.
- gotcha Failing to initialize the SDK with a valid `SDK-TOKEN` will prevent the Gleap widget and associated functionality from appearing or working correctly.
- gotcha The Gleap SDK is designed for client-side environments (browsers). Attempting to run its initialization or core functionality directly in a Node.js server-side environment without proper mocking or conditional loading can lead to errors.
Install
-
npm install gleap -
yarn add gleap -
pnpm add gleap
Imports
- Gleap
const Gleap = require('gleap');import Gleap from 'gleap';
- initialize
import { initialize } from 'gleap';import Gleap from 'gleap'; Gleap.initialize('YOUR_SDK_TOKEN'); - Gleap (type)
import Gleap from 'gleap'; type GleapInstance = typeof Gleap;
Quickstart
import Gleap from 'gleap';
// Replace 'YOUR_SDK_TOKEN' with your actual token from the Gleap dashboard.
// For production, consider using environment variables for security.
const SDK_TOKEN = process.env.GLEAP_SDK_TOKEN || 'YOUR_SDK_TOKEN_HERE';
if (SDK_TOKEN === 'YOUR_SDK_TOKEN_HERE') {
console.warn('Gleap SDK: SDK_TOKEN is a placeholder. Please replace it with your actual token.');
}
try {
Gleap.initialize(SDK_TOKEN);
console.log('Gleap SDK initialized successfully.');
// Example of identifying a user (optional, but common practice)
Gleap.identify('user-123', {
name: 'John Doe',
email: 'john.doe@example.com',
plan: 'premium'
});
// To open the Gleap widget programmatically (e.g., from a custom button)
// Gleap.open();
} catch (error) {
console.error('Failed to initialize Gleap SDK:', error);
}