---
title: "JavaScript SDK: Surveys"
description: "Display surveys and collect customer responses with the Gleap JavaScript SDK. Follow the integration code examples."
url: https://docs.gleap.ai/en/articles/429-javascript-sdk-surveys
collection: "Widget apps"
updated: 2026-11-01
language: en
---

# JavaScript SDK: Surveys

Display surveys and collect customer responses with the Gleap JavaScript SDK. Follow the integration code examples.

Gleap allows you to create micro surveys to be run directly in your Gleap widget. We offer templates for some of the most common survey types, such as NPS scores, product market fit or product satisfaction.

## Sending surveys with triggers

Usually customers use triggers to send surveys. Example use cases for that include:

-   Sending surveys after a certain amount of time
    
-   Sending a survey on a certain page
    
-   Sending a survey after a specific event happened
    
-   ...
    

After your app has tracked an event, open Outreach → Surveys, select the survey, then Share → In the app and configure its audience and trigger. Use the SDK’s event method to provide the event your trigger matches.

![Current survey delivery and trigger setup under Share → In the app in the Pied Piper demo project.](https://staticfiles.gleap.io/p613b5dd730aed737108f87ab/Gm35M6gNjgaQiP0Tb3x2O9d8Pwb6EYzm9xJrhwTLJPaaatKZPgH6aY352yPZvTQvH27DYrHnFoW.png)

## Manually sending surveys

Show a survey from code with its survey id (**Share → In the app** in the survey editor shows it):

```javascript
Gleap.showSurvey("survey-id");
```

### Options

Pass an options object as the second parameter:

```javascript
Gleap.showSurvey("survey-id", {
  format: "full",
  fields: { plan: "pro", source: "upgrade-flow" },
});
```

`format` _'card' | 'full' | 'page'_

`card` (default): compact card in the corner, bottom sheet on phones. `full`: Typeform-style full screen. `page`: the survey fills `container` (inline embed).

`fields` _Record<string, string>_

Values for the survey's [hidden fields](https://gleap-developer-docs.gleap.help/en/articles/699-surveys#hidden-fields), stored with the response and usable in logic and question text.

`container` _HTMLElement_

With `format: "page"`: the element the survey renders into. Defaults to `document.body`.

`personalToken` _string_

A [personal link](https://gleap-developer-docs.gleap.help/en/articles/699-surveys#personal-links) token that attaches the response to a known contact.

`resume` _boolean_

Continue an unfinished response of this survey on this device where the person left off.

Embed a survey inline in your page:

```javascript
Gleap.showSurvey("survey-id", {
  format: "page",
  container: document.getElementById("feedback"),
});
```

### Survey events

Listen to `survey-shown`, `survey-step-viewed`, `survey-answered`, `survey-completed` and `survey-closed` with `Gleap.on`. A completed survey also fires `feedback-sent` (the answers by question key) and `outbound-sent` (`{ outboundId, outbound, formData, surveyId, responseId, endingId, status: "completed" }`) once, as a sent survey always did, and the SDK tracks `outbound-<surveyId>-submitted`. To push survey events into Google Analytics 4, Google Tag Manager or Meta Pixel, see [Send survey events to your analytics](https://gleap-developer-docs.gleap.help/en/articles/701-survey-analytics#send-survey-events-to-your-analytics).

### Legacy format string

The previous signature keeps working:

```javascript
Gleap.showSurvey("survey-id", "survey");      // same as { format: "card" }
Gleap.showSurvey("survey-id", "survey_full"); // same as { format: "full" }
```

> **Note:** `survey` and `survey_full` are deprecated aliases of `card` and `full`. The native SDKs (iOS, Android, React Native, Flutter, Capacitor, Cordova) keep `showSurvey(id, format)` with their format constants.

> **Info:** Please note that the Gleap SDK needs to be fully initialized to be able to show a survey. The options object needs JavaScript SDK 19.2.0 or later; older versions only accept the format string.

## Send surveys with URL parameters

You can also open surveys with URL parameters. This is useful if you want to send surveys to specific users. For example, you can send a survey to a specific user by sending them a link like this:

```javascript
https://yourapp.com/?gleap_survey=\{your-survey-id\}&gleap_survey_format=\{survey\}
```

Please replace {your-survey-id} with your survey id and {survey} with the survey format: `survey` (card, default) or `survey_full` (full screen).

> **Info:** The application that you use for sending surveys with URL parameters needs to have the Gleap SDK installed. To share a survey with people who don't use your app, use the [survey page](https://gleap-developer-docs.gleap.help/en/articles/699-surveys#survey-page) instead.

## Related

- [JavaScript SDK: Conversations](https://docs.gleap.ai/en/articles/425-javascript-sdk-conversations.md)
- [JavaScript SDK: Feature requests](https://docs.gleap.ai/en/articles/426-javascript-sdk-feature-requests.md)
- [JavaScript SDK: Help center](https://docs.gleap.ai/en/articles/427-javascript-sdk-help-center.md)
- [JavaScript SDK: Release notes & news](https://docs.gleap.ai/en/articles/428-javascript-sdk-release-notes-and-news.md)
- [JavaScript SDK: Checklists](https://docs.gleap.ai/en/articles/430-javascript-sdk-checklists.md)
