Gleap SDK Setup
Guides users through integrating the Gleap SDK into their project. Supports JavaScript, iOS, Android, React Native, Flutter, Ionic/Capacitor, Cordova, and FlutterFlow.
Platform Detection
Detect the user's platform before proceeding. If the user explicitly states their platform, skip detection.
Auto-Detection Priority
Check in this order (first match wins):
-
pubspec.yamlexists?- Contains
flutterflowreferences or user mentions FlutterFlow -> FlutterFlow (platform-flutterflow.md) - Otherwise -> Flutter (
platform-flutter.md)
- Contains
-
package.jsonexists? Read it and checkdependencies+devDependencies:react-nativepresent -> React Native (platform-react-native.md)@capacitor/coreorcapacitor-corepresent -> Ionic/Capacitor (platform-ionic-capacitor.md)cordovapresent, orconfig.xmlexists with<widget>-> Cordova (platform-cordova.md)@angular/corepresent -> JavaScript (Angular)reactpresent (withoutreact-native) -> JavaScript (React)vuepresent -> JavaScript (Vue)nextpresent -> JavaScript (Next.js)nuxtpresent -> JavaScript (Nuxt)- Other or no framework -> JavaScript (generic npm)
- Use
platform-javascript.mdfor all JavaScript variants
-
*.xcodeproj,*.xcworkspace, orPodfileexists? -> iOS (platform-ios.md) -
build.gradle,build.gradle.kts, orapp/build.gradleexists? -> Android (platform-android.md) -
index.htmlexists (nopackage.json)? -> JavaScript CDN approach (platform-javascript.md) -
Server-side web framework detected? These all use the JavaScript SDK on the client side (
platform-javascript.md):composer.jsonexists (PHP / Laravel) — use CDN or npm depending on whether a JS build pipeline existsGemfilewithrails(Ruby on Rails) — use CDN in layouts, or npm if Webpacker/esbuild/importmap is presentrequirements.txt/pyproject.tomlwithdjangoorflask(Python) — use CDN in base templates*.cshtml/*.csprojfiles (.NET / ASP.NET) — use CDN in layout viewspom.xml/build.gradlewith Spring Boot (Java) — use CDN in Thymeleaf templates- Any other web framework (Go, Elixir/Phoenix, etc.) — use CDN approach
- Note: If the project also has a
package.jsonwith a frontend framework, step 2 already covers this.
-
Nothing detected -> Ask the user which platform they are targeting.
Detection Commands
Use Glob to scan for key files:
pubspec.yamlpackage.json**/*.xcodeproj**/*.xcworkspacePodfilebuild.gradlebuild.gradle.ktsapp/build.gradleconfig.xmlindex.htmlcomposer.jsonGemfilerequirements.txtpyproject.toml
If package.json is found, use Read to inspect its dependencies and devDependencies keys.
Project ID Resolution
Every SDK is initialized with the project's Project ID (formerly called "SDK key" or "API key"; the value is the same). It identifies the project, not a user: it is public, safe to commit and not a secret. Before asking the user for it, check these locations in order:
- User provided it in the conversation (e.g., "add Gleap with project ID abc123") — use it directly
.envfile in the project root — look forGLEAP_PROJECT_ID=...(older setups may have it asGLEAP_API_KEY=...; same value)- Environment variable — check
GLEAP_PROJECT_ID(or the olderGLEAP_API_KEY) viaecho $GLEAP_PROJECT_ID - Not found — ask the user for their Project ID (Gleap dashboard at https://app.gleap.ai, under Settings → Project → General, or on Settings → Widget → Install)
When it is found or provided, you may offer to save it to the project's .env file as GLEAP_PROJECT_ID for future use. It is not a secret, so it can also go straight into the initialization code.
Do not confuse it with a server API key (Settings → Developer → API keys): that one is secret, belongs only on a backend, and is never needed to install the SDK.
Workflow
Follow these steps in order:
- Fetch latest SDK versions: Run
scripts/get-latest-versions.shfrom this skill's directory. Use the returned versions in all install commands instead of hardcoded version numbers. - Detect platform using the priority rules above.
- Resolve the Project ID using the Project ID Resolution steps above.
- Confirm with user: State the detected platform and ask for confirmation. If the user already specified a platform, skip this step.
- Read platform guide: Read the matching
platform-{name}.mdfile from this skill's directory. - Install SDK: Walk the user through installing the dependency using the latest version from step 1. Run install commands when the user approves. Verify installation succeeded.
- Initialize SDK: Add initialization code using the resolved Project ID (SDK 19.5.0 or newer, JavaScript 19.6.0:
projectId/withProjectId:; older SDK versions take the same value under its old name, such astoken:,withToken:or{ API_KEY }). - Identify users: If the app has a logged-in user, wire the signed identity token (see "User Identification" below) with the platform's
setUserJwtcall from the platform guide. Plain unsignedidentifyonly when there is no backend. - Configure platform: Apply required permissions, manifest entries, or additional config from the platform guide.
- Verify: Suggest building/running the project to confirm integration works.
- Describe the PR: State whether identify is signed (identity token, legacy user hash or unsigned, and why), which environment variables the backend needs, and the required action in Gleap (see "What the PR description must say").
User Identification
Decide this once, before writing an identify call, and state the result in the PR description.
The app has a logged-in user (the normal case): signed identity token
Gleap trusts what the backend signs and nothing the browser or app says about itself. The flow:
- The backend signs an identity token: an HS256 JWT signed with one of the project's identity keys (Gleap dashboard > Settings → Security → Customer identity, step Create an identity key; the secret is shown once). Put the key id in the
kidheader and the secret in an environment variable. The secret never reaches the client.- Claims:
userId(required, the same id the app uses for the user), optionalemail,name,phone,company({ "id": "...", "name": "..." }),plan, provider ids such asstripeCustomerId,chargebeeCustomerId,paddleCustomerId,lemonsqueezyCustomerId,revenuecatAppUserId,shopifyCustomerId,woocommerceCustomerId. Every further top-level claim (string, number or boolean) becomes a signed attribute on the contact. exp: required for new integrations, at most one hour ahead. Omit claims the app does not have; never invent values.
- Claims:
- Expose it on an authenticated endpoint of the app's backend (for example
GET /api/gleap-token) that returns the token for the signed-in user. - The app calls
setUserJwt(token)after login and on every app start while a user is signed in, andclearIdentity()on logout. Everything Gleap should know about the contact is a claim in the token; the client passes no other contact fields. - Token refresh (optional): register
setUserJwtProviderwith a function that fetches a fresh token; the SDK calls it when a token has expired. Every SDK that hassetUserJwthas it; it never replaces thesetUserJwtcall.
What the project's mode means. Creating an identity key protects nothing and doesn't switch the project. New projects start in Signed mode and accept identity tokens only (no user hash). Existing (Classic) projects keep working exactly as before until someone checks a token on the same page (Check a token from your backend) and clicks Turn on signed sessions. Guide: https://docs.gleap.ai/en/articles/709-customer-identity; moving an existing user-hash integration: https://docs.gleap.ai/en/articles/16752008-upgrade-to-identity-tokens
| Platform | Call |
|----------|------|
| JavaScript | Gleap.setUserJwt(token) |
| iOS | Gleap.setUserJwt(token) |
| Android | Gleap.getInstance().setUserJwt(token) |
| React Native | Gleap.setUserJwt(token) |
| Flutter | Gleap.setUserJwt(token: token) |
| Ionic/Capacitor | Gleap.setUserJwt({ token }) |
| Cordova | No setUserJwt; pass the token as the third argument of identify(userId, data, token) |
| FlutterFlow | A Custom Action that calls the Flutter method |
Installed SDK without setUserJwt (older version, Cordova): pass the token where the legacy user hash goes, as the third argument of identify(userId, data, token) (per-platform shape in the platform guide). Suggest updating the SDK in the PR so setUserJwt can be used. An SDK without setUserJwt sends no session grant, so on a project in Signed mode Kai treats those users as unverified until the app is upgraded.
Backend example (Node, npm install jsonwebtoken; any JWT library in any language works the same way: HS256, kid header, one-hour expiry):
import jwt from "jsonwebtoken";
export function gleapIdentityToken(user) {
return jwt.sign(
{
userId: user.id,
email: user.email,
name: user.name,
company: { id: user.companyId, name: user.companyName },
plan: user.plan,
stripeCustomerId: user.stripeCustomerId,
},
process.env.GLEAP_IDENTITY_SECRET,
{ algorithm: "HS256", keyid: process.env.GLEAP_IDENTITY_KEY_ID, expiresIn: "1h" }
);
}
Environment variables the backend needs: GLEAP_IDENTITY_KEY_ID (the key id, shown in the dashboard) and GLEAP_IDENTITY_SECRET (the secret, shown once on creation). Add them to .env.example with empty values, never commit real values.
No backend to change: plain unsigned identify
Only when the app has no backend (static site, prototype, a client-only app): call identify(userId, data) without a token. Say so in the PR: the identity is unverified, Kai shows no billing or account data to such contacts, and fields the project marks "Only signed updates" (Settings > Inbox & tickets > Data attributes, Contact tab) ignore these writes. Never put plan, billing, company or provider ids in an unsigned identify; they belong in the token.
Legacy user hash
Existing integrations may pass a hex HMAC-SHA256 of the user id, computed server-side with the project secret, as the user hash (third argument of identify). It keeps working on existing projects while their "Accept legacy user hash" switch is on; projects created in Signed mode don't accept it. New integrations use the identity token; when migrating, replace the hash endpoint with the token endpoint and the identify(..., hash) call with setUserJwt(token).
What the PR description must say
- Whether identify is signed with the identity token, signed with the legacy user hash, or unsigned, and why.
- Which environment variables the backend needs (for the token:
GLEAP_IDENTITY_KEY_ID,GLEAP_IDENTITY_SECRET). - For the token, a required action for the maintainer: in Gleap under Settings → Security → Customer identity, create an identity key, set both environment variables on the backend, check a token with Check a token from your backend, and click Turn on signed sessions if the page still offers it (until the variables are set, the endpoint returns no token and login keeps working).
- That the Project ID in the code is public and safe to commit.
Post-Setup API Guidance
After setup, if the user asks about using the Gleap API, refer to the "Common API Usage" section in the relevant platform file. The most common tasks are:
- Identify users: Signed identity token via
setUserJwtwhen the app has a logged-in user (see "User Identification"); plainidentifyonly without a backend - Track events: Log custom events at key points in the app
- Custom data: Attach contextual data to feedback tickets
- Widget control: Programmatically open/close the Gleap widget
Re-read the platform file's API section for the correct method signatures, as they differ between platforms.
Important Notes
initialize()must be called exactly once in the application lifecycle- For cross-platform frameworks (React Native, Flutter, Ionic/Capacitor), both iOS and Android platform-specific configuration (permissions) is needed
- The JavaScript CDN approach works for any web context and does not require npm
- User identification: the identity token is signed on the backend with the project's identity key and passed with
setUserJwt; the legacy user hash (HMAC of the user id with the project secret) is also computed server-side and keeps working on existing projects while "Accept legacy user hash" is on. Never sign or hash on the client - Custom data supports only primitive values (strings, numbers, booleans) with a max of 35 keys; attributes that gate data or billing (plan, provider customer ids, company) go into the identity token's claims, not into unsigned custom data
Common Troubleshooting
pod installfails: Runpod repo updatefirst, then retry- Gradle sync fails: Ensure
minSdkVersionis at least 21 - Flutter version conflict: Add
tools:overrideLibrary="io.gleap.gleap_sdk"to AndroidManifest.xml - Widget not showing on web: Check Content Security Policy headers allow
sdk.gleap.io - Soft-reload clears widget (Rails/Turbo): Call
Gleap.getInstance().softReInitialize()after reload - Android hardware acceleration: Do not set
android:hardwareAccelerated="false"at application level

微信扫一扫