export function cartAbandonment(form: FormTs) {
// Cart Abandonment Survey - E-commerce exit intent feedback
// Demonstrates: RadioButton, Dropdown, conditional sections, dynamic visibility, recovery options
// ============================================
// HEADER
// ============================================
form.addRow(row => {
row.addTextPanel('header', {
label: 'Before You Go...',
computedValue: () => 'Help us understand how we can serve you better',
customStyles: {
backgroundColor: '#f97316',
color: 'white',
padding: '24px',
borderRadius: '12px',
textAlign: 'center'
}
});
});
// ============================================
// SECTION 1: Primary Reason
// ============================================
const primarySection = form.addSubform('primarySection', {
title: 'What stopped you from completing your purchase?',
customStyles: { backgroundColor: '#fff7ed', padding: '16px', borderRadius: '8px' }
});
primarySection.addRow(row => {
row.addRadioButton('primaryReason', {
label: 'Select the main reason',
options: [
{ id: 'price_too_high', name: 'Price was too high' },
{ id: 'shipping_cost', name: 'Shipping costs were unexpected' },
{ id: 'just_browsing', name: 'Just browsing / not ready to buy' },
{ id: 'comparing', name: 'Comparing prices elsewhere' },
{ id: 'checkout_issues', name: 'Checkout was too complicated' },
{ id: 'payment_issues', name: 'Payment method not available' },
{ id: 'trust_concerns', name: 'Security/trust concerns' },
{ id: 'found_elsewhere', name: 'Found it cheaper elsewhere' },
{ id: 'delivery_time', name: 'Delivery time too long' },
{ id: 'other', name: 'Other reason' }
],
orientation: 'vertical',
isRequired: true
});
});
// ============================================
// SECTION 2: Price Concerns (Conditional)
// ============================================
const priceSection = form.addSubform('priceSection', {
title: 'Tell Us About Pricing',
isVisible: () => {
const reason = primarySection.radioButton('primaryReason')?.value();
return reason === 'price_too_high' || reason === 'comparing' || reason === 'found_elsewhere';
},
customStyles: { padding: '16px', borderRadius: '8px', backgroundColor: '#fef3c7', borderLeft: '4px solid #f59e0b' }
});
priceSection.addRow(row => {
row.addRadioButton('priceExpectation', {
label: 'How much were you expecting to pay?',
options: [
{ id: 'much_less', name: 'Much less (30%+ cheaper)' },
{ id: 'bit_less', name: 'A bit less (10-30% cheaper)' },
{ id: 'slightly_less', name: 'Slightly less (under 10%)' },
{ id: 'same', name: 'About the same price' }
],
orientation: 'vertical'
});
});
priceSection.addRow(row => {
row.addSlider('acceptablePrice', {
label: 'What discount would make you complete the purchase?',
min: 5,
max: 50,
step: 5,
showValue: true,
unit: '% off',
defaultValue: 15
});
});
priceSection.addRow(row => {
row.addThumbRating('wouldBuyWithDiscount', {
label: 'Would a discount code convince you to buy today?',
showLabels: true,
upLabel: 'Yes, probably',
downLabel: 'No, not right now',
alignment: 'left'
});
});
// ============================================
// SECTION 3: Shipping Concerns (Conditional)
// ============================================
const shippingSection = form.addSubform('shippingSection', {
title: 'Shipping Feedback',
isVisible: () => {
const reason = primarySection.radioButton('primaryReason')?.value();
return reason === 'shipping_cost' || reason === 'delivery_time';
},
customStyles: { padding: '16px', borderRadius: '8px', backgroundColor: '#dbeafe', borderLeft: '4px solid #3b82f6' }
});
shippingSection.addRow(row => {
row.addRadioButton('shippingConcern', {
label: 'What\'s your main shipping concern?',
options: [
{ id: 'cost_unexpected', name: 'Shipping cost was higher than expected' },
{ id: 'free_shipping_threshold', name: 'Didn\'t want to buy more to get free shipping' },
{ id: 'delivery_too_slow', name: 'Delivery time too slow' },
{ id: 'no_express', name: 'No express shipping option' },
{ id: 'international', name: 'International shipping issues' }
],
orientation: 'vertical'
});
});
shippingSection.addRow(row => {
row.addSlider('maxShippingWilling', {
label: 'Maximum shipping cost you\'d be willing to pay ($)',
min: 0,
max: 20,
step: 1,
showValue: true,
unit: '$',
defaultValue: 5
});
});
shippingSection.addRow(row => {
row.addThumbRating('freeShippingConvert', {
label: 'Would free shipping convince you to complete the purchase?',
showLabels: true,
upLabel: 'Yes, definitely',
downLabel: 'Not the main issue',
alignment: 'left'
});
});
// ============================================
// SECTION 4: Checkout Issues (Conditional)
// ============================================
const checkoutSection = form.addSubform('checkoutSection', {
title: 'Checkout Experience',
isVisible: () => {
const reason = primarySection.radioButton('primaryReason')?.value();
return reason === 'checkout_issues' || reason === 'payment_issues';
},
customStyles: { padding: '16px', borderRadius: '8px', backgroundColor: '#fee2e2', borderLeft: '4px solid #ef4444' }
});
checkoutSection.addRow(row => {
row.addCheckboxList('checkoutProblems', {
label: 'What problems did you encounter?',
options: [
{ id: 'too_many_steps', name: 'Too many steps' },
{ id: 'account_required', name: 'Required account creation' },
{ id: 'form_errors', name: 'Form errors/validation issues' },
{ id: 'slow_loading', name: 'Page was slow to load' },
{ id: 'confusing_layout', name: 'Confusing layout' },
{ id: 'missing_payment', name: 'My payment method wasn\'t available' },
{ id: 'payment_failed', name: 'Payment was declined' },
{ id: 'coupon_issues', name: 'Coupon code didn\'t work' }
],
orientation: 'vertical'
});
});
checkoutSection.addRow(row => {
row.addDropdown('preferredPayment', {
label: 'What payment method would you prefer?',
options: [
{ id: 'credit_card', name: 'Credit/Debit Card' },
{ id: 'paypal', name: 'PayPal' },
{ id: 'apple_pay', name: 'Apple Pay' },
{ id: 'google_pay', name: 'Google Pay' },
{ id: 'klarna', name: 'Buy Now Pay Later (Klarna, Affirm)' },
{ id: 'crypto', name: 'Cryptocurrency' },
{ id: 'bank_transfer', name: 'Bank Transfer' }
],
placeholder: 'Select preferred payment'
});
});
// ============================================
// SECTION 5: Trust Concerns (Conditional)
// ============================================
const trustSection = form.addSubform('trustSection', {
title: 'Trust & Security',
isVisible: () => primarySection.radioButton('primaryReason')?.value() === 'trust_concerns',
customStyles: { padding: '16px', borderRadius: '8px', backgroundColor: '#faf5ff', borderLeft: '4px solid #a855f7' }
});
trustSection.addRow(row => {
row.addCheckboxList('trustConcerns', {
label: 'What made you concerned?',
options: [
{ id: 'no_https', name: 'Website didn\'t seem secure' },
{ id: 'unknown_brand', name: 'Never heard of this store before' },
{ id: 'no_reviews', name: 'Couldn\'t find reviews' },
{ id: 'too_good', name: 'Prices seemed too good to be true' },
{ id: 'payment_security', name: 'Worried about payment security' },
{ id: 'return_policy', name: 'Unclear return policy' },
{ id: 'contact_info', name: 'No contact information visible' }
],
orientation: 'vertical'
});
});
trustSection.addRow(row => {
row.addSuggestionChips('wouldHelpTrust', {
label: 'What would help build your trust?',
suggestions: [
{ id: 'reviews', name: 'Customer Reviews' },
{ id: 'security_badges', name: 'Security Badges' },
{ id: 'money_back', name: 'Money-Back Guarantee' },
{ id: 'contact', name: 'Easy Contact' },
{ id: 'social_proof', name: 'Social Media Presence' },
{ id: 'secure_payment', name: 'Trusted Payment Methods' }
],
max: 3,
alignment: 'left'
});
});
// ============================================
// SECTION 6: Just Browsing (Conditional)
// ============================================
const browsingSection = form.addSubform('browsingSection', {
title: 'When Will You Be Ready?',
isVisible: () => primarySection.radioButton('primaryReason')?.value() === 'just_browsing',
customStyles: { padding: '16px', borderRadius: '8px', backgroundColor: '#ecfdf5', borderLeft: '4px solid #10b981' }
});
browsingSection.addRow(row => {
row.addRadioButton('purchaseTimeline', {
label: 'When do you plan to make a purchase?',
options: [
{ id: 'today', name: 'Today, just deciding' },
{ id: 'this_week', name: 'This week' },
{ id: 'this_month', name: 'This month' },
{ id: 'researching', name: 'Still researching options' },
{ id: 'not_sure', name: 'Not sure yet' }
],
orientation: 'vertical'
});
});
browsingSection.addRow(row => {
row.addThumbRating('saveCart', {
label: 'Would you like us to save your cart?',
showLabels: true,
upLabel: 'Yes, save it',
downLabel: 'No thanks',
alignment: 'left'
});
});
browsingSection.addRow(row => {
row.addCheckbox('notifyPriceDrop', {
label: 'Notify me if prices drop on items in my cart'
});
});
// ============================================
// SECTION 7: Other Reason (Conditional)
// ============================================
const otherSection = form.addSubform('otherSection', {
title: 'Tell Us More',
isVisible: () => primarySection.radioButton('primaryReason')?.value() === 'other',
customStyles: { padding: '16px', borderRadius: '8px', border: '1px solid #e2e8f0' }
});
otherSection.addRow(row => {
row.addTextarea('otherReason', {
label: 'Please describe what stopped you',
placeholder: 'Your feedback helps us improve...',
rows: 3,
autoExpand: true,
isRequired: true
});
});
// ============================================
// SECTION 8: Product Feedback
// ============================================
const productSection = form.addSubform('productSection', {
title: 'About the Product(s)',
customStyles: { padding: '16px', borderRadius: '8px', border: '1px solid #e2e8f0' }
});
productSection.addRow(row => {
row.addThumbRating('foundWhatNeeded', {
label: 'Did you find what you were looking for?',
showLabels: true,
upLabel: 'Yes',
downLabel: 'No / Partially',
alignment: 'left'
});
});
productSection.addRow(row => {
row.addTextarea('missingProduct', {
label: 'What were you looking for that you couldn\'t find?',
placeholder: 'Help us improve our selection...',
rows: 2,
autoExpand: true,
isVisible: () => productSection.thumbRating('foundWhatNeeded')?.value() === 'down'
});
});
productSection.addRow(row => {
row.addRadioButton('productInfoSufficient', {
label: 'Was there enough product information?',
options: [
{ id: 'yes', name: 'Yes, plenty of info' },
{ id: 'mostly', name: 'Mostly, but some gaps' },
{ id: 'no', name: 'No, needed more details' }
],
orientation: 'horizontal'
});
});
productSection.addRow(row => {
row.addCheckboxList('missingInfo', {
label: 'What information was missing?',
options: [
{ id: 'specs', name: 'Technical specifications' },
{ id: 'size_guide', name: 'Size guide/dimensions' },
{ id: 'reviews', name: 'Customer reviews' },
{ id: 'photos', name: 'More product photos' },
{ id: 'video', name: 'Product video' },
{ id: 'availability', name: 'Stock/availability info' }
],
orientation: 'vertical',
isVisible: () => productSection.radioButton('productInfoSufficient')?.value() !== 'yes'
});
});
// ============================================
// SECTION 9: Recovery Options
// ============================================
const recoverySection = form.addSubform('recoverySection', {
title: 'How Can We Help?',
customStyles: { padding: '16px', borderRadius: '8px', backgroundColor: '#f0fdf4' }
});
recoverySection.addRow(row => {
row.addCheckboxList('helpOptions', {
label: 'What would help you complete your purchase?',
options: [
{ id: 'discount', name: 'A discount code' },
{ id: 'free_shipping', name: 'Free shipping' },
{ id: 'remind_later', name: 'A reminder email later' },
{ id: 'chat_support', name: 'Live chat support' },
{ id: 'phone_support', name: 'Phone support' },
{ id: 'more_info', name: 'More product information' },
{ id: 'nothing', name: 'Nothing right now' }
],
orientation: 'vertical'
});
});
// ============================================
// SECTION 10: Contact for Follow-up
// ============================================
const contactSection = form.addSubform('contactSection', {
title: 'Stay Connected',
isVisible: () => {
const helpOptions = recoverySection.checkboxList('helpOptions')?.value() || [];
return !helpOptions.includes('nothing');
}
});
contactSection.addRow(row => {
row.addCheckbox('subscribeOffers', {
label: 'Send me exclusive offers and discounts'
});
});
contactSection.addRow(row => {
row.addEmail('contactEmail', {
label: 'Email Address',
placeholder: 'your@email.com',
isVisible: () => contactSection.checkbox('subscribeOffers')?.value() === true,
isRequired: () => contactSection.checkbox('subscribeOffers')?.value() === true
});
});
// ============================================
// SUMMARY SECTION
// ============================================
const summarySection = form.addSubform('summarySection', {
title: 'Summary',
isVisible: () => primarySection.radioButton('primaryReason')?.value() !== null
});
summarySection.addRow(row => {
row.addTextPanel('summaryContent', {
computedValue: () => {
const reason = primarySection.radioButton('primaryReason')?.value();
const helpOptions = recoverySection.checkboxList('helpOptions')?.value() || [];
const wouldBuyWithDiscount = priceSection.thumbRating('wouldBuyWithDiscount')?.value();
const freeShippingConvert = shippingSection.thumbRating('freeShippingConvert')?.value();
if (!reason) return '';
const reasonLabels: Record<string, string> = {
'price_too_high': 'Price concerns',
'shipping_cost': 'Shipping costs',
'just_browsing': 'Just browsing',
'comparing': 'Price comparison',
'checkout_issues': 'Checkout problems',
'payment_issues': 'Payment issues',
'trust_concerns': 'Trust/security',
'found_elsewhere': 'Found elsewhere',
'delivery_time': 'Delivery time',
'other': 'Other reason'
};
let emoji = '🛒';
if (wouldBuyWithDiscount === 'up' || freeShippingConvert === 'up') {
emoji = '💰';
} else if (reason === 'just_browsing') {
emoji = '👀';
}
let summary = `${emoji} Cart Abandonment Summary\n`;
summary += `${'═'.repeat(28)}\n\n`;
summary += `📋 Main Reason: ${reasonLabels[reason] || reason}\n`;
if (helpOptions.length > 0 && !helpOptions.includes('nothing')) {
summary += `\n🤝 Recovery Options: ${helpOptions.length} selected`;
}
if (wouldBuyWithDiscount === 'up') {
summary += `\n💸 Would convert with discount`;
}
if (freeShippingConvert === 'up') {
summary += `\n🚚 Would convert with free shipping`;
}
return summary;
},
customStyles: {
padding: '16px',
borderRadius: '8px',
whiteSpace: 'pre-wrap',
fontFamily: 'monospace',
fontSize: '14px',
backgroundColor: '#fff7ed',
borderLeft: '4px solid #f97316'
}
});
});
// ============================================
// FORM CONFIGURATION
// ============================================
form.configureSubmitButton({
label: 'Submit Feedback',
isVisible: () => primarySection.radioButton('primaryReason')?.value() !== null
});
form.configureCompletionScreen({
type: 'text',
title: 'Thank You for Your Feedback!',
message: 'Your input helps us create a better shopping experience. We hope to see you back soon!'
});
}