@pocketping/widget 0.3.2 → 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{index.mjs → index.cjs} +471 -79
- package/dist/{index.d.mts → index.d.cts} +79 -5
- package/dist/index.d.ts +79 -5
- package/dist/index.js +432 -116
- package/dist/pocketping.min.global.js +90 -2
- package/package.json +9 -8
|
@@ -123,6 +123,24 @@ interface CustomEvent {
|
|
|
123
123
|
}
|
|
124
124
|
/** Handler for custom events */
|
|
125
125
|
type CustomEventHandler = (data: Record<string, unknown> | undefined, event: CustomEvent) => void;
|
|
126
|
+
/** Options for trigger() method */
|
|
127
|
+
interface TriggerOptions {
|
|
128
|
+
/** If provided, opens the widget and shows this message */
|
|
129
|
+
widgetMessage?: string;
|
|
130
|
+
}
|
|
131
|
+
/** Tracked element configuration (for SaaS auto-tracking) */
|
|
132
|
+
interface TrackedElement {
|
|
133
|
+
/** CSS selector for the element(s) to track */
|
|
134
|
+
selector: string;
|
|
135
|
+
/** DOM event to listen for (default: 'click') */
|
|
136
|
+
event?: 'click' | 'submit' | 'focus' | 'change' | 'mouseenter';
|
|
137
|
+
/** Event name sent to backend */
|
|
138
|
+
name: string;
|
|
139
|
+
/** If provided, opens widget with this message when triggered */
|
|
140
|
+
widgetMessage?: string;
|
|
141
|
+
/** Additional data to send with the event */
|
|
142
|
+
data?: Record<string, unknown>;
|
|
143
|
+
}
|
|
126
144
|
/**
|
|
127
145
|
* User identity data for identifying visitors
|
|
128
146
|
* @example
|
|
@@ -159,6 +177,10 @@ declare class PocketPingClient {
|
|
|
159
177
|
private reconnectAttempts;
|
|
160
178
|
private maxReconnectAttempts;
|
|
161
179
|
private reconnectTimeout;
|
|
180
|
+
private trackedElementCleanups;
|
|
181
|
+
private currentTrackedElements;
|
|
182
|
+
private inspectorMode;
|
|
183
|
+
private inspectorCleanup;
|
|
162
184
|
constructor(config: ResolvedPocketPingConfig);
|
|
163
185
|
connect(): Promise<Session>;
|
|
164
186
|
disconnect(): void;
|
|
@@ -206,10 +228,15 @@ declare class PocketPingClient {
|
|
|
206
228
|
* Trigger a custom event to the backend
|
|
207
229
|
* @param eventName - The name of the event (e.g., 'clicked_pricing', 'viewed_demo')
|
|
208
230
|
* @param data - Optional payload to send with the event
|
|
231
|
+
* @param options - Optional trigger options (widgetMessage to open chat)
|
|
209
232
|
* @example
|
|
210
|
-
*
|
|
233
|
+
* // Silent event (just notify bridges)
|
|
234
|
+
* PocketPing.trigger('clicked_cta', { button: 'signup' })
|
|
235
|
+
*
|
|
236
|
+
* // Open widget with message
|
|
237
|
+
* PocketPing.trigger('clicked_pricing', { plan: 'pro' }, { widgetMessage: 'Need help choosing a plan?' })
|
|
211
238
|
*/
|
|
212
|
-
trigger(eventName: string, data?: Record<string, unknown
|
|
239
|
+
trigger(eventName: string, data?: Record<string, unknown>, options?: TriggerOptions): void;
|
|
213
240
|
/**
|
|
214
241
|
* Subscribe to custom events from the backend
|
|
215
242
|
* @param eventName - The name of the event to listen for (e.g., 'show_offer', 'open_chat')
|
|
@@ -228,6 +255,32 @@ declare class PocketPingClient {
|
|
|
228
255
|
*/
|
|
229
256
|
offEvent(eventName: string, handler: CustomEventHandler): void;
|
|
230
257
|
private emitCustomEvent;
|
|
258
|
+
/**
|
|
259
|
+
* Setup tracked elements from config (used by SaaS dashboard)
|
|
260
|
+
* @param elements - Array of tracked element configurations
|
|
261
|
+
*/
|
|
262
|
+
setupTrackedElements(elements: TrackedElement[]): void;
|
|
263
|
+
/**
|
|
264
|
+
* Cleanup all tracked element listeners
|
|
265
|
+
*/
|
|
266
|
+
private cleanupTrackedElements;
|
|
267
|
+
/**
|
|
268
|
+
* Get current tracked elements configuration
|
|
269
|
+
*/
|
|
270
|
+
getTrackedElements(): TrackedElement[];
|
|
271
|
+
/**
|
|
272
|
+
* Enable inspector mode for visual element selection
|
|
273
|
+
* This shows an overlay that allows clicking on elements to get their CSS selector
|
|
274
|
+
*/
|
|
275
|
+
private enableInspectorMode;
|
|
276
|
+
/**
|
|
277
|
+
* Disable inspector mode
|
|
278
|
+
*/
|
|
279
|
+
private disableInspectorMode;
|
|
280
|
+
/**
|
|
281
|
+
* Check if inspector mode is active
|
|
282
|
+
*/
|
|
283
|
+
isInspectorModeActive(): boolean;
|
|
231
284
|
private connectWebSocket;
|
|
232
285
|
private handleWebSocketEvent;
|
|
233
286
|
private handleVersionWarning;
|
|
@@ -254,10 +307,29 @@ declare function sendMessage(content: string): Promise<Message>;
|
|
|
254
307
|
* Trigger a custom event to the backend
|
|
255
308
|
* @param eventName - The name of the event (e.g., 'clicked_pricing', 'viewed_demo')
|
|
256
309
|
* @param data - Optional payload to send with the event
|
|
310
|
+
* @param options - Optional trigger options (widgetMessage to open chat)
|
|
257
311
|
* @example
|
|
258
|
-
*
|
|
312
|
+
* // Silent event (just notify bridges)
|
|
313
|
+
* PocketPing.trigger('clicked_cta', { button: 'signup' })
|
|
314
|
+
*
|
|
315
|
+
* // Open widget with message
|
|
316
|
+
* PocketPing.trigger('clicked_pricing', { plan: 'pro' }, { widgetMessage: 'Need help choosing?' })
|
|
317
|
+
*/
|
|
318
|
+
declare function trigger(eventName: string, data?: Record<string, unknown>, options?: TriggerOptions): void;
|
|
319
|
+
/**
|
|
320
|
+
* Setup tracked elements for auto-tracking (typically called by SaaS backend)
|
|
321
|
+
* @param elements - Array of tracked element configurations
|
|
322
|
+
* @example
|
|
323
|
+
* PocketPing.setupTrackedElements([
|
|
324
|
+
* { selector: '#search-btn', event: 'click', name: 'clicked_search' },
|
|
325
|
+
* { selector: '.pricing-card', event: 'click', name: 'viewed_pricing', widgetMessage: 'Need help?' }
|
|
326
|
+
* ])
|
|
327
|
+
*/
|
|
328
|
+
declare function setupTrackedElements(elements: TrackedElement[]): void;
|
|
329
|
+
/**
|
|
330
|
+
* Get current tracked elements configuration
|
|
259
331
|
*/
|
|
260
|
-
declare function
|
|
332
|
+
declare function getTrackedElements(): TrackedElement[];
|
|
261
333
|
/**
|
|
262
334
|
* Subscribe to custom events from the backend
|
|
263
335
|
* @param eventName - The name of the event to listen for
|
|
@@ -335,6 +407,8 @@ declare const _default: {
|
|
|
335
407
|
identify: typeof identify;
|
|
336
408
|
reset: typeof reset;
|
|
337
409
|
getIdentity: typeof getIdentity;
|
|
410
|
+
setupTrackedElements: typeof setupTrackedElements;
|
|
411
|
+
getTrackedElements: typeof getTrackedElements;
|
|
338
412
|
};
|
|
339
413
|
|
|
340
|
-
export { type CustomEvent, type CustomEventHandler, type Message, type PocketPingConfig, type UserIdentity, type VersionWarning, close, _default as default, destroy, getIdentity, identify, init, offEvent, on, onEvent, open, reset, sendMessage, toggle, trigger };
|
|
414
|
+
export { type CustomEvent, type CustomEventHandler, type Message, type PocketPingConfig, type TrackedElement, type TriggerOptions, type UserIdentity, type VersionWarning, close, _default as default, destroy, getIdentity, getTrackedElements, identify, init, offEvent, on, onEvent, open, reset, sendMessage, setupTrackedElements, toggle, trigger };
|
package/dist/index.d.ts
CHANGED
|
@@ -123,6 +123,24 @@ interface CustomEvent {
|
|
|
123
123
|
}
|
|
124
124
|
/** Handler for custom events */
|
|
125
125
|
type CustomEventHandler = (data: Record<string, unknown> | undefined, event: CustomEvent) => void;
|
|
126
|
+
/** Options for trigger() method */
|
|
127
|
+
interface TriggerOptions {
|
|
128
|
+
/** If provided, opens the widget and shows this message */
|
|
129
|
+
widgetMessage?: string;
|
|
130
|
+
}
|
|
131
|
+
/** Tracked element configuration (for SaaS auto-tracking) */
|
|
132
|
+
interface TrackedElement {
|
|
133
|
+
/** CSS selector for the element(s) to track */
|
|
134
|
+
selector: string;
|
|
135
|
+
/** DOM event to listen for (default: 'click') */
|
|
136
|
+
event?: 'click' | 'submit' | 'focus' | 'change' | 'mouseenter';
|
|
137
|
+
/** Event name sent to backend */
|
|
138
|
+
name: string;
|
|
139
|
+
/** If provided, opens widget with this message when triggered */
|
|
140
|
+
widgetMessage?: string;
|
|
141
|
+
/** Additional data to send with the event */
|
|
142
|
+
data?: Record<string, unknown>;
|
|
143
|
+
}
|
|
126
144
|
/**
|
|
127
145
|
* User identity data for identifying visitors
|
|
128
146
|
* @example
|
|
@@ -159,6 +177,10 @@ declare class PocketPingClient {
|
|
|
159
177
|
private reconnectAttempts;
|
|
160
178
|
private maxReconnectAttempts;
|
|
161
179
|
private reconnectTimeout;
|
|
180
|
+
private trackedElementCleanups;
|
|
181
|
+
private currentTrackedElements;
|
|
182
|
+
private inspectorMode;
|
|
183
|
+
private inspectorCleanup;
|
|
162
184
|
constructor(config: ResolvedPocketPingConfig);
|
|
163
185
|
connect(): Promise<Session>;
|
|
164
186
|
disconnect(): void;
|
|
@@ -206,10 +228,15 @@ declare class PocketPingClient {
|
|
|
206
228
|
* Trigger a custom event to the backend
|
|
207
229
|
* @param eventName - The name of the event (e.g., 'clicked_pricing', 'viewed_demo')
|
|
208
230
|
* @param data - Optional payload to send with the event
|
|
231
|
+
* @param options - Optional trigger options (widgetMessage to open chat)
|
|
209
232
|
* @example
|
|
210
|
-
*
|
|
233
|
+
* // Silent event (just notify bridges)
|
|
234
|
+
* PocketPing.trigger('clicked_cta', { button: 'signup' })
|
|
235
|
+
*
|
|
236
|
+
* // Open widget with message
|
|
237
|
+
* PocketPing.trigger('clicked_pricing', { plan: 'pro' }, { widgetMessage: 'Need help choosing a plan?' })
|
|
211
238
|
*/
|
|
212
|
-
trigger(eventName: string, data?: Record<string, unknown
|
|
239
|
+
trigger(eventName: string, data?: Record<string, unknown>, options?: TriggerOptions): void;
|
|
213
240
|
/**
|
|
214
241
|
* Subscribe to custom events from the backend
|
|
215
242
|
* @param eventName - The name of the event to listen for (e.g., 'show_offer', 'open_chat')
|
|
@@ -228,6 +255,32 @@ declare class PocketPingClient {
|
|
|
228
255
|
*/
|
|
229
256
|
offEvent(eventName: string, handler: CustomEventHandler): void;
|
|
230
257
|
private emitCustomEvent;
|
|
258
|
+
/**
|
|
259
|
+
* Setup tracked elements from config (used by SaaS dashboard)
|
|
260
|
+
* @param elements - Array of tracked element configurations
|
|
261
|
+
*/
|
|
262
|
+
setupTrackedElements(elements: TrackedElement[]): void;
|
|
263
|
+
/**
|
|
264
|
+
* Cleanup all tracked element listeners
|
|
265
|
+
*/
|
|
266
|
+
private cleanupTrackedElements;
|
|
267
|
+
/**
|
|
268
|
+
* Get current tracked elements configuration
|
|
269
|
+
*/
|
|
270
|
+
getTrackedElements(): TrackedElement[];
|
|
271
|
+
/**
|
|
272
|
+
* Enable inspector mode for visual element selection
|
|
273
|
+
* This shows an overlay that allows clicking on elements to get their CSS selector
|
|
274
|
+
*/
|
|
275
|
+
private enableInspectorMode;
|
|
276
|
+
/**
|
|
277
|
+
* Disable inspector mode
|
|
278
|
+
*/
|
|
279
|
+
private disableInspectorMode;
|
|
280
|
+
/**
|
|
281
|
+
* Check if inspector mode is active
|
|
282
|
+
*/
|
|
283
|
+
isInspectorModeActive(): boolean;
|
|
231
284
|
private connectWebSocket;
|
|
232
285
|
private handleWebSocketEvent;
|
|
233
286
|
private handleVersionWarning;
|
|
@@ -254,10 +307,29 @@ declare function sendMessage(content: string): Promise<Message>;
|
|
|
254
307
|
* Trigger a custom event to the backend
|
|
255
308
|
* @param eventName - The name of the event (e.g., 'clicked_pricing', 'viewed_demo')
|
|
256
309
|
* @param data - Optional payload to send with the event
|
|
310
|
+
* @param options - Optional trigger options (widgetMessage to open chat)
|
|
257
311
|
* @example
|
|
258
|
-
*
|
|
312
|
+
* // Silent event (just notify bridges)
|
|
313
|
+
* PocketPing.trigger('clicked_cta', { button: 'signup' })
|
|
314
|
+
*
|
|
315
|
+
* // Open widget with message
|
|
316
|
+
* PocketPing.trigger('clicked_pricing', { plan: 'pro' }, { widgetMessage: 'Need help choosing?' })
|
|
317
|
+
*/
|
|
318
|
+
declare function trigger(eventName: string, data?: Record<string, unknown>, options?: TriggerOptions): void;
|
|
319
|
+
/**
|
|
320
|
+
* Setup tracked elements for auto-tracking (typically called by SaaS backend)
|
|
321
|
+
* @param elements - Array of tracked element configurations
|
|
322
|
+
* @example
|
|
323
|
+
* PocketPing.setupTrackedElements([
|
|
324
|
+
* { selector: '#search-btn', event: 'click', name: 'clicked_search' },
|
|
325
|
+
* { selector: '.pricing-card', event: 'click', name: 'viewed_pricing', widgetMessage: 'Need help?' }
|
|
326
|
+
* ])
|
|
327
|
+
*/
|
|
328
|
+
declare function setupTrackedElements(elements: TrackedElement[]): void;
|
|
329
|
+
/**
|
|
330
|
+
* Get current tracked elements configuration
|
|
259
331
|
*/
|
|
260
|
-
declare function
|
|
332
|
+
declare function getTrackedElements(): TrackedElement[];
|
|
261
333
|
/**
|
|
262
334
|
* Subscribe to custom events from the backend
|
|
263
335
|
* @param eventName - The name of the event to listen for
|
|
@@ -335,6 +407,8 @@ declare const _default: {
|
|
|
335
407
|
identify: typeof identify;
|
|
336
408
|
reset: typeof reset;
|
|
337
409
|
getIdentity: typeof getIdentity;
|
|
410
|
+
setupTrackedElements: typeof setupTrackedElements;
|
|
411
|
+
getTrackedElements: typeof getTrackedElements;
|
|
338
412
|
};
|
|
339
413
|
|
|
340
|
-
export { type CustomEvent, type CustomEventHandler, type Message, type PocketPingConfig, type UserIdentity, type VersionWarning, close, _default as default, destroy, getIdentity, identify, init, offEvent, on, onEvent, open, reset, sendMessage, toggle, trigger };
|
|
414
|
+
export { type CustomEvent, type CustomEventHandler, type Message, type PocketPingConfig, type TrackedElement, type TriggerOptions, type UserIdentity, type VersionWarning, close, _default as default, destroy, getIdentity, getTrackedElements, identify, init, offEvent, on, onEvent, open, reset, sendMessage, setupTrackedElements, toggle, trigger };
|