Amplitude's Guides and Surveys SDK enables you to deploy Guides and Surveys on your website or application.
Guides and Surveys supports different installation options to work best with your existing Amplitude implementation, if you have one.
Install the Guides and Surveys SDK with a script, or as a package with npm or Yarn.
1<script src="https://cdn.amplitude.com/script/API_KEY.engagement.js"></script>2<script>amplitude.add(window.engagement.plugin())</script>
1npm install @amplitude/engagement-browser
Import Guides and Surveys into your project:
1import { plugin as engagementPlugin } from '@amplitude/engagement-browser';2amplitude.add(engagementPlugin());
1yarn add @amplitude/engagement-browser
Import Guides and Surveys into your project:
1import { plugin as engagementPlugin } from '@amplitude/engagement-browser';2amplitude.add(engagementPlugin());
Using the Guides and Surveys standalone SDK with another analytics provider requires extra configuration to help map properties to Amplitude. This initialization code accepts parameters that define the user and any integrations.
1engagement.boot(options: BootOptions): Promise<void>
Parameter | Type | Description |
---|---|---|
options.user |
EndUser or (() => EndUser) |
Required. User information or a function that returns user information. |
options.integrations |
Array<Integration> |
Optional. An array of integrations for tracking events. |
1await window.engagement.boot({ 2 user: { 3 // Guides and Surveys requires either user_id or device_id for user identification 4 user_id: 'USER_ID', 5 device_id: 'DEVICE_ID', 6 user_properties: {}, 7 }, 8 integrations: [ 9 {10 track: (event) => {11 analytics.track(event.event_type, event.event_properties)12 }13 },14 ],15});
First, the initialization code requires you to map the
Initialize with Segment analytics
user_id
and device_id
fields, and optionally configure event forwarding to enable event-based triggers.
To verify that the Guides and Surveys SDK is running on your site or dev environment, open your browser's Developer Tools, and enter the following in the console:
1window.engagement
If the response is undefined
, Guides and Surveys isn't installed properly.
If your organization has a strict Content Security Policy (CSP), Guides and Surveys requires some additions to ensure smooth operation.
When you use the Amplitude Browser SDK 2 for analytics, add the following items to your CSP:
1script-src: https://*.amplitude.com;2connect-src: https://*.amplitude.com;
Regardless of the analytics provider you use, Guides and Surveys requires the following additions:
1img-src: https://*.amplitude.com;2media-src: https://*.amplitude.com;3style-src: https://*.amplitude.com;
Configure the visual theme that displays to the user.
1engagement.setThemeMode(mode: ThemeMode): void
Parameter | Type | Description |
---|---|---|
mode |
light_mode , dark_mode , auto |
Required. Select the theme to apply. |
1// Automatically detect user's system preferences2window.engagement.setThemeMode("auto");3 4// Set dark mode explicitly5window.engagement.setThemeMode("dark_mode");6 7// Set light mode explicitly8window.engagement.setThemeMode("light_mode");
Configure how Guides and Surveys handles URLs in a single page application (SPA).
1engagement.setRouter(routerFn: (url: string) => void): void
Parameter | Type | Description |
---|---|---|
routerRn |
(url: string) => void |
Required. A function that handles changes to the URL. |
1// React Router v6 implementation 2import { useNavigate } from "react-router-dom"; 3 4const MyComponent = () => { 5 const navigate = useNavigate(); 6 7 React.useEffect(() => { 8 window.engagement.setRouter((newUrl) => navigate(newUrl)); 9 }, []);10};
Reset a guide or survey to a specific step.
1engagement.gs.reset(key: string, stepIndex?: number)
Parameter | Type | Description |
---|---|---|
key |
string |
Required. The guide or survey's key. |
stepIndex |
number |
Required. The zero-based index of the step to reset to. Defaults to the initial step. |
Retrieve a list of visible guides or surveys
1engagement.gs.list(): Array<GuideOrSurvey>
1interface GuideOrSuvey {2 id: number;3 status: "visible" | "active";4 step: number;5 title: string6}
Display a specific guide or survey.
1engagement.gs.show(key: string, stepIndex?: number): void
Parameter | Type | Description |
---|---|---|
key |
string |
Required. The guide or survey's key. |
stepIndex |
number |
Required. The zero-based index of the step to show. Defaults to the initial step. |
Trigger Guides and Surveys programmatically.
1engagement.forwardEvent(event: Event): void
Parameter | Type | Description |
---|---|---|
event |
Event | Required. An event object that launches a guide or survey. |
Close all active guides and surveys.
1engagement.gs.closeAll(): void
Thanks for your feedback!
February 7th, 2025
Need help? Contact Support
Visit Amplitude.com
Have a look at the Amplitude Blog
Learn more at Amplitude Academy
© 2025 Amplitude, Inc. All rights reserved. Amplitude is a registered trademark of Amplitude, Inc.