Debug Mode
The Campaign Cart SDK includes a comprehensive debug overlay system that helps developers inspect state, monitor events, and troubleshoot issues during development.
Enabling Debug Mode
Section titled “Enabling Debug Mode”Add the ?debugger=true parameter to any page URL:
https://yoursite.com/checkout?debugger=true- Automatic activation - Debug overlay loads and displays at the bottom of the page
- Global access - Creates the
window.nextDebugobject for console access - Verbose logging - Sets logger to DEBUG level for detailed console output
Debug Overlay Features
Section titled “Debug Overlay Features”The debug overlay provides multiple panels for inspecting different aspects of the SDK:
1. Cart Panel
Section titled “1. Cart Panel”- View current cart state and items
- Inspect cart totals, discounts, and calculations
- Monitor cart updates in real-time
- Test cart operations directly
2. Config Panel
Section titled “2. Config Panel”- View current SDK configuration
- Inspect API keys and endpoints
- Check feature flags and settings
- Monitor configuration changes
3. Campaign Panel
Section titled “3. Campaign Panel”- View campaign data and settings
- Inspect product/package information
- Monitor campaign-specific state
- Test campaign operations
4. Checkout Panel
Section titled “4. Checkout Panel”- Monitor checkout form state
- Inspect validation errors
- View payment method selections
- Debug checkout flow issues
5. Event Timeline Panel
Section titled “5. Event Timeline Panel”- Real-time event monitoring
- Visual timeline of SDK events
- Event details and payloads
- Performance timing information
6. Storage Panel
Section titled “6. Storage Panel”- Inspect localStorage data
- View sessionStorage contents
- Monitor storage changes
- Clear storage for testing
Using Debug Mode
Section titled “Using Debug Mode”Global Access
Section titled “Global Access”When debug mode is active (via ?debugger=true), a global nextDebug object is available in the console:
// Access debug overlay controlsnextDebug.overlay.show()nextDebug.overlay.hide()nextDebug.overlay.toggle()nextDebug.overlay.isVisible()// Debug mode managementnextDebug.enableDebug() // Enables debug mode programmaticallynextDebug.disableDebug() // Disables debug mode and removes URL paramnextDebug.toggleDebug() // Toggles debug mode on/offnextDebug.isDebugMode() // Returns true/false// Access to SDK storesnextDebug.stores.cart // Cart storenextDebug.stores.campaign // Campaign storenextDebug.stores.config // Config storenextDebug.stores.checkout // Checkout storenextDebug.stores.order // Order storenextDebug.stores.attribution // Attribution store// SDK instancenextDebug.sdk // NextCommerce instance
// Utility methodsnextDebug.reinitialize() // Reinitialize the SDKnextDebug.getStats() // Get initialization statisticsKeyboard Shortcuts
Section titled “Keyboard Shortcuts”When the debug overlay is visible:
ESC- Toggle overlay visibilityTab- Switch between panels↑/↓- Navigate within panels
Panel-Specific Features
Section titled “Panel-Specific Features”Cart Panel Actions
Section titled “Cart Panel Actions”- Add/remove test items
- Apply test discounts
- Clear cart
- Simulate cart errors
Event Timeline
Section titled “Event Timeline”- Filter events by type
- Export event log
- Clear timeline
- Pause/resume monitoring
Storage Panel
Section titled “Storage Panel”- Search storage keys
- Edit values directly
- Export/import storage
- Clear specific keys
Visual Debugging
Section titled “Visual Debugging”X-Ray Mode
Section titled “X-Ray Mode”The debugger includes an X-Ray mode that highlights SDK-enhanced elements with color-coded outlines:
- Cyan (
#4ecdc4): Display attributes (data-next-display) - Yellow (
#ffe66d): Conditional visibility (data-next-show) - Red (
#ff6b6b): Checkout elements - Green (
#a8e6cf): Package selectors - Purple (
#6c5ce7): Bump/toggle elements - Orange (
#ffa502): Selected states - Pink (
#ff8b94): Package IDs
Toggle X-Ray mode from the debug overlay toolbar.
Performance Monitoring
Section titled “Performance Monitoring”- Track render times
- Monitor API call durations
- Identify performance bottlenecks
- View memory usage
Advanced Features
Section titled “Advanced Features”Cart Operations
Section titled “Cart Operations”// Add items to cartnextDebug.addToCart(packageId, quantity)
// Remove items from cartnextDebug.removeFromCart(packageId)
// Update quantitynextDebug.updateQuantity(packageId, quantity)
// Add test items (packages 2, 7, 9)nextDebug.addTestItems()Campaign Inspection
Section titled “Campaign Inspection”// Reload campaign datanextDebug.loadCampaign()
// Clear campaign cachenextDebug.clearCampaignCache()
// Get cache informationnextDebug.getCacheInfo()
// Inspect specific package detailsnextDebug.inspectPackage(packageId)
// Test shipping methodsnextDebug.testShippingMethod(methodId)Analytics Debugging
Section titled “Analytics Debugging”// Get analytics statusawait nextDebug.analytics.getStatus()
// View active providersawait nextDebug.analytics.getProviders()
// Track custom eventawait nextDebug.analytics.track('custom_event', { data: 'value' })
// Enable analytics debug modeawait nextDebug.analytics.setDebugMode(true)
// Invalidate analytics contextawait nextDebug.analytics.invalidateContext()Attribution Debugging
Section titled “Attribution Debugging”// Debug attribution datanextDebug.attribution.debug()
// Get attribution for APInextDebug.attribution.get()
// Set funnel namenextDebug.attribution.setFunnel('FUNNEL_NAME')
// Set Everflow click IDnextDebug.attribution.setEvclid('click_id')
// Get current funnelnextDebug.attribution.getFunnel()
// Clear persisted funnelnextDebug.attribution.clearFunnel()Order Management
Section titled “Order Management”// View upsell journeynextDebug.order.getJourney()
// Check if order is expirednextDebug.order.isExpired()
// Clear order cachenextDebug.order.clearCache()
// Get order statisticsnextDebug.order.getStats()Accordion Controls
Section titled “Accordion Controls”// Open accordionnextDebug.accordion.open('accordion-id')
// Close accordionnextDebug.accordion.close('accordion-id')
// Toggle accordionnextDebug.accordion.toggle('accordion-id')Custom Event Logging
Section titled “Custom Event Logging”// Log custom events to the timelinewindow.dispatchEvent(new CustomEvent('debug:log', { detail: { type: 'custom', message: 'My debug message', data: { /* any data */ } }}));
// Update debug contentwindow.dispatchEvent(new CustomEvent('debug:update-content'));State Snapshots
Section titled “State Snapshots”- Save current state for later comparison
- Export state as JSON
- Import saved states for testing
- Compare state differences
Network Monitoring
Section titled “Network Monitoring”- View API requests and responses
- Inspect request headers
- Monitor request timing
- Simulate network errors
Alternative Activation Methods
Section titled “Alternative Activation Methods”https://yoursite.com?debugger=trueThe primary and recommended method.
<meta name="next-debug" content="true">Enables debug mode without URL parameter.
window.nextConfig = { debug: true};Configure via JavaScript before SDK loads.
// First, check if the SDK is loadedif (window.next) { // Add debugger=true to URL and reload const url = new URL(window.location.href); url.searchParams.set('debugger', 'true'); window.location.href = url.toString();}Activate from code (requires page reload).
Best Practices
Section titled “Best Practices”- Development Only - Never enable debug mode in production environments
- Performance Impact - Debug mode adds overhead; disable when testing performance
- Privacy Concerns - Debug overlay may display sensitive data (API keys, customer info)
- Storage Management - Clear debug storage regularly to avoid conflicts
Troubleshooting
Section titled “Troubleshooting”Debug Overlay Not Appearing
Section titled “Debug Overlay Not Appearing”- Ensure
?debugger=trueis in the URL - Check browser console for errors
- Verify SDK is properly loaded
- Try hard refresh (
Ctrl+F5orCmd+Shift+R)
Performance Issues
Section titled “Performance Issues”If the debug overlay is causing performance problems:
- Disable event timeline if too many events
- Clear storage panel data
- Reduce update frequency in settings
- Use panel-specific views instead of “All”
Console Errors
Section titled “Console Errors”nextDebug is undefined
Section titled “nextDebug is undefined”This happens when debug mode is not enabled. Solutions:
https://yoursite.com?debugger=trueAdd the parameter and reload.
// First, check if the SDK is loadedif (window.next) { // Add debugger=true to URL and reload const url = new URL(window.location.href); url.searchParams.set('debugger', 'true'); window.location.href = url.toString();}// In your config.jswindow.nextConfig = { debug: true, // other config...};Panel-specific errors
Section titled “Panel-specific errors”// Refresh specific panelnextDebug.overlay.updateContent()
// Reinitialize debug overlaynextDebug.reinitialize()Security Considerations
Section titled “Security Considerations”The debug overlay displays:
- API keys and configuration
- Cart and order details
- Customer information
- Analytics data
- Internal SDK state
Best practices:
- Be cautious when sharing debug screenshots
- Clear sensitive data from storage panel
- Disable debug mode for production builds
- Use environment-specific configuration
Integration with Dev Tools
Section titled “Integration with Dev Tools”The debug overlay complements browser dev tools:
- Console logs include debug context
- Network tab shows SDK requests
- Elements panel highlights SDK attributes
- Performance profiler includes SDK marks
Related Documentation
Section titled “Related Documentation”- URL Parameters - Other functional URL parameters
- Configuration Reference - Complete SDK configuration
- Events - SDK event system