Manage localStorage events with clearStoredEvents(), including date-based filtering and count limits
Remove all stored events while keeping the session active.
// Clear all stored events
widget.store.clearStoredEvents();Clear older events but keep the most recent N events.
// Keep only the last 5 events
widget.store.clearStoredEvents(5);Clear events older than a specified time period.
// Clear events older than 1 hour
const cutoff = Date.now() - 1 * 60 * 60 * 1000;
widget.store.clearStoredEvents({ beforeDate: new Date(cutoff) });Clear events before a specific date using an ISO 8601 string or timestamp.
// Clear events before a specific date (ISO string)
widget.store.clearStoredEvents({
beforeDate: '2026-01-14T12:00:00.000Z'
});
// Also accepts Unix timestamp (milliseconds)
widget.store.clearStoredEvents({
beforeDate: 1736856000000
});Apply both filters: first remove events before the date, then apply keepCount to the remaining events.
// Combined: date filter + keep count
// 1. First removes events before the date
// 2. Then keeps only the last 5 of remaining events
widget.store.clearStoredEvents({
beforeDate: new Date(Date.now() - 1 * 60 * 60 * 1000),
keepCount: 5
});Completely remove all localStorage data for this experience. This clears session, events, state, and disclaimer acceptance. The widget will need to be reinitialized.
// Static method - no widget instance needed
const success = NexusChatWidget.clearStorage("your-experience-id");
// Clears: session, events, state, disclaimer acceptance
// Returns: true if cleared, false if localStorage unavailableActions will appear here...
Try the controls on the left!
// Type definitions
interface ClearEventsOptions {
keepCount?: number; // Keep at least N most recent events
beforeDate?: Date | string | number; // Clear events before this date
}
// Method signature (supports both forms for backward compatibility)
store.clearStoredEvents(options?: number | ClearEventsOptions): void
// Behavior:
// - No arguments: clears all stored events
// - Number: keeps the last N events (backward compatible)
// - { beforeDate }: clears events with timestamp < beforeDate
// - { keepCount }: keeps last N events
// - { beforeDate, keepCount }:
// 1. First removes events before beforeDate
// 2. Then if remaining > keepCount, keeps only last keepCount
// Date parameter accepts:
// - Date object: new Date('2026-01-14')
// - ISO 8601 string: '2026-01-14T12:00:00.000Z'
// - Unix timestamp (ms): 1736856000000
// Note: Events with timestamp >= beforeDate are preserved