gotcha-feedback 1.1.6 → 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.
Files changed (2) hide show
  1. package/README.md +144 -3
  2. package/package.json +1 -1
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gotcha-feedback",
3
- "version": "1.1.6",
3
+ "version": "1.1.7",
4
4
  "description": "Developer-first contextual feedback SDK",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",