In-product JavaScript API
The FromUsers in-product JavaScript API lets your application initialize context, show surveys on demand, emit trigger events, and submit responses when you need programmatic control.
Prerequisites
Section titled “Prerequisites”fromusers-sdk.jsinstalled withdata-api-keyanddata-website-id. See Install the SDK.- At least one in-product survey on that website for end-to-end tests.
- Basic familiarity with your front-end codebase.
Core methods
Section titled “Core methods”| Method | Purpose |
|---|---|
| FromUsers.init | Initialize or update SDK configuration and user context |
| FromUsers.showSurvey | Display a specific survey from code |
| FromUsers.trackEvent | Emit a named event for custom triggers |
| FromUsers.submitResponse | Submit a response programmatically when your flow requires it |
Exact argument shapes appear in the snippet and API hints inside FromUsers. Use the method names above consistently in your codebase.
FromUsers.init
Section titled “FromUsers.init”Call init when you know who the user is or when attributes change after login.
Typical uses:
- Pass user attributes for audience rules.
- Provide dynamic values for personalization.
- Re-run setup after client-side authentication.
Example pattern:
FromUsers.init({ user: { id: "user_123", plan: "pro", role: "editor", },});Adapt property names to what your audience rules expect.
FromUsers.showSurvey
Section titled “FromUsers.showSurvey”Use showSurvey for explicit UI entry points:
- “Give feedback” buttons
- Help center widgets
- Post-task prompts you fully control in code
The survey should still be Live and not blocked by frequency or quarantine. Targeting may still apply depending on how you invoke the method. Always test the path you ship.
FromUsers.trackEvent
Section titled “FromUsers.trackEvent”Pair with a custom JS event trigger:
- In the survey, set the trigger event name (for example
export_complete). - In your app, call
FromUsers.trackEvent('export_complete')after the action succeeds. - Confirm the survey appears under your frequency rules.
FromUsers.trackEvent("export_complete");Keep event names stable and documented for researchers configuring triggers.
FromUsers.submitResponse
Section titled “FromUsers.submitResponse”Use submitResponse when your product UI collects answers outside the default survey chrome and you still want FromUsers to store the response. Most teams rely on the built-in survey UI instead. Prefer the standard display modes unless you have a custom form requirement.
SPA notes
Section titled “SPA notes”- Ensure the SDK is loaded before calling methods.
- After route changes, fire events or re-check eligibility for page-targeted surveys.
- Guard calls with feature detection if the script might be blocked.
if (window.FromUsers) { FromUsers.trackEvent("onboarding_finished");}Related
Section titled “Related”Common questions
When should I call showSurvey?
Use it to open a specific survey from your UI after the SDK is installed, for example from a Help menu or after a custom workflow step.
What does trackEvent do?
It records a named event your triggers can listen for, such as export_complete or onboarding_finished.
Is init required if I only use the script tag?
The script tag with data-api-key and data-website-id boots the SDK. Call FromUsers.init when you need to pass user attributes or refresh configuration from code.