How Exit Triggers Work
Unlike traditional exit-intent popups that try to catch the user before they leave, the MagicFeedback SDK’s exit triggers are designed for a better user experience:- User visits a matching route (e.g.,
/pricing) - User navigates away to a different route
- Exit trigger is queued in sessionStorage
- After a configurable delay on the destination route, the popup appears
Exit popups appear after navigation, not before. This avoids interrupting the user’s intent to navigate while still capturing valuable feedback.
Defining Exit Triggers
Configuration Options
Delay Value
Thevalue field specifies how many seconds to wait after navigation before showing the popup:
- Short delay (1-3s): Good for high-intent pages where users are actively browsing
- Medium delay (5-10s): Balanced approach for general exit feedback
- Long delay (15-30s): For detailed feedback after users have settled on the new page
Route Targeting
Usesegments.path to specify which routes should trigger the exit popup when users navigate away:
The Exit Popup Queue
How the Queue Works
The SDK uses sessionStorage to persist exit popups across navigation:- When a user leaves a matching route, the popup is queued
- The queue stores: popup ID, survey ID, source URL, and due time
- After the delay expires, the SDK shows the popup
- Shown popups are removed from the queue
Queue Persistence
Exit popups survive page reloads and navigation:Navigation Detection
Exit triggers work with all navigation methods:Anchor tag navigation
Anchor tag navigation
Hash navigation
Hash navigation
History API
History API
Framework routing
Framework routing
Works with modern frameworks:
Complete Example
Here’s a real-world example with multiple exit triggers:Exit Popup Behavior
When Popups Are Shown
An exit popup will show when:- ✅ User was on a matching route (defined in
segments.path) - ✅ User navigated to a different route
- ✅ The configured delay has elapsed
- ✅ Conditions are met (
answered,cooldownDays) - ✅ No other popup is currently showing
When Popups Are Skipped
An exit popup will not show when:- ❌ User is still on the same route
- ❌ Conditions block it (
answered: falseand survey was completed) - ❌ Cooldown period hasn’t elapsed
- ❌ Route doesn’t match
segments.path - ❌ User closed the tab before delay elapsed
The SDK checks conditions at render time (after the delay), not when the exit is queued. This ensures popups respect real-time user state.
Source Code Reference
The exit popup implementation is insrc/core/deepdots-popups.ts:
- Queue storage: Lines 307-444 handle sessionStorage persistence
- Navigation detection: Triggers module detects route changes
- Path matching: Lines 247-283 evaluate
segments.path - Deferred rendering: Lines 362-392 manage timers and display logic
API Reference
queueExitPopup(surveyId, delaySeconds, sourceUrl?, popupId?)
Manually queue an exit popup (typically called by trigger handlers):
Best Practices
Choose appropriate delays
Choose appropriate delays
Match your delay to the user’s context:
Use meaningful cooldowns
Use meaningful cooldowns
Prevent survey fatigue with cooldown periods:
Target specific routes
Target specific routes
Focus on pages where exit feedback is most valuable:
Test navigation flows
Test navigation flows
Debugging Exit Popups
Enable debug mode to see exit popup logs:- When exits are queued
- Queue contents in sessionStorage
- When delays expire
- Why popups are skipped
- When popups are shown
Next Steps
Route Targeting
Learn path matching rules for exit triggers
Event Triggers
Trigger popups from business events
Server Mode
Manage exit popups remotely
Client Mode
Define exit triggers inline