Documentation Index
Fetch the complete documentation index at: https://docs.sprig.com/llms.txt
Use this file to discover all available pages before exploring further.
Getting Started
Overview
The Sprig Javascript SDK, when installed in your website or web app, allows you to track your customer’s in-product behavior and display Sprig studies when they perform certain actions. To learn more about SDKs and web installation options provided by Sprig, click here.Requirements
- Join your teammates on Sprig (check with your Sprig admin whether team discovery is on, or simply have a team member invite you via your email address). This will give you access to your team’s environment IDs, as well as the interactive Installation Guide.
- Ensure you have access to your web codebase, and can deploy to a development and/or production environment
Install SDK
If you are installing the Sprig Javascript SDK, we recommend installing Sprig via the HTML code snippet. This installation method automatically ensures you have the latest version of our SDK, reducing the workload on your engineering team since they won’t have to fetch and deploy an update every time Sprig releases a new version of the SDK. You will automatically have access to the latest features on the latest SDKs. For teams that prefer to use a package manager, Sprig can also be installed via npm or Yarn. Note that your engineering team will need to do some additional work to update in order to access the latest features and bug fixes.Obtain an Environment ID
Sprig provides two environments, Development and Production, each with its own corresponding ENVIRONMENT_ID (which can be found in Integrations > Javascript SDK). The Development environment is recommended for initially setting up and verifying your installation. Then, you can use the Production environment to deploy studies to real users.Install with HTML (recommended)
Add the following JavaScript snippet to every page on your website where you want Sprig to track your users. You can paste the snippet anywhere on the page, but preferably at the bottom of the document, before the</body> tag. Be sure to swap in the correct ENVIRONMENT_ID.
Install with npm/Yarn
Use the following shell command to install the Sprig SDK through npm or YARN. With this installation method, Sprig will be bundled with the rest of your front-end application and be immediately accessible on page load. Note that you will have to update the SDK manually to receive the latest functionality. We recommend you update the package monthly for improved functionality and bug fixes.npm
Yarn
configure can be found below in the Customize Appearance section.
Usage with Next.js (Sprig SDK v2.42.0 or higher)
The Sprig SDK is a client side SDK that should only be run in client components in Next.js applications. Former versions of the Sprig SDK relied on the browsers globalwindow. Starting with v2.42.0 of the SDK, calls to window have been transitioned to globalThis with optional chaining so calls fail silently if Sprig does not exist. If you are still using a previous version of the SDK, please skip to Usage with Next.js (Sprig SDK v.2.41.3 or lower) for the recommended implementation of Sprig with your Next.js application.
After installing the Sprig SDK through npm or YARN, initialize Sprig with your ENVIRONMENT_ID:
Usage with Next.js (Sprig SDK v2.41.3 or lower)
The Sprig SDK is a client side SDK that relies on the browsers globalwindow and other client side APIs, meaning that the Sprig SDK should only be run in client components in Next.js applications. We recommend creating a client side context for the Sprig SDK to ensure that only one instance of the Sprig SDK is configured.
Create the Sprig Context and load the Sprig SDK dynamically in a useEffect:
SprigContextProvider within your application:
Updating the Sprig SDK with npm or Yarn
When using npm or Yarn, you should regularly update your Sprig installation with the latest features by running the following command:npm
YARN
CSP Configuration
Using Sprig for Web studies may require you to update your web application’s Content Security Policy (CSP). This may be required because Sprig uses third-party libraries to support JavaScript. The following list of sources is required to use Video & Voice questions:- Base64 SVGs and fonts.
- Connecting to Mux (for streaming and short video uploads).
- Connecting to Google APIs (for long video uploads).
Sprig CSP
Sprig CSP for Voice/Video
Info As every company has different security policies, the example may not reflect the complete configuration. You may need to add additional keys and values in order to comply with your own organization’s policies.
Verify Installation
- Load a page from your website/web app that has the Sprig SDK installed
- Open the developer console to the Network tab
- Find a network request named
configthat hitshttps://api.sprig.com/... - Check the status code of the request. If it’s 200 or 304, your install is working correctly and you can move on.
Identify Users
Each time a user is tracked by Sprig on a webpage with the SDK installed, they are assigned a unique visitor ID in Sprig that allows users to be targeted with studies when they perform specified behaviors. While this is a requirement for targeting users with Sprig studies, these are still considered unauthenticated users until their Sprig visitor IDs are coupled with the unique USER_IDs assigned to users within your platform’s internal authentication framework. We recommend that you follow this best practice when installing Sprig:- This ensures consistency between the visitor IDs generated by Sprig and the ones in your internal database, product analytics/CDP, or data warehouse, allowing more effective targeting of studies.
- Your users have a consistent experience across platforms, and do not see the same study multiple times.
- It also optimizes the number of Monthly Unique Users (MUUs) sent to Sprig, which impacts your billing.
- Unique: Two users should not share the same User ID.
- Mappable: User IDs sent to Sprig should map back to your internal User IDs, either directly or anonymously.
- Static: Once assigned, a User ID should not change.
Set User ID
You can usesetUserId to identify a user with any string less than 256 characters. This function can be called multiple times safely, and stores the identifier via local storage. We recommend you set the User ID whenever the user logs in to your website, as well as after the installation snippet (if the user is already logged in).
HTML script tag
npm
Logout
When a user logs out of your webpage, make sure to log out of Sprig. This will prevent new activity from being associated with an incorrect user. Note that if you calllogoutUser() on an unauthenticated user, Sprig will assign them a new profile and count this new user separately toward your MTU limit.
HTML script tag
npm
Track Events
Sprig uses events to trigger (display) studies after the user performs a specific action. They can also be used as a filter to target users who have previously performed an action. Once you’ve installed the Sprig SDK, the next step is to configure the tracking of events that you would like to use to trigger a study. Sprig provides two types of Events for triggering and filtering your studies, Code and No-Code events.No-Code Events
No-Code events let teammates without access to the codebase create events in Sprig based on the page’s URL, HTML elements, or CSS, which can then be used to trigger or filter Web studies. No-code events tend to be used to define more straightforward user actions, like viewing a page or clicking a button. For more information, see No-Code events.Code Events
Sometimes No-Code events may not provide visibility into a particular event that you would like to track. For example, you may want to study users who, in the previous month, have downgraded their account status from premium to standard. It may be preferable to generate the event directly from the webpage. To track a Code event, you will need the following snippet. You can also optionally attach properties to your event.HTML script tag
npm
Track Attributes
Sprig allows you to track attributes, which can provide more context about the user to help you better understand their feedback. You can also use these attributes to filter your audience and target specific kinds of users. Some example attributes that can be tracked are:- Plan type
- Super users / power users
- Company
ATTRIBUTE_NAMEmust be a string less than 256 characters, and cannot start with an!(these names are reserved for use by Sprig)ATTRIBUTE_VALUEmust be a number, boolean, or string less than 256 characters
HTML script tag
npm
Set Email Address
Setting the user’s email address is optional. Setting emails is not required for web or mobile studies, but can be used to target users or create a Group of users based on their email. Check your organization’s guidelines around personally-identifiable information before sending email addresses to Sprig.HTML script tag
npm
Test & Deploy
To confirm everything is working as expected with survey, you can create a survey and manually trigger delivery from the Developer Console.- You’ll first need to create a Study and set the delivery method to Web. If you’re testing in the Development environment, you’ll need to create the Study in Development.
- In the Sprig app, go to Settings > Configure and select Allow Manual Study Display (on by default for the Development environment)
- Open the developer console and run
Sprig('displaySurvey', SURVEY_ID);. The SURVEY_ID of a study can be found at the end of its URL (https://app.sprig.com/surveys/SURVEY_ID). - If the Sprig snippet is already installed on that page, your browser will display the study.
- If the questions are not rendering correctly or responses aren’t uploaded, check your browser console for any errors. You may have to work with your engineering and security teams to update your installation or CSP settings to resolve the errors.
Advanced Customization
Customize Appearance
You can set a hard limit on the height of your study with themaxHeight parameter, which sets the maxHeight property of the iframe.
For custom installations, if Sprig is installed within an iframe that initially has 0 width, by default, studies will render with desktop styling and a width of 360px. In these cases, to make use of mobile styling and full-width studies on mobile web, you can provide your window dimensions when Sprig is initialized, and when the window is resized, with the setWindowDimensions function.
Example of configuring maxHeight and using setWindowDimensions:
HTML script tag
npm
Sandbox implementation
A common use case from our customers is to place the UserLeapKit in a sandbox iframe that’s hosted by a hosting frame with an initial size of 0. The sandboxed frame will observe thesurvey.height events and the survey.closed events to manage the size and appearance of the hosting frame.
See a gist of the implementation
Inject CSS to your studies
For more fine-tuned control of how your study looks, Sprig supports injecting CSS into the survey. Sprig creates a<style/> tag in the <head/> of the iframe and sets the CSS string as the text content.
HTML script tag
npm
| Element | CSS Selector |
|---|---|
| Container | .ul-card__container |
| Main question title | .ul-question |
| Question subtitle | .ul-caption |
| Progress bar | .ul-progress-bar-container |
Study Event Lifecycle Notifications
Sprig exposes updates throughout the study lifecycle. Here is a sample code block for listening to SDK events in real time:HTML script tag
npm
Sprig.UPDATES if using the JS snippet, and SprigEvent if using the NPM package:
For the event when a question is answered, it will return the value the user submitted. See below for each question type and its possible value. There are mainly two types of value, the user can either submit an answer or skip it. Please be aware of all possible outcome of survey responses.
| Question Type | Input | Value(s) |
|---|---|---|
| Text/URL | Clicked | value: undefined |
| Text/URL | Skipped | value: {skipped: true} |
| Consent/Legal Form | Submitted | value: {submitted: boolean, name?: string} |
| Consent/Legal Form | Skipped | value: null |
| Rating Scale | Submitted | value: number |
| Rating Scale | Skipped | value: null |
| Open Text | Submitted | value: string |
| Open Text | Skipped | value: '' |
| Multiple-Choice Single Choice | Submitted | value: { [optionId]: string } |
| Multiple-Choice Single Choice | Skipped | value: {} |
| Multiple-Choice Multiple Choice | Submitted | value: { [optionId1]: boolean, [optionId2]: boolean, ... } |
| Multiple-Choice Multiple Choice | Skipped | value: { [optionId1]: boolean, [optionId2]: boolean, ... } (same as submitted but all false value) |
| NPS | Submitted | value: number |
| NPS | Skipped | value: null |
| Voice and Video | Submitted | value: { mediaRecordingUid: string } |
| Voice and Video | Skipped | value: null |
| Recorded Task | Submitted | value: {taskStatus: “completed”} |
| Recorded Task | Given up | value: {taskStatus: “given.up”} |
| Recorded Task | Skipped | value: {taskStatus: “abandoned”} |
Installing without Session Replay Code
For installations and use cases where you do not want session replay code bundled, you can do this only via npm by installing@sprig-technologies/sprig-browser and changing the import as shown below
Web Replays: Pause and Resume Recording
Overview
Use these functions to pause and resume the capture of recordings within web Replays. This granular control allows for additional privacy protection while maintaining session continuity for those viewing Replays. Requires: v2.34.0 of the web SDK or higher.Pause Recording
pauseReplayRecording()
Temporarily pauses all replay recording activity without ending the session. This function stops the recording of DOM events, user interactions (clicks, scrolls, keystrokes), and any other Replay data until recording is resumed.
How to useSprig.pauseReplayRecording();
When to use
- When users are entering sensitive information (passwords, credit card numbers, personal data)
- During privacy-sensitive workflows or screens
- When temporarily switching to content that shouldn’t be recorded
- To comply with privacy regulations during specific user flows
- Records a “pause” event marker before stopping recording
- Maintains the existing replay session (doesn’t create a new session when resumed)
- All subsequent user activity is ignored until resumeReplayRecording() is called
- Safe to call multiple times (subsequent calls are ignored if already paused)
- Pause state persists across page refreshes within the same session
void
Resume Recording
resumeReplayRecording()
Resumes Replay recording after it was paused with pauseReplayRecording(). This function re-enables the capture of user interactions.
How to useSprig.resumeReplayRecording(); When to use
- After users complete entering sensitive information
- When exiting privacy-sensitive workflows or screens
- To resume normal replay recording after a temporary pause
- Resumes capture of all user interactions and DOM changes
- Safe to call multiple times (subsequent calls are ignored if not currently paused)
void
Example Usage
// Pause recording before sensitive inputSprig.pauseReplayRecording();
// User enters password or sensitive data// ... user activity not recorded ...
// Resume recording after sensitive input is completeSprig.resumeReplayRecording();