@sprig-technologies/sprig-browser 2.14.0 → 2.14.2

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.
@@ -533,13 +533,18 @@ const __enableUserLeapAPIActions = function(config) {
533
533
  return;
534
534
  }
535
535
 
536
- const identifyAndTrackHelper = async (payload) => {
536
+ const identifyAndTrackHelper = async (payload = {}) => {
537
537
  const { userId, anonymousId, metadata = {} } = payload;
538
538
  let { eventName } = payload;
539
539
  if (UserLeap.debugMode && eventName !== PAGE_URL_EVENT_NAME) console.log('[DEBUG] Sprig track', arguments);
540
540
  if (config.mode === 'test') {
541
541
  return;
542
542
  }
543
+ if (config.requireUserIdForTracking && !UserLeap.userId && !userId) {
544
+ const message = '[Sprig] - Skipping tracking without userId';
545
+ console.warn(message);
546
+ return { success: false, message, surveyState: SURVEY_STATE.NO_SURVEY };
547
+ }
543
548
  if (!eventName || eventName.trim().length === 0) {
544
549
  eventName = eventName ? String(eventName) : '';
545
550
  const message = `[Sprig] - Invalid event name ` + eventName;
@@ -629,6 +634,11 @@ const __enableUserLeapAPIActions = function(config) {
629
634
  async setAttributes(attributes) {
630
635
  if (UserLeap.debugMode) console.log('[DEBUG] Sprig setAttributes', arguments);
631
636
  if (config.mode === 'test') return;
637
+ if (config.requireUserIdForTracking && !UserLeap.userId) {
638
+ const message = '[Sprig] - Skipping tracking without userId';
639
+ console.warn(message);
640
+ return { success: false, message };
641
+ }
632
642
  if (attributes === null || attributes === undefined || Object.keys(attributes).length === 0) {
633
643
  const message = `[Sprig] - Disregarding empty attributes provided`;
634
644
  console.warn(message);
@@ -659,6 +669,12 @@ const __enableUserLeapAPIActions = function(config) {
659
669
  }
660
670
  const { userId, anonymousId, attributes } = payload;
661
671
 
672
+ if (config.requireUserIdForTracking && !UserLeap.userId && !userId) {
673
+ const message = '[Sprig] - Skipping tracking without userId';
674
+ console.warn(message);
675
+ return { success: false, message };
676
+ }
677
+
662
678
  if (
663
679
  // no attributes to set, and the provided userId and/or anonymousId are already set locally; nothing to do.
664
680
  !attributes &&
@@ -711,6 +727,11 @@ const __enableUserLeapAPIActions = function(config) {
711
727
  console.warn(message);
712
728
  return { success: false, message };
713
729
  }
730
+ if (config.requireUserIdForTracking && !UserLeap.userId) {
731
+ const message = '[Sprig] - Skipping tracking without userId';
732
+ console.warn(message);
733
+ return { success: false, message };
734
+ }
714
735
  const result = await authenticatedFetch(apiUrl(1, [PATH_ENV, PATH_VISITOR], 'attributes'), {
715
736
  body: JSON.stringify({ delete: attributes }),
716
737
  method: 'DELETE',