@survicate/survicate-web-package 28.7.1-npm → 28.9.0-npm

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/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "28.7.1-npm",
2
+ "version": "28.9.0-npm",
3
3
  "name": "@survicate/survicate-web-package",
4
4
  "description": "Survicate Web Package",
5
5
  "author": {
@@ -229,6 +229,40 @@ export interface SurveyApi {
229
229
  */
230
230
  getVisitorId: (surveyType?: SurveyType) => string;
231
231
 
232
+ /**
233
+ * Get the response UUID for the current survey session
234
+ *
235
+ * This method returns the unique identifier for the current survey response.
236
+ * When connectResponse is true:
237
+ * - If an active survey exists with answers being collected, returns the survey's existing response UUID
238
+ * - If no active survey exists, generates a new UUID (not stored)
239
+ * When connectResponse is false or undefined, generates a new UUID each time.
240
+ *
241
+ * Note: The survey state response UUID is only available when there's already an active survey
242
+ * with answers being collected. For programmatic submissions without an active survey,
243
+ * you should generate a UUID once and reuse it across multiple submitAnswer calls.
244
+ *
245
+ * @example
246
+ * ```javascript
247
+ * // Safest way: Get response UUID after a question is answered (ensures active survey)
248
+ * window._sva?.addEventListener('question_answered', function(surveyId, questionId) {
249
+ * if (surveyId === 'ab1791b79cacc6ba' && questionId === 1332422) {
250
+ * const responseUuid = window._sva?.getResponseUuid('WidgetSurvey', true);
251
+ *
252
+ * window._sva?.submitAnswer(
253
+ * { surveyId: 'ab1791b79cacc6ba', pointId: 1332423, answer: 'this was submitted by API' },
254
+ * responseUuid
255
+ * );
256
+ * }
257
+ * });
258
+ * ```
259
+ *
260
+ * @param surveyType - The survey type (WidgetSurvey or FeedbackButton) to get the response UUID for
261
+ * @param connectResponse - If true, returns existing response UUID from active survey, otherwise generates new UUID
262
+ * @returns Response UUID string
263
+ */
264
+ getResponseUuid: (surveyType: SurveyType, connectResponse?: boolean) => string;
265
+
232
266
  /**
233
267
  * Get metadata about survey points (questions)
234
268
  *
@@ -280,6 +314,10 @@ export interface SurveyApi {
280
314
  * without user interaction, useful for integrations or testing.
281
315
  *
282
316
  * @param params - Object containing survey, point, and answer information
317
+ * @param responseUuid - Optional response UUID to use for this answer submission.
318
+ * If provided and valid, reuses the existing response UUID, otherwise generates a new one.
319
+ * Useful when a survey is partially shown with some questions hidden, or when you want to
320
+ * connect all answers into a single record in the analysis tab.
283
321
  */
284
322
  submitAnswer: (params: {
285
323
  /** Survey ID */
@@ -290,7 +328,7 @@ export interface SurveyApi {
290
328
  answerId?: number;
291
329
  /** Answer value (for text or numeric questions) */
292
330
  answer?: string | number;
293
- }) => void;
331
+ }, responseUuid?: string) => void;
294
332
 
295
333
  /** Current visitor traits/attributes */
296
334
  traits?: VisitorAttributes;
@@ -353,6 +391,47 @@ declare const Survicate: {
353
391
  */
354
392
  getVisitorId: (surveyType?: SurveyType) => string;
355
393
 
394
+ /**
395
+ * Get the response UUID for the current survey session
396
+ *
397
+ * This method returns the unique identifier for the current survey response.
398
+ * When connectResponse is true:
399
+ * - If an active survey exists with answers being collected, returns the survey's existing response UUID
400
+ * - If no active survey exists, generates a new UUID (not stored)
401
+ * When connectResponse is false or undefined, generates a new UUID each time.
402
+ *
403
+ * Note: The survey state response UUID is only available when there's already an active survey
404
+ * with answers being collected. For programmatic submissions without an active survey,
405
+ * you should generate a UUID once and reuse it across multiple submitAnswer calls.
406
+ *
407
+ * @example
408
+ * ```javascript
409
+ * // Safest way: Get response UUID after a question is answered (ensures active survey)
410
+ * Survicate.addEventListener('question_answered', function(surveyId, questionId) {
411
+ * if (surveyId === 'ab1791b79cacc6ba' && questionId === 1332422) {
412
+ * const responseUuid = Survicate.getResponseUuid(Survicate.SurveyType.WidgetSurvey, true);
413
+ * Survicate.submitAnswer(
414
+ * { surveyId: 'ab1791b79cacc6ba', pointId: 1332423, answer: 'this was submitted by API' },
415
+ * responseUuid
416
+ * );
417
+ * }
418
+ * });
419
+ *
420
+ * // Alternative: Get a new response UUID (generates new UUID each time)
421
+ * const responseUuid = Survicate.getResponseUuid(Survicate.SurveyType.WidgetSurvey);
422
+ *
423
+ * // For programmatic submissions without active survey, generate UUID once and reuse it
424
+ * const responseUuid = Survicate.getResponseUuid(Survicate.SurveyType.WidgetSurvey);
425
+ * Survicate.submitAnswer({ surveyId: 'survey-1', pointId: 1, answerId: 5 }, responseUuid);
426
+ * Survicate.submitAnswer({ surveyId: 'survey-1', pointId: 2, answerId: 3 }, responseUuid);
427
+ * ```
428
+ *
429
+ * @param surveyType - The survey type (WidgetSurvey or FeedbackButton) to get the response UUID for
430
+ * @param connectResponse - If true, returns existing response UUID from active survey, otherwise generates new UUID
431
+ * @returns Response UUID string
432
+ */
433
+ getResponseUuid: (surveyType: SurveyType, connectResponse?: boolean) => string;
434
+
356
435
  /**
357
436
  * Initialize the Survicate SDK with configuration
358
437
  *
@@ -465,6 +544,10 @@ declare const Survicate: {
465
544
  * without user interaction, useful for integrations or testing.
466
545
  *
467
546
  * @param params - Object containing survey, point, and answer information
547
+ * @param responseUuid - Optional response UUID to use for this answer submission.
548
+ * If provided and valid, reuses the existing response UUID, otherwise generates a new one.
549
+ * Useful when a survey is partially shown with some questions hidden, or when you want to
550
+ * connect all answers into a single record in the analysis tab.
468
551
  */
469
552
  submitAnswer: (params: {
470
553
  /** Survey ID */
@@ -472,10 +555,10 @@ declare const Survicate: {
472
555
  /** Question/point ID */
473
556
  pointId: number;
474
557
  /** Answer option ID (for single choice questions) */
475
- answerId: number;
558
+ answerId?: number;
476
559
  /** Answer value (for text or numeric questions) */
477
- answer: string | number;
478
- }) => void;
560
+ answer?: string | number;
561
+ }, responseUuid?: string) => void;
479
562
 
480
563
  /**
481
564
  * Get metadata about survey points (questions)