gotcha-feedback 1.1.5 → 1.1.7

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 CHANGED
@@ -46,10 +46,16 @@ function FeatureCard() {
46
46
  - **Bug Flagging** - Let users flag feedback as issues/bugs with a single toggle
47
47
  - **User Segmentation** - Analyze feedback by custom user attributes
48
48
  - **Edit Support** - Users can update their previous submissions
49
+ - **Programmatic Trigger** - Open/close the widget from code with `useGotchaTrigger`
50
+ - **Follow-up Questions** - Ask a follow-up after low ratings or negative votes
51
+ - **Trigger Conditions** - Show widget after time delay, scroll depth, or visit count
52
+ - **Screenshot Capture** - Users can attach screenshots when reporting bugs
53
+ - **Offline Support** - Submissions queue in localStorage when offline, flush on reconnect
54
+ - **Context Enrichment** - Viewport, timezone, language, and recent JS errors auto-attached
55
+ - **Visibility Control** - Hide widget for N days after submission, reset onePerUser after N days
49
56
  - **Customizable** - Themes, sizes, positions
50
57
  - **Accessible** - Full keyboard navigation and screen reader support
51
58
  - **Animated** - Smooth enter/exit animations with CSS transitions
52
- - **Lightweight** - ~11KB gzipped
53
59
 
54
60
  ## Props
55
61
 
@@ -86,6 +92,18 @@ function FeatureCard() {
86
92
  | `npsHighLabel` | `string` | `'Very likely'` | Label for high end of NPS scale |
87
93
  | `enableBugFlag` | `boolean` | `false` | Show "Report an issue" toggle in feedback form |
88
94
  | `bugFlagLabel` | `string` | `'Report an issue'` | Custom label for the bug flag toggle |
95
+ | `enableScreenshot` | `boolean` | `false` | Enable screenshot capture when bug flag is toggled (requires `enableBugFlag`) |
96
+ | `onePerUser` | `boolean` | `false` | Show edit mode instead of new form when user has existing response |
97
+ | `cooldownDays` | `number` | - | Allow new submission after N days (requires `onePerUser`) |
98
+ | `hideAfterSubmitDays` | `number` | - | Hide widget for N days after submission (localStorage) |
99
+ | `showAfterSeconds` | `number` | - | Delay showing widget by N seconds |
100
+ | `showAfterScrollPercent` | `number` | - | Show widget after scrolling past N% (0-100) |
101
+ | `showAfterVisits` | `number` | - | Show widget after N page visits (localStorage) |
102
+ | `followUp` | `object` | - | Show follow-up question after low rating or negative vote |
103
+ | `followUp.ratingThreshold` | `number` | - | Ratings at or below this trigger the follow-up |
104
+ | `followUp.onNegativeVote` | `boolean` | - | Trigger follow-up on thumbs down |
105
+ | `followUp.promptText` | `string` | Required | The follow-up question text |
106
+ | `followUp.placeholder` | `string` | `'Tell us more...'` | Placeholder for follow-up textarea |
89
107
  | `user` | `object` | - | User metadata for segmentation |
90
108
  | `onSubmit` | `function` | - | Callback after submission |
91
109
  | `onOpen` | `function` | - | Callback when modal opens |
@@ -180,6 +198,82 @@ Add a "Report an issue" toggle to any feedback form. When toggled on, the submis
180
198
  />
181
199
  ```
182
200
 
201
+ ### Screenshot Capture
202
+
203
+ When bug flagging is enabled, you can also let users capture and attach a screenshot. Tries `html2canvas` first (install as optional peer dep), falls back to the native Screen Capture API.
204
+
205
+ ```tsx
206
+ <Gotcha
207
+ elementId="checkout"
208
+ mode="feedback"
209
+ enableBugFlag
210
+ enableScreenshot
211
+ />
212
+ ```
213
+
214
+ ### Follow-up Questions
215
+
216
+ Ask a follow-up question when users give a low rating or negative vote. The follow-up updates the original response.
217
+
218
+ ```tsx
219
+ <Gotcha
220
+ elementId="feature"
221
+ mode="feedback"
222
+ followUp={{
223
+ ratingThreshold: 2, // Ratings 1-2 trigger follow-up
224
+ promptText: "What could we improve?",
225
+ placeholder: "Tell us more...",
226
+ }}
227
+ />
228
+ ```
229
+
230
+ ```tsx
231
+ // Follow-up on negative vote
232
+ <Gotcha
233
+ elementId="article"
234
+ mode="vote"
235
+ followUp={{
236
+ onNegativeVote: true,
237
+ promptText: "What went wrong?",
238
+ }}
239
+ />
240
+ ```
241
+
242
+ ### Trigger Conditions
243
+
244
+ Control when the widget appears based on user engagement. All specified conditions must be met (AND logic).
245
+
246
+ ```tsx
247
+ // Show after 5 seconds on page
248
+ <Gotcha elementId="onboarding" showAfterSeconds={5} />
249
+
250
+ // Show after scrolling 50%
251
+ <Gotcha elementId="article-end" showAfterScrollPercent={50} />
252
+
253
+ // Show after 3 visits
254
+ <Gotcha elementId="feature" showAfterVisits={3} />
255
+
256
+ // Combine: show after 10 seconds AND 3 visits
257
+ <Gotcha elementId="power-user" showAfterSeconds={10} showAfterVisits={3} />
258
+ ```
259
+
260
+ ### Visibility Control
261
+
262
+ Hide the widget for a period after submission, or allow re-submission after a cooldown.
263
+
264
+ ```tsx
265
+ // Hide widget for 7 days after submission
266
+ <Gotcha elementId="nps" hideAfterSubmitDays={7} />
267
+
268
+ // One response per user, but allow new submission after 30 days
269
+ <Gotcha
270
+ elementId="quarterly-survey"
271
+ onePerUser
272
+ cooldownDays={30}
273
+ user={{ id: currentUser.id }}
274
+ />
275
+ ```
276
+
183
277
  ### Feedback Field Options
184
278
 
185
279
  By default, feedback mode shows both a star rating and a text input. Use `showText` and `showRating` to control which fields appear.
@@ -279,6 +373,29 @@ Pass any attributes relevant to your use case. Supported value types: `string`,
279
373
 
280
374
  ## Hooks
281
375
 
376
+ ### useGotchaTrigger
377
+
378
+ Open or close a specific widget programmatically. The corresponding `<Gotcha>` component must be mounted.
379
+
380
+ ```tsx
381
+ import { useGotchaTrigger } from 'gotcha-feedback';
382
+
383
+ function ErrorBoundary({ children }) {
384
+ const { open } = useGotchaTrigger('error-feedback');
385
+
386
+ const handleError = () => {
387
+ open(); // Opens the feedback modal for "error-feedback"
388
+ };
389
+
390
+ return <ErrorHandler onError={handleError}>{children}</ErrorHandler>;
391
+ }
392
+
393
+ // The widget must be rendered somewhere in the tree
394
+ <Gotcha elementId="error-feedback" mode="feedback" promptText="What happened?" />
395
+ ```
396
+
397
+ Returns `{ open, close, isOpen }`.
398
+
282
399
  ### useGotcha
283
400
 
284
401
  Access the Gotcha context for programmatic control:
@@ -287,7 +404,7 @@ Access the Gotcha context for programmatic control:
287
404
  import { useGotcha } from 'gotcha-feedback';
288
405
 
289
406
  function MyComponent() {
290
- const { submitFeedback, disabled } = useGotcha();
407
+ const { submitFeedback, openModal, closeModal } = useGotcha();
291
408
 
292
409
  const handleCustomSubmit = async () => {
293
410
  await submitFeedback({
@@ -302,6 +419,8 @@ function MyComponent() {
302
419
  }
303
420
  ```
304
421
 
422
+ Returns `{ client, disabled, defaultUser, debug, submitFeedback, openModal, closeModal, activeModalId }`.
423
+
305
424
  ## User Metadata & Segmentation
306
425
 
307
426
  When you pass custom attributes in the `user` prop, Gotcha automatically tracks them and enables segmentation in your dashboard.
@@ -383,12 +502,34 @@ import { GotchaScore } from 'gotcha-feedback';
383
502
  | `theme` | `'light' \| 'dark' \| 'auto'` | `'auto'` | Color theme |
384
503
  | `refreshInterval` | `number` | - | Auto-refresh interval in ms |
385
504
 
505
+ ## Offline Support
506
+
507
+ Submissions are automatically queued in localStorage when the user is offline. When connectivity returns, queued items are flushed automatically. A subtle indicator appears on the widget button when items are queued. No configuration needed — this works out of the box.
508
+
509
+ ## Context Enrichment
510
+
511
+ Every submission automatically includes enriched context beyond the page URL and user agent:
512
+
513
+ - **Viewport size** (width x height)
514
+ - **Language** and **timezone**
515
+ - **Screen resolution**
516
+ - **Recent JS errors** (last 10 uncaught errors and unhandled rejections)
517
+
518
+ This context appears in your dashboard and is included in bug ticket descriptions. No configuration needed.
519
+
386
520
  ## TypeScript
387
521
 
388
522
  The package includes full TypeScript definitions:
389
523
 
390
524
  ```tsx
391
- import type { GotchaProps, GotchaProviderProps, ScoreData } from 'gotcha-feedback';
525
+ import type {
526
+ GotchaProps,
527
+ GotchaProviderProps,
528
+ ScoreData,
529
+ SubmissionContext,
530
+ GotchaResponse,
531
+ GotchaError,
532
+ } from 'gotcha-feedback';
392
533
  ```
393
534
 
394
535
  ## Requirements
package/dist/index.d.mts CHANGED
@@ -34,6 +34,25 @@ interface GotchaStyles {
34
34
  backdrop?: React.CSSProperties;
35
35
  spinner?: React.CSSProperties;
36
36
  }
37
+ interface SubmissionContext {
38
+ url?: string;
39
+ userAgent?: string;
40
+ viewport?: {
41
+ width: number;
42
+ height: number;
43
+ };
44
+ language?: string;
45
+ timezone?: string;
46
+ screenResolution?: {
47
+ width: number;
48
+ height: number;
49
+ };
50
+ recentErrors?: Array<{
51
+ message: string;
52
+ source?: string;
53
+ timestamp: number;
54
+ }>;
55
+ }
37
56
  interface SubmitResponsePayload {
38
57
  elementId: string;
39
58
  mode: ResponseMode;
@@ -44,15 +63,13 @@ interface SubmitResponsePayload {
44
63
  pollOptions?: string[];
45
64
  pollSelected?: string[];
46
65
  isBug?: boolean;
66
+ screenshot?: string;
47
67
  user?: GotchaUser;
48
- context?: {
49
- url?: string;
50
- userAgent?: string;
51
- };
68
+ context?: SubmissionContext;
52
69
  }
53
70
  interface GotchaResponse {
54
71
  id: string;
55
- status: 'created' | 'duplicate' | 'updated';
72
+ status: 'created' | 'duplicate' | 'updated' | 'queued';
56
73
  createdAt: string;
57
74
  results?: PollResults;
58
75
  }
@@ -89,6 +106,8 @@ interface ScoreData {
89
106
  npsScore: number | null;
90
107
  }
91
108
 
109
+ declare function getQueueLength(): number;
110
+
92
111
  interface GotchaThemeColors {
93
112
  primary: string;
94
113
  primaryHover: string;
@@ -277,8 +296,32 @@ interface GotchaProps {
277
296
  enableBugFlag?: boolean;
278
297
  /** Custom label for the bug flag toggle (default: "Report an issue") */
279
298
  bugFlagLabel?: string;
299
+ /** Enable screenshot capture when bug flag is toggled (requires html2canvas peer dep, falls back to native API) */
300
+ enableScreenshot?: boolean;
280
301
  /** When true and user has already responded, show submitted state and allow review/edit instead of new submission */
281
302
  onePerUser?: boolean;
303
+ /** When onePerUser is true, allow a new submission after this many days. Has no effect without onePerUser. */
304
+ cooldownDays?: number;
305
+ /** After submission, hide the widget for this many days (client-side, localStorage).
306
+ * Independent of cooldownDays — the widget stays hidden for the full duration even if cooldown expires sooner. */
307
+ hideAfterSubmitDays?: number;
308
+ /** Delay showing widget by N seconds after page load */
309
+ showAfterSeconds?: number;
310
+ /** Show widget after user scrolls past this percentage (0-100) */
311
+ showAfterScrollPercent?: number;
312
+ /** Show widget after user has visited N times (uses localStorage) */
313
+ showAfterVisits?: number;
314
+ /** Show a follow-up question after low rating or negative vote */
315
+ followUp?: {
316
+ /** Rating threshold (inclusive) — e.g., 2 means ratings 1-2 trigger follow-up */
317
+ ratingThreshold?: number;
318
+ /** Also trigger on negative vote */
319
+ onNegativeVote?: boolean;
320
+ /** The prompt text shown */
321
+ promptText: string;
322
+ /** Placeholder for the follow-up textarea */
323
+ placeholder?: string;
324
+ };
282
325
  /** Enable entrance animations on the button and modal (default: true) */
283
326
  animated?: boolean;
284
327
  /** Called after successful submission */
@@ -290,7 +333,7 @@ interface GotchaProps {
290
333
  /** Called on error */
291
334
  onError?: (error: GotchaError) => void;
292
335
  }
293
- declare function Gotcha({ elementId, user, mode, showText, showRating, voteLabels, options, allowMultiple, npsQuestion, npsFollowUp, npsFollowUpPlaceholder, npsLowLabel, npsHighLabel, enableBugFlag, bugFlagLabel, onePerUser, animated, position, size, theme, customStyles, visible, showOnHover, touchBehavior, promptText, placeholder, submitText, thankYouMessage, onSubmit, onOpen, onClose, onError, }: GotchaProps): react_jsx_runtime.JSX.Element | null;
336
+ declare function Gotcha({ elementId, user, mode, showText, showRating, voteLabels, options, allowMultiple, npsQuestion, npsFollowUp, npsFollowUpPlaceholder, npsLowLabel, npsHighLabel, enableBugFlag, bugFlagLabel, enableScreenshot, onePerUser, cooldownDays, hideAfterSubmitDays, showAfterSeconds, showAfterScrollPercent, showAfterVisits, followUp, animated, position, size, theme, customStyles, visible, showOnHover, touchBehavior, promptText, placeholder, submitText, thankYouMessage, onSubmit, onOpen, onClose, onError, }: GotchaProps): react_jsx_runtime.JSX.Element | null;
294
337
 
295
338
  type ScoreVariant = 'stars' | 'number' | 'compact' | 'votes';
296
339
  interface GotchaScoreProps {
@@ -325,6 +368,8 @@ declare function useGotcha(): {
325
368
  ticketId: string;
326
369
  status: string;
327
370
  }>;
371
+ flushQueue(): Promise<void>;
372
+ getQueueLength: typeof getQueueLength;
328
373
  getBaseUrl(): string;
329
374
  };
330
375
  /** Whether Gotcha is globally disabled */
@@ -335,6 +380,22 @@ declare function useGotcha(): {
335
380
  debug: boolean;
336
381
  /** Submit feedback programmatically */
337
382
  submitFeedback: (payload: Omit<SubmitResponsePayload, "context">) => Promise<GotchaResponse>;
383
+ /** Open a specific Gotcha modal by elementId */
384
+ openModal: (elementId: string) => void;
385
+ /** Close the currently open modal */
386
+ closeModal: () => void;
387
+ /** The currently open modal's elementId, or null */
388
+ activeModalId: string | null;
389
+ };
390
+
391
+ /**
392
+ * Hook to programmatically open/close a specific Gotcha widget.
393
+ * The corresponding <Gotcha elementId="..."> must be mounted for the modal to render.
394
+ */
395
+ declare function useGotchaTrigger(elementId: string): {
396
+ open: () => void;
397
+ close: () => void;
398
+ isOpen: boolean;
338
399
  };
339
400
 
340
- export { Gotcha, type GotchaError, type GotchaProps, GotchaProvider, type GotchaProviderProps, type GotchaResponse, GotchaScore, type GotchaScoreProps, type GotchaStyles, type GotchaThemeConfig, type GotchaUser, type Position, type ResponseMode, type ScoreData, type Size, type Theme, type TouchBehavior, type VoteType, createTheme, useGotcha };
401
+ export { Gotcha, type GotchaError, type GotchaProps, GotchaProvider, type GotchaProviderProps, type GotchaResponse, GotchaScore, type GotchaScoreProps, type GotchaStyles, type GotchaThemeConfig, type GotchaUser, type Position, type ResponseMode, type ScoreData, type Size, type SubmissionContext, type Theme, type TouchBehavior, type VoteType, createTheme, useGotcha, useGotchaTrigger };
package/dist/index.d.ts CHANGED
@@ -34,6 +34,25 @@ interface GotchaStyles {
34
34
  backdrop?: React.CSSProperties;
35
35
  spinner?: React.CSSProperties;
36
36
  }
37
+ interface SubmissionContext {
38
+ url?: string;
39
+ userAgent?: string;
40
+ viewport?: {
41
+ width: number;
42
+ height: number;
43
+ };
44
+ language?: string;
45
+ timezone?: string;
46
+ screenResolution?: {
47
+ width: number;
48
+ height: number;
49
+ };
50
+ recentErrors?: Array<{
51
+ message: string;
52
+ source?: string;
53
+ timestamp: number;
54
+ }>;
55
+ }
37
56
  interface SubmitResponsePayload {
38
57
  elementId: string;
39
58
  mode: ResponseMode;
@@ -44,15 +63,13 @@ interface SubmitResponsePayload {
44
63
  pollOptions?: string[];
45
64
  pollSelected?: string[];
46
65
  isBug?: boolean;
66
+ screenshot?: string;
47
67
  user?: GotchaUser;
48
- context?: {
49
- url?: string;
50
- userAgent?: string;
51
- };
68
+ context?: SubmissionContext;
52
69
  }
53
70
  interface GotchaResponse {
54
71
  id: string;
55
- status: 'created' | 'duplicate' | 'updated';
72
+ status: 'created' | 'duplicate' | 'updated' | 'queued';
56
73
  createdAt: string;
57
74
  results?: PollResults;
58
75
  }
@@ -89,6 +106,8 @@ interface ScoreData {
89
106
  npsScore: number | null;
90
107
  }
91
108
 
109
+ declare function getQueueLength(): number;
110
+
92
111
  interface GotchaThemeColors {
93
112
  primary: string;
94
113
  primaryHover: string;
@@ -277,8 +296,32 @@ interface GotchaProps {
277
296
  enableBugFlag?: boolean;
278
297
  /** Custom label for the bug flag toggle (default: "Report an issue") */
279
298
  bugFlagLabel?: string;
299
+ /** Enable screenshot capture when bug flag is toggled (requires html2canvas peer dep, falls back to native API) */
300
+ enableScreenshot?: boolean;
280
301
  /** When true and user has already responded, show submitted state and allow review/edit instead of new submission */
281
302
  onePerUser?: boolean;
303
+ /** When onePerUser is true, allow a new submission after this many days. Has no effect without onePerUser. */
304
+ cooldownDays?: number;
305
+ /** After submission, hide the widget for this many days (client-side, localStorage).
306
+ * Independent of cooldownDays — the widget stays hidden for the full duration even if cooldown expires sooner. */
307
+ hideAfterSubmitDays?: number;
308
+ /** Delay showing widget by N seconds after page load */
309
+ showAfterSeconds?: number;
310
+ /** Show widget after user scrolls past this percentage (0-100) */
311
+ showAfterScrollPercent?: number;
312
+ /** Show widget after user has visited N times (uses localStorage) */
313
+ showAfterVisits?: number;
314
+ /** Show a follow-up question after low rating or negative vote */
315
+ followUp?: {
316
+ /** Rating threshold (inclusive) — e.g., 2 means ratings 1-2 trigger follow-up */
317
+ ratingThreshold?: number;
318
+ /** Also trigger on negative vote */
319
+ onNegativeVote?: boolean;
320
+ /** The prompt text shown */
321
+ promptText: string;
322
+ /** Placeholder for the follow-up textarea */
323
+ placeholder?: string;
324
+ };
282
325
  /** Enable entrance animations on the button and modal (default: true) */
283
326
  animated?: boolean;
284
327
  /** Called after successful submission */
@@ -290,7 +333,7 @@ interface GotchaProps {
290
333
  /** Called on error */
291
334
  onError?: (error: GotchaError) => void;
292
335
  }
293
- declare function Gotcha({ elementId, user, mode, showText, showRating, voteLabels, options, allowMultiple, npsQuestion, npsFollowUp, npsFollowUpPlaceholder, npsLowLabel, npsHighLabel, enableBugFlag, bugFlagLabel, onePerUser, animated, position, size, theme, customStyles, visible, showOnHover, touchBehavior, promptText, placeholder, submitText, thankYouMessage, onSubmit, onOpen, onClose, onError, }: GotchaProps): react_jsx_runtime.JSX.Element | null;
336
+ declare function Gotcha({ elementId, user, mode, showText, showRating, voteLabels, options, allowMultiple, npsQuestion, npsFollowUp, npsFollowUpPlaceholder, npsLowLabel, npsHighLabel, enableBugFlag, bugFlagLabel, enableScreenshot, onePerUser, cooldownDays, hideAfterSubmitDays, showAfterSeconds, showAfterScrollPercent, showAfterVisits, followUp, animated, position, size, theme, customStyles, visible, showOnHover, touchBehavior, promptText, placeholder, submitText, thankYouMessage, onSubmit, onOpen, onClose, onError, }: GotchaProps): react_jsx_runtime.JSX.Element | null;
294
337
 
295
338
  type ScoreVariant = 'stars' | 'number' | 'compact' | 'votes';
296
339
  interface GotchaScoreProps {
@@ -325,6 +368,8 @@ declare function useGotcha(): {
325
368
  ticketId: string;
326
369
  status: string;
327
370
  }>;
371
+ flushQueue(): Promise<void>;
372
+ getQueueLength: typeof getQueueLength;
328
373
  getBaseUrl(): string;
329
374
  };
330
375
  /** Whether Gotcha is globally disabled */
@@ -335,6 +380,22 @@ declare function useGotcha(): {
335
380
  debug: boolean;
336
381
  /** Submit feedback programmatically */
337
382
  submitFeedback: (payload: Omit<SubmitResponsePayload, "context">) => Promise<GotchaResponse>;
383
+ /** Open a specific Gotcha modal by elementId */
384
+ openModal: (elementId: string) => void;
385
+ /** Close the currently open modal */
386
+ closeModal: () => void;
387
+ /** The currently open modal's elementId, or null */
388
+ activeModalId: string | null;
389
+ };
390
+
391
+ /**
392
+ * Hook to programmatically open/close a specific Gotcha widget.
393
+ * The corresponding <Gotcha elementId="..."> must be mounted for the modal to render.
394
+ */
395
+ declare function useGotchaTrigger(elementId: string): {
396
+ open: () => void;
397
+ close: () => void;
398
+ isOpen: boolean;
338
399
  };
339
400
 
340
- export { Gotcha, type GotchaError, type GotchaProps, GotchaProvider, type GotchaProviderProps, type GotchaResponse, GotchaScore, type GotchaScoreProps, type GotchaStyles, type GotchaThemeConfig, type GotchaUser, type Position, type ResponseMode, type ScoreData, type Size, type Theme, type TouchBehavior, type VoteType, createTheme, useGotcha };
401
+ export { Gotcha, type GotchaError, type GotchaProps, GotchaProvider, type GotchaProviderProps, type GotchaResponse, GotchaScore, type GotchaScoreProps, type GotchaStyles, type GotchaThemeConfig, type GotchaUser, type Position, type ResponseMode, type ScoreData, type Size, type SubmissionContext, type Theme, type TouchBehavior, type VoteType, createTheme, useGotcha, useGotchaTrigger };