Event Types
The SDK emits three event types:popup_shown- Fired when a popup is displayed to the userpopup_clicked- Fired when the user interacts with popup elementssurvey_completed- Fired when the user completes a survey
Event Structure
All events follow the same payload structure:Event Fields
| Field | Type | Description |
|---|---|---|
type | DeepdotsEventType | The type of event that occurred |
surveyId | string | The survey ID associated with the popup |
timestamp | number | Unix timestamp (milliseconds) when the event occurred |
data | Record<string, unknown> | Optional additional data about the event |
Listening to Events
Subscribe to events using theon() method:
Unsubscribing from Events
Remove event listeners using theoff() method:
You must pass the exact same function reference to
off() that you passed to on(). Anonymous functions cannot be unsubscribed.Event Details
popup_shown
Fired when a popup is displayed to the user.data fields:
popupId: The ID of the popup definitionuserId: The user ID if provided ininit()
- Analytics tracking
- Impression counting
- A/B test bucketing
- User behavior analysis
popup_clicked
Fired when the user interacts with any popup element (buttons, close icon, etc.).data.action values:
loaded- Popup iframe loaded successfullystart_survey- User clicked the start buttonmanual_send- User manually submitted the surveyback- User clicked the back buttoncomplete- User clicked the complete buttonclose_icon- User clicked the X close icon
popup_clicked is a general interaction event. The specific action is determined by the data.action field.- Engagement tracking
- Funnel analysis
- Understanding drop-off points
- User interaction patterns
survey_completed
Fired when the user completes a survey.- When
survey_completedis emitted, the SDK automatically marks the survey as answered - This affects future trigger conditions with
answered: false - You can manually mark surveys as answered using
markSurveyAnswered(surveyId)
- Conversion tracking
- Thank you messages
- Follow-up actions (email notifications, CRM updates)
- Reward distribution
- Preventing survey fatigue
Marking Surveys as Answered Manually
Marking Surveys as Answered Manually
If you need to manually mark a survey as answered (for example, if the user completes it outside the popup flow):This will prevent the survey from being shown again if the popup definition has a condition like:
Event Data Examples
Here are real-world examples of event payloads:Error Handling
Event listeners should handle errors gracefully. The SDK catches and logs errors in event listeners to prevent one failing listener from affecting others:If an error occurs in an event listener, the SDK logs it to the console but continues processing other listeners and SDK operations normally.
Best Practices
Keep Listeners Lightweight
Keep Listeners Lightweight
Event listeners should execute quickly to avoid blocking the UI. If you need to perform expensive operations (API calls, complex calculations), do them asynchronously:
Clean Up in SPAs
Clean Up in SPAs
In single-page applications, always unsubscribe from events when components unmount:
Use Type Safety
Use Type Safety
The SDK exports TypeScript types for events:
Server-Side Event Reporting
Inserver mode, the SDK automatically reports popup_shown and survey_completed events to the Deepdots API for analytics and tracking:
Server-side event reporting only happens in
server mode and requires a valid apiKey. Events are still emitted locally via on() regardless of mode.