@magicfeedback/popup-sdk 1.0.10 → 1.0.11
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/README.md +19 -16
- package/dist/index.d.mts +20 -13
- package/dist/index.d.ts +20 -13
- package/dist/index.js +268 -44
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +268 -44
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -25,7 +25,7 @@ popups.init({
|
|
|
25
25
|
id: 'popup-123',
|
|
26
26
|
title: 'Help us improve?',
|
|
27
27
|
message: '<p>Take a quick survey and share your thoughts.</p>',
|
|
28
|
-
|
|
28
|
+
triggers: {type: 'time_on_page', value: 5, condition: [{answered: false, cooldownDays: 7}]},
|
|
29
29
|
actions: {
|
|
30
30
|
accept: {label: 'Take Survey', surveyId: 'survey-abc'},
|
|
31
31
|
decline: {label: 'Not Now', cooldownDays: 7}
|
|
@@ -38,12 +38,8 @@ popups.init({
|
|
|
38
38
|
]
|
|
39
39
|
});
|
|
40
40
|
|
|
41
|
-
//
|
|
42
|
-
popups.
|
|
43
|
-
surveyId: 'survey-abc',
|
|
44
|
-
productId: 'product-xyz',
|
|
45
|
-
data: {source: 'homepage'}
|
|
46
|
-
});
|
|
41
|
+
// Start triggers
|
|
42
|
+
popups.autoLaunch();
|
|
47
43
|
|
|
48
44
|
// Listen to events
|
|
49
45
|
popups.on('popup_shown', (ev) => console.log('Shown:', ev));
|
|
@@ -53,8 +49,8 @@ popups.on('survey_completed', (ev) => console.log('Completed:', ev));
|
|
|
53
49
|
|
|
54
50
|
## Features
|
|
55
51
|
|
|
56
|
-
- ✅ Simple API: initialize and
|
|
57
|
-
- ✅ Auto-launch triggers: time, scroll, exit intent
|
|
52
|
+
- ✅ Simple API: initialize and launch popups with minimal code
|
|
53
|
+
- ✅ Auto-launch triggers: time, scroll, exit intent, click
|
|
58
54
|
- ✅ Automatic trigger derivation from popup definitions (`time_on_page` → internal `time` in ms)
|
|
59
55
|
- ✅ Conditions & cooldowns: prevent display if already answered or within cooldown window
|
|
60
56
|
- ✅ Event system: `popup_shown`, `popup_clicked`, `survey_completed`
|
|
@@ -98,13 +94,14 @@ popups.showByPopupId('popup-123');
|
|
|
98
94
|
```
|
|
99
95
|
|
|
100
96
|
#### `configureTriggers(triggers: TriggerConfig[]): void`
|
|
101
|
-
Registers manual triggers.
|
|
97
|
+
Registers manual triggers. Most apps should use `autoLaunch()` and popup definitions instead.
|
|
102
98
|
|
|
103
99
|
```typescript
|
|
104
100
|
popups.configureTriggers([
|
|
105
101
|
{ type: 'time', value: 5000, surveyId: 'survey-1' },
|
|
106
102
|
{ type: 'scroll', value: 60, surveyId: 'survey-2' },
|
|
107
|
-
{ type: 'exit', surveyId: 'survey-3' }
|
|
103
|
+
{ type: 'exit', surveyId: 'survey-3' },
|
|
104
|
+
{ type: 'click', value: 'cta-button', surveyId: 'survey-4' }
|
|
108
105
|
]);
|
|
109
106
|
```
|
|
110
107
|
|
|
@@ -149,7 +146,8 @@ sdk.init({ mode: 'client', popups: [...] });
|
|
|
149
146
|
When using `client` mode you can preload definitions. In `server` mode a fake fetch creates sample definitions. Trigger types in definitions:
|
|
150
147
|
- `time_on_page` (seconds) → mapped automatically to internal `time` trigger (milliseconds)
|
|
151
148
|
- `scroll` (percentage scrolled)
|
|
152
|
-
- `exit` (exit intent)
|
|
149
|
+
- `exit` (route/navigation exit intent)
|
|
150
|
+
- `click` (element id, string)
|
|
153
151
|
|
|
154
152
|
Structure:
|
|
155
153
|
|
|
@@ -158,9 +156,9 @@ interface PopupDefinition {
|
|
|
158
156
|
id: string;
|
|
159
157
|
title: string;
|
|
160
158
|
message: string; // HTML string
|
|
161
|
-
|
|
162
|
-
type: 'time_on_page' | 'scroll' | 'exit';
|
|
163
|
-
value: number; // seconds
|
|
159
|
+
triggers: {
|
|
160
|
+
type: 'time_on_page' | 'scroll' | 'exit' | 'click';
|
|
161
|
+
value: number | string; // seconds, percentage, or element id for click
|
|
164
162
|
condition?: { answered: boolean; cooldownDays: number }[];
|
|
165
163
|
};
|
|
166
164
|
actions: {
|
|
@@ -204,12 +202,17 @@ interface DeepdotsEvent {
|
|
|
204
202
|
```typescript
|
|
205
203
|
{ type: 'time', value: 5000, surveyId: 'survey-1' } // after 5s
|
|
206
204
|
{ type: 'scroll', value: 50, surveyId: 'survey-2' } // at 50% scroll
|
|
207
|
-
{ type: 'exit', surveyId: 'survey-3' } // exit intent
|
|
205
|
+
{ type: 'exit', surveyId: 'survey-3' } // navigation exit intent
|
|
206
|
+
{ type: 'click', value: 'cta-button', surveyId: 'survey-4' } // click on element id
|
|
208
207
|
```
|
|
209
208
|
|
|
210
209
|
## Automatic Trigger Derivation
|
|
211
210
|
When definitions are loaded, each `time_on_page` trigger is converted to `{ type: 'time', value: seconds * 1000 }`. You just call `autoLaunch()` and derived triggers start.
|
|
212
211
|
|
|
212
|
+
## Trigger Behavior Notes
|
|
213
|
+
- `exit` fires on navigation intent (link clicks or SPA route changes). It does not depend on mouse leaving the viewport.
|
|
214
|
+
- `click` expects a DOM element id in `value`. The handler attaches on `DOMContentLoaded` if the element isn't available immediately.
|
|
215
|
+
|
|
213
216
|
## Styling & Container
|
|
214
217
|
Browser renderer creates a container `#deepdots-popup-container` with an overlay. Override styles via global CSS (e.g. `.deepdots-popup`, `#deepdots-popup-container`). The layout is intentionally minimal.
|
|
215
218
|
|
package/dist/index.d.mts
CHANGED
|
@@ -12,27 +12,29 @@ interface DeepdotsInitParams {
|
|
|
12
12
|
debug?: boolean;
|
|
13
13
|
/** Lista de definiciones de popups precargadas */
|
|
14
14
|
popups?: PopupDefinition[];
|
|
15
|
+
/** Optional user id to send with popup events */
|
|
16
|
+
userId?: string;
|
|
15
17
|
}
|
|
16
18
|
interface DeepdotsConfig {
|
|
17
19
|
/** API key for authentication */
|
|
18
20
|
apiKey?: string;
|
|
19
|
-
/** Base url to contact with the api */
|
|
20
|
-
baseUrl?: string;
|
|
21
21
|
/** Execution mode: 'server' or 'client' */
|
|
22
22
|
mode?: 'server' | 'client';
|
|
23
23
|
/** Enable debug logging */
|
|
24
24
|
debug?: boolean;
|
|
25
25
|
/** Lista de definiciones de popups precargadas */
|
|
26
26
|
popups?: PopupDefinition[];
|
|
27
|
+
/** Optional user id to send with popup events */
|
|
28
|
+
userId?: string;
|
|
27
29
|
}
|
|
28
30
|
/**
|
|
29
31
|
* Options for configuring survey triggers
|
|
30
32
|
*/
|
|
31
33
|
interface TriggerConfig {
|
|
32
|
-
/** Trigger type: 'time' (delay), 'scroll' (scroll percentage), 'exit' (exit intent) */
|
|
33
|
-
type: 'time' | 'scroll' | 'exit';
|
|
34
|
-
/** Value for the trigger (milliseconds for time, percentage for scroll) */
|
|
35
|
-
value?: number;
|
|
34
|
+
/** Trigger type: 'time' (delay), 'scroll' (scroll percentage), 'exit' (exit intent), 'click' (element id) */
|
|
35
|
+
type: 'time' | 'scroll' | 'exit' | 'click';
|
|
36
|
+
/** Value for the trigger (milliseconds for time, percentage for scroll, element id for click) */
|
|
37
|
+
value?: number | string;
|
|
36
38
|
/** Survey ID to show when triggered */
|
|
37
39
|
surveyId: string;
|
|
38
40
|
}
|
|
@@ -65,7 +67,7 @@ interface DeepdotsEvent {
|
|
|
65
67
|
*/
|
|
66
68
|
type EventListener = (event: DeepdotsEvent) => void;
|
|
67
69
|
/** Tipo de trigger específico para definiciones de popup remotas */
|
|
68
|
-
type PopupTriggerType = 'time_on_page' | 'scroll' | 'exit';
|
|
70
|
+
type PopupTriggerType = 'time_on_page' | 'scroll' | 'exit' | 'click';
|
|
69
71
|
/** Condición adicional para la activación del popup */
|
|
70
72
|
interface PopupTriggerCondition {
|
|
71
73
|
answered: boolean;
|
|
@@ -74,7 +76,7 @@ interface PopupTriggerCondition {
|
|
|
74
76
|
/** Trigger asociado a la definición del popup */
|
|
75
77
|
interface PopupTrigger {
|
|
76
78
|
type: PopupTriggerType;
|
|
77
|
-
value: number;
|
|
79
|
+
value: number | string;
|
|
78
80
|
condition?: PopupTriggerCondition[];
|
|
79
81
|
}
|
|
80
82
|
/** Acción de aceptar (abrir encuesta) */
|
|
@@ -123,7 +125,7 @@ interface PopupDefinition {
|
|
|
123
125
|
id: string;
|
|
124
126
|
title: string;
|
|
125
127
|
message: string;
|
|
126
|
-
|
|
128
|
+
triggers: PopupTrigger;
|
|
127
129
|
actions?: PopupActions;
|
|
128
130
|
surveyId: string;
|
|
129
131
|
productId: string;
|
|
@@ -135,7 +137,7 @@ interface PopupRenderer {
|
|
|
135
137
|
/** Preparar recursos si aplica */
|
|
136
138
|
init?(): void;
|
|
137
139
|
/** Mostrar popup */
|
|
138
|
-
show(surveyId: string, productId: string, actions: PopupActions | undefined, emit: (type: DeepdotsEventType, surveyId: string, data?: Record<string, unknown>) => void, onClose: () => void): void;
|
|
140
|
+
show(surveyId: string, productId: string, actions: PopupActions | undefined, emit: (type: DeepdotsEventType, surveyId: string, data?: Record<string, unknown>) => void, onClose: () => void, env?: string): void;
|
|
139
141
|
/** Ocultar popup */
|
|
140
142
|
hide(): void;
|
|
141
143
|
}
|
|
@@ -155,6 +157,9 @@ declare class DeepdotsPopups {
|
|
|
155
157
|
private pendingAutoLaunch;
|
|
156
158
|
private answeredSurveys;
|
|
157
159
|
private lastShown;
|
|
160
|
+
private surveyToPopupId;
|
|
161
|
+
private baseUrl;
|
|
162
|
+
private env;
|
|
158
163
|
/** Initialize the SDK with configuration */
|
|
159
164
|
init(config: DeepdotsInitParams): void;
|
|
160
165
|
/** Enable auto-launch functionality with configured triggers */
|
|
@@ -176,13 +181,14 @@ declare class DeepdotsPopups {
|
|
|
176
181
|
/** Lógica para evaluar condiciones antes de mostrar una encuesta */
|
|
177
182
|
triggerSurvey(surveyId: string): void;
|
|
178
183
|
private shouldShow;
|
|
184
|
+
private matchesSegmentsPath;
|
|
179
185
|
private evaluateCondition;
|
|
180
186
|
/** Marcar encuesta como contestada externamente */
|
|
181
187
|
markSurveyAnswered(surveyId: string): void;
|
|
182
|
-
/**
|
|
188
|
+
/** Fetch al servidor para obtener popups */
|
|
183
189
|
private fetchPopupsFromServer;
|
|
184
|
-
/**
|
|
185
|
-
private
|
|
190
|
+
/** Notifica eventos de popup a la API */
|
|
191
|
+
private postPopupEvent;
|
|
186
192
|
/** Add an event listener */
|
|
187
193
|
on(eventType: DeepdotsEventType, listener: EventListener): void;
|
|
188
194
|
/** Remove an event listener */
|
|
@@ -202,6 +208,7 @@ declare class DeepdotsPopups {
|
|
|
202
208
|
/** Set a custom renderer */
|
|
203
209
|
setRenderer(renderer: PopupRenderer): void;
|
|
204
210
|
private isPopupDefinition;
|
|
211
|
+
private normalizePopupDefinition;
|
|
205
212
|
private validatePopupDefinitions;
|
|
206
213
|
}
|
|
207
214
|
|
package/dist/index.d.ts
CHANGED
|
@@ -12,27 +12,29 @@ interface DeepdotsInitParams {
|
|
|
12
12
|
debug?: boolean;
|
|
13
13
|
/** Lista de definiciones de popups precargadas */
|
|
14
14
|
popups?: PopupDefinition[];
|
|
15
|
+
/** Optional user id to send with popup events */
|
|
16
|
+
userId?: string;
|
|
15
17
|
}
|
|
16
18
|
interface DeepdotsConfig {
|
|
17
19
|
/** API key for authentication */
|
|
18
20
|
apiKey?: string;
|
|
19
|
-
/** Base url to contact with the api */
|
|
20
|
-
baseUrl?: string;
|
|
21
21
|
/** Execution mode: 'server' or 'client' */
|
|
22
22
|
mode?: 'server' | 'client';
|
|
23
23
|
/** Enable debug logging */
|
|
24
24
|
debug?: boolean;
|
|
25
25
|
/** Lista de definiciones de popups precargadas */
|
|
26
26
|
popups?: PopupDefinition[];
|
|
27
|
+
/** Optional user id to send with popup events */
|
|
28
|
+
userId?: string;
|
|
27
29
|
}
|
|
28
30
|
/**
|
|
29
31
|
* Options for configuring survey triggers
|
|
30
32
|
*/
|
|
31
33
|
interface TriggerConfig {
|
|
32
|
-
/** Trigger type: 'time' (delay), 'scroll' (scroll percentage), 'exit' (exit intent) */
|
|
33
|
-
type: 'time' | 'scroll' | 'exit';
|
|
34
|
-
/** Value for the trigger (milliseconds for time, percentage for scroll) */
|
|
35
|
-
value?: number;
|
|
34
|
+
/** Trigger type: 'time' (delay), 'scroll' (scroll percentage), 'exit' (exit intent), 'click' (element id) */
|
|
35
|
+
type: 'time' | 'scroll' | 'exit' | 'click';
|
|
36
|
+
/** Value for the trigger (milliseconds for time, percentage for scroll, element id for click) */
|
|
37
|
+
value?: number | string;
|
|
36
38
|
/** Survey ID to show when triggered */
|
|
37
39
|
surveyId: string;
|
|
38
40
|
}
|
|
@@ -65,7 +67,7 @@ interface DeepdotsEvent {
|
|
|
65
67
|
*/
|
|
66
68
|
type EventListener = (event: DeepdotsEvent) => void;
|
|
67
69
|
/** Tipo de trigger específico para definiciones de popup remotas */
|
|
68
|
-
type PopupTriggerType = 'time_on_page' | 'scroll' | 'exit';
|
|
70
|
+
type PopupTriggerType = 'time_on_page' | 'scroll' | 'exit' | 'click';
|
|
69
71
|
/** Condición adicional para la activación del popup */
|
|
70
72
|
interface PopupTriggerCondition {
|
|
71
73
|
answered: boolean;
|
|
@@ -74,7 +76,7 @@ interface PopupTriggerCondition {
|
|
|
74
76
|
/** Trigger asociado a la definición del popup */
|
|
75
77
|
interface PopupTrigger {
|
|
76
78
|
type: PopupTriggerType;
|
|
77
|
-
value: number;
|
|
79
|
+
value: number | string;
|
|
78
80
|
condition?: PopupTriggerCondition[];
|
|
79
81
|
}
|
|
80
82
|
/** Acción de aceptar (abrir encuesta) */
|
|
@@ -123,7 +125,7 @@ interface PopupDefinition {
|
|
|
123
125
|
id: string;
|
|
124
126
|
title: string;
|
|
125
127
|
message: string;
|
|
126
|
-
|
|
128
|
+
triggers: PopupTrigger;
|
|
127
129
|
actions?: PopupActions;
|
|
128
130
|
surveyId: string;
|
|
129
131
|
productId: string;
|
|
@@ -135,7 +137,7 @@ interface PopupRenderer {
|
|
|
135
137
|
/** Preparar recursos si aplica */
|
|
136
138
|
init?(): void;
|
|
137
139
|
/** Mostrar popup */
|
|
138
|
-
show(surveyId: string, productId: string, actions: PopupActions | undefined, emit: (type: DeepdotsEventType, surveyId: string, data?: Record<string, unknown>) => void, onClose: () => void): void;
|
|
140
|
+
show(surveyId: string, productId: string, actions: PopupActions | undefined, emit: (type: DeepdotsEventType, surveyId: string, data?: Record<string, unknown>) => void, onClose: () => void, env?: string): void;
|
|
139
141
|
/** Ocultar popup */
|
|
140
142
|
hide(): void;
|
|
141
143
|
}
|
|
@@ -155,6 +157,9 @@ declare class DeepdotsPopups {
|
|
|
155
157
|
private pendingAutoLaunch;
|
|
156
158
|
private answeredSurveys;
|
|
157
159
|
private lastShown;
|
|
160
|
+
private surveyToPopupId;
|
|
161
|
+
private baseUrl;
|
|
162
|
+
private env;
|
|
158
163
|
/** Initialize the SDK with configuration */
|
|
159
164
|
init(config: DeepdotsInitParams): void;
|
|
160
165
|
/** Enable auto-launch functionality with configured triggers */
|
|
@@ -176,13 +181,14 @@ declare class DeepdotsPopups {
|
|
|
176
181
|
/** Lógica para evaluar condiciones antes de mostrar una encuesta */
|
|
177
182
|
triggerSurvey(surveyId: string): void;
|
|
178
183
|
private shouldShow;
|
|
184
|
+
private matchesSegmentsPath;
|
|
179
185
|
private evaluateCondition;
|
|
180
186
|
/** Marcar encuesta como contestada externamente */
|
|
181
187
|
markSurveyAnswered(surveyId: string): void;
|
|
182
|
-
/**
|
|
188
|
+
/** Fetch al servidor para obtener popups */
|
|
183
189
|
private fetchPopupsFromServer;
|
|
184
|
-
/**
|
|
185
|
-
private
|
|
190
|
+
/** Notifica eventos de popup a la API */
|
|
191
|
+
private postPopupEvent;
|
|
186
192
|
/** Add an event listener */
|
|
187
193
|
on(eventType: DeepdotsEventType, listener: EventListener): void;
|
|
188
194
|
/** Remove an event listener */
|
|
@@ -202,6 +208,7 @@ declare class DeepdotsPopups {
|
|
|
202
208
|
/** Set a custom renderer */
|
|
203
209
|
setRenderer(renderer: PopupRenderer): void;
|
|
204
210
|
private isPopupDefinition;
|
|
211
|
+
private normalizePopupDefinition;
|
|
205
212
|
private validatePopupDefinitions;
|
|
206
213
|
}
|
|
207
214
|
|