export function browseAbandonmentSurvey(form: FormTs) {
// Browse Exit Survey - Exit Intent Feedback for E-commerce
// Demonstrates: EmojiRating, SuggestionChips, Slider, RadioButton, ThumbRating, Conditional Visibility
// ============================================
// HEADER
// ============================================
form.addRow(row => {
row.addTextPanel('header', {
label: 'Before You Go...',
computedValue: () => 'We noticed you\'re leaving. Help us improve your experience with a quick 30-second survey.',
customStyles: {
backgroundColor: '#ec4899',
color: 'white',
padding: '20px',
borderRadius: '12px',
textAlign: 'center'
}
});
});
// ============================================
// SECTION 1: Interest Level
// ============================================
const interestSection = form.addSubform('interest', {
title: 'Your Interest'
});
interestSection.addRow(row => {
row.addEmojiRating('interestLevel', {
label: 'How interested were you in what you saw today?',
preset: 'satisfaction',
size: 'lg',
alignment: 'center'
});
});
// ============================================
// SECTION 2: Visit Purpose
// ============================================
const purposeSection = form.addSubform('purpose', {
title: 'Your Visit Today',
isVisible: () => interestSection.emojiRating('interestLevel')?.value() !== null
});
purposeSection.addRow(row => {
row.addRadioButton('visitPurpose', {
label: 'What brought you here today?',
options: [
{ id: 'browse', name: 'Just browsing / window shopping' },
{ id: 'research', name: 'Researching before buying' },
{ id: 'compare', name: 'Comparing with other sites' },
{ id: 'specific', name: 'Looking for something specific' },
{ id: 'return', name: 'Returning to finish a purchase' },
{ id: 'other', name: 'Other reason' }
],
orientation: 'vertical'
});
});
// Show product interest for specific shoppers
const productInterestSection = form.addSubform('productInterest', {
title: 'What Were You Looking For?',
isVisible: () => {
const purpose = purposeSection.radioButton('visitPurpose')?.value();
return purpose === 'specific' || purpose === 'research' || purpose === 'compare';
},
customStyles: { backgroundColor: '#fdf4ff', padding: '16px', borderRadius: '8px' }
});
productInterestSection.addRow(row => {
row.addSuggestionChips('categories', {
label: 'Which categories were you interested in?',
suggestions: [
{ id: 'electronics', name: 'Electronics' },
{ id: 'clothing', name: 'Clothing & Fashion' },
{ id: 'home', name: 'Home & Garden' },
{ id: 'beauty', name: 'Beauty & Personal Care' },
{ id: 'sports', name: 'Sports & Outdoors' },
{ id: 'toys', name: 'Toys & Games' },
{ id: 'books', name: 'Books & Media' },
{ id: 'food', name: 'Food & Groceries' }
],
alignment: 'center'
});
});
productInterestSection.addRow(row => {
row.addTextbox('specificProduct', {
label: 'Were you looking for a specific product?',
placeholder: 'e.g., "wireless headphones", "summer dress", "garden tools"'
});
});
// ============================================
// SECTION 3: Barriers
// ============================================
const barriersSection = form.addSubform('barriers', {
title: 'What Stopped You?',
isVisible: () => {
const interest = interestSection.emojiRating('interestLevel')?.value();
return interest !== null && interest !== 'very-bad';
}
});
barriersSection.addRow(row => {
row.addSuggestionChips('mainBarriers', {
label: 'Select what prevented you from buying today:',
suggestions: [
{ id: 'not-ready', name: 'Not ready to buy yet' },
{ id: 'price', name: 'Prices too high' },
{ id: 'shipping', name: 'Shipping costs' },
{ id: 'not-found', name: 'Couldn\'t find what I wanted' },
{ id: 'trust', name: 'Trust/security concerns' },
{ id: 'compare', name: 'Need to compare options' },
{ id: 'reviews', name: 'Not enough reviews' },
{ id: 'info', name: 'Missing product info' }
],
alignment: 'center',
max: 3
});
});
// ============================================
// SECTION 4: Price Sensitivity (if price was a barrier)
// ============================================
const priceSection = form.addSubform('priceDetails', {
title: 'About Pricing',
isVisible: () => {
const barriers = barriersSection.suggestionChips('mainBarriers')?.value() || [];
return barriers.includes('price') || barriers.includes('shipping');
},
customStyles: { backgroundColor: '#fef3c7', padding: '16px', borderRadius: '8px' }
});
priceSection.addRow(row => {
row.addSlider('priceReduction', {
label: 'What discount would make you consider buying?',
min: 5,
max: 50,
step: 5,
unit: '% off',
showValue: true,
defaultValue: 15
}, '1fr');
row.addRadioButton('shippingPreference', {
label: 'What shipping option would you prefer?',
options: [
{ id: 'free-slow', name: 'Free shipping (slower)' },
{ id: 'cheap-fast', name: 'Low cost, fast delivery' },
{ id: 'threshold', name: 'Free shipping over $X' }
],
orientation: 'vertical',
isVisible: () => {
const barriers = barriersSection.suggestionChips('mainBarriers')?.value() || [];
return barriers.includes('shipping');
}
}, '1fr');
});
// ============================================
// SECTION 5: Trust Issues (if trust was a barrier)
// ============================================
const trustSection = form.addSubform('trustDetails', {
title: 'Trust & Security Concerns',
isVisible: () => {
const barriers = barriersSection.suggestionChips('mainBarriers')?.value() || [];
return barriers.includes('trust');
},
customStyles: { backgroundColor: '#fee2e2', padding: '16px', borderRadius: '8px' }
});
trustSection.addRow(row => {
row.addCheckboxList('trustConcerns', {
label: 'What would make you feel more confident?',
options: [
{ id: 'reviews', name: 'More customer reviews' },
{ id: 'badges', name: 'Security badges/certificates' },
{ id: 'returns', name: 'Clear return policy' },
{ id: 'payment', name: 'More payment options' },
{ id: 'contact', name: 'Easy-to-find contact info' },
{ id: 'social', name: 'Social proof/testimonials' }
],
orientation: 'vertical'
});
});
// ============================================
// SECTION 6: Future Intent
// ============================================
const futureSection = form.addSubform('future', {
title: 'Will You Return?',
isVisible: () => interestSection.emojiRating('interestLevel')?.value() !== null
});
futureSection.addRow(row => {
row.addThumbRating('returnIntent', {
label: 'Do you plan to come back and shop with us?',
size: 'lg',
showLabels: true,
upLabel: 'Yes, I\'ll be back',
downLabel: 'Probably not',
alignment: 'center'
});
});
futureSection.addRow(row => {
row.addRatingScale('purchaseTimeline', {
label: 'When are you likely to make a purchase?',
preset: 'custom',
min: 1,
max: 5,
lowLabel: 'Today',
highLabel: 'Not sure / months',
alignment: 'center',
isVisible: () => futureSection.thumbRating('returnIntent')?.value() === 'up'
});
});
// ============================================
// SECTION 7: Capture Email for Incentive
// ============================================
const emailSection = form.addSubform('emailCapture', {
title: 'Want a Special Offer?',
isVisible: () => {
const interest = interestSection.emojiRating('interestLevel')?.value();
const returnIntent = futureSection.thumbRating('returnIntent')?.value();
return (interest === 'good' || interest === 'excellent') || returnIntent === 'up';
},
customStyles: { backgroundColor: '#ecfdf5', padding: '16px', borderRadius: '8px' }
});
emailSection.addRow(row => {
row.addTextPanel('offerText', {
computedValue: () => {
const discount = priceSection.slider('priceReduction')?.value() ?? 10;
return `Get ${Math.min(discount, 15)}% off your first purchase! Enter your email below.`;
},
customStyles: {
textAlign: 'center',
fontWeight: 'bold',
color: '#059669',
marginBottom: '12px'
}
});
});
emailSection.addRow(row => {
row.addEmail('email', {
label: 'Your email address',
placeholder: 'you@example.com'
}, '1fr');
row.addCheckbox('marketingConsent', {
label: 'Send me deals and new arrivals (you can unsubscribe anytime)'
}, '1fr');
});
// ============================================
// SECTION 8: Additional Feedback
// ============================================
const feedbackSection = form.addSubform('additionalFeedback', {
title: 'Anything Else?',
isVisible: () => interestSection.emojiRating('interestLevel')?.value() !== null
});
feedbackSection.addSpacer({ height: '8px' });
feedbackSection.addRow(row => {
row.addTextarea('additionalComments', {
label: 'Is there anything else you\'d like us to know?',
placeholder: 'What would make your shopping experience better?',
rows: 3
});
});
// ============================================
// SECTION 9: Summary
// ============================================
const summarySection = form.addSubform('summary', {
title: 'Your Feedback Summary',
isVisible: () => interestSection.emojiRating('interestLevel')?.value() !== null
});
summarySection.addRow(row => {
row.addTextPanel('summaryContent', {
computedValue: () => {
const interest = interestSection.emojiRating('interestLevel')?.value();
const purpose = purposeSection.radioButton('visitPurpose')?.value();
const barriers = barriersSection.suggestionChips('mainBarriers')?.value() || [];
const returnIntent = futureSection.thumbRating('returnIntent')?.value();
const email = emailSection.email('email')?.value();
const interestLabels: Record<string, string> = {
'very-bad': 'Not interested',
'bad': 'Slightly interested',
'neutral': 'Somewhat interested',
'good': 'Very interested',
'excellent': 'Extremely interested'
};
const purposeLabels: Record<string, string> = {
'browse': 'Just browsing',
'research': 'Researching products',
'compare': 'Comparing options',
'specific': 'Looking for something specific',
'return': 'Returning to finish purchase',
'other': 'Other'
};
let summary = `Exit Survey Summary\n`;
summary += `${''.repeat(22)}\n\n`;
if (interest) {
summary += ` Interest: ${interestLabels[interest] || interest}\n`;
}
if (purpose) {
summary += ` Purpose: ${purposeLabels[purpose] || purpose}\n`;
}
if (barriers.length > 0) {
summary += `\n Barriers: ${barriers.length} factors identified\n`;
}
if (returnIntent) {
summary += `\n Return Intent: ${returnIntent === 'up' ? ' Will return' : ' Unlikely to return'}\n`;
}
if (email) {
summary += `\n Email captured for follow-up\n`;
}
return summary;
},
customStyles: () => {
const interest = interestSection.emojiRating('interestLevel')?.value();
const returnIntent = futureSection.thumbRating('returnIntent')?.value();
const baseStyles = {
padding: '16px',
borderRadius: '8px',
whiteSpace: 'pre-wrap',
fontFamily: 'monospace',
fontSize: '14px'
};
if (interest === 'excellent' || interest === 'good' || returnIntent === 'up') {
return { ...baseStyles, backgroundColor: '#d1fae5', borderLeft: '4px solid #10b981' };
}
if (interest === 'neutral') {
return { ...baseStyles, backgroundColor: '#fef3c7', borderLeft: '4px solid #f59e0b' };
}
return { ...baseStyles, backgroundColor: '#fee2e2', borderLeft: '4px solid #ef4444' };
}
});
});
// ============================================
// FORM CONFIGURATION
// ============================================
form.configureSubmitButton({
label: () => {
const email = emailSection.email('email')?.value();
if (email) return 'Submit & Get My Discount';
return 'Submit Feedback';
}
});
form.configureCompletionScreen({
type: 'text',
title: 'Thanks for your feedback!',
message: 'Your input helps us create a better shopping experience. If you shared your email, check your inbox for a special discount code!'
});
}