@sprig-technologies/sprig-browser 2.14.0 → 2.14.4
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/controller/controller.d.ts +13 -0
- package/controller/controller.d.ts.map +1 -0
- package/controller/controller.js +56 -33
- package/controller/encodedViewJs.d.ts +2 -0
- package/controller/encodedViewJs.d.ts.map +1 -0
- package/controller/encodedViewJs.js +1 -1
- package/controller/iframe.d.ts +9 -0
- package/controller/iframe.d.ts.map +1 -0
- package/controller/queue.d.ts +18 -0
- package/controller/queue.d.ts.map +1 -0
- package/controller/queue.js +1 -2
- package/controller/recordingAPI/index.js +37 -1
- package/index.d.ts +127 -0
- package/index.d.ts.map +1 -0
- package/index.js +2 -1
- package/package.json +1 -1
- package/shared/conflicting_widgets/index.d.ts +5 -0
- package/shared/conflicting_widgets/index.d.ts.map +1 -0
- package/shared/conflicting_widgets/intercom.d.ts +3 -0
- package/shared/conflicting_widgets/intercom.d.ts.map +1 -0
- package/shared/constants.d.ts +47 -0
- package/shared/constants.d.ts.map +1 -0
- package/shared/constants.js +1 -0
- package/shared/deferred.d.ts +10 -0
- package/shared/deferred.d.ts.map +1 -0
- package/shared/eventEmitter.d.ts +10 -0
- package/shared/eventEmitter.d.ts.map +1 -0
- package/shared/network.d.ts +8 -0
- package/shared/network.d.ts.map +1 -0
- package/shared/network.js +1 -1
- package/shared/networkHelper.d.ts +5 -0
- package/shared/networkHelper.d.ts.map +1 -0
- package/shared/shouldDirectEmbed.d.ts +7 -0
- package/shared/shouldDirectEmbed.d.ts.map +1 -0
- package/shared/tool.d.ts +3 -0
- package/shared/tool.d.ts.map +1 -0
- package/shared/ulEvents.d.ts +33 -0
- package/shared/ulEvents.d.ts.map +1 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Initialize frame and bootstrap data
|
|
3
|
+
* @param {Object} config this is included in the compilation step (points to the default viewSDKURL)
|
|
4
|
+
* @param {String} config.envId Environment Id
|
|
5
|
+
* @param {String} config.path Frame script url
|
|
6
|
+
* @param {String} [config.border] Border color
|
|
7
|
+
*/
|
|
8
|
+
export default function sprigInitializer(config?: {
|
|
9
|
+
envId: string;
|
|
10
|
+
path: string;
|
|
11
|
+
border?: string;
|
|
12
|
+
}): void;
|
|
13
|
+
//# sourceMappingURL=controller.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../../sprig-browser/controller/controller.js"],"names":[],"mappings":"AA68BA;;;;;;GAMG;AACH;IAJ0B,KAAK;IACL,IAAI;IACH,MAAM;SAkFhC"}
|
package/controller/controller.js
CHANGED
|
@@ -7,7 +7,7 @@ import ConflictingWidgets from '../shared/conflicting_widgets';
|
|
|
7
7
|
import { APP_MODES, CSS_CONSTANTS } from '../shared/constants';
|
|
8
8
|
import { ulFetch, killNetworkRequests, getHttpHeaders } from '../shared/network';
|
|
9
9
|
import { createFrame, createContainer, removeContainerOnClose, removeContainer } from '../controller/iframe';
|
|
10
|
-
import './queue';
|
|
10
|
+
import { UserLeapQueue } from './queue';
|
|
11
11
|
import eventEmitter from '../shared/eventEmitter';
|
|
12
12
|
import { ulEvents, DISMISS_REASONS, SURVEY_STATE, internalEvents } from '../shared/ulEvents';
|
|
13
13
|
import { calculateFrameHeight, overrideStyles } from '../shared/tool';
|
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
MOBILE_PLATFORM_HEADERS,
|
|
21
21
|
INSTALLATION_METHOD,
|
|
22
22
|
} from '../shared/constants';
|
|
23
|
+
import { encodedViewJs } from './encodedViewJs';
|
|
23
24
|
|
|
24
25
|
const credentialsStorageKey = 'userleap.ids';
|
|
25
26
|
const pageViewsStorageKey = 'userleap.pageviews';
|
|
@@ -66,7 +67,7 @@ function shouldDisplaySurveyAfterDelay(triggeringEventId, trackStartUrl) {
|
|
|
66
67
|
function locationChangeHandler(event) {
|
|
67
68
|
const { pageUrlEvents, interactiveEvents, dismissOnPageChange, platform } = UserLeap._config;
|
|
68
69
|
if (platform && platform !== 'web') return; // we should clean this up during web sdk controller refactor along with the should direct embed
|
|
69
|
-
if (pageUrlEvents)
|
|
70
|
+
if (pageUrlEvents) trackPageView(window.location.href);
|
|
70
71
|
if (interactiveEvents) {
|
|
71
72
|
// need to remove old listeners bc current page may not be targeted
|
|
72
73
|
removeInteractiveEventListener();
|
|
@@ -117,7 +118,7 @@ function apiUrl(version, fillPaths, trailing) {
|
|
|
117
118
|
fillPaths.forEach((p) => {
|
|
118
119
|
components.push(p);
|
|
119
120
|
if (p === PATH_ENV) components.push(UserLeap.envId);
|
|
120
|
-
else if (p === PATH_VISITOR) components.push(
|
|
121
|
+
else if (p === PATH_VISITOR) components.push(widgetGetVID());
|
|
121
122
|
});
|
|
122
123
|
}
|
|
123
124
|
if (trailing) components.push(trailing);
|
|
@@ -209,13 +210,11 @@ function generateVisitorId() {
|
|
|
209
210
|
eventEmitter.emit(ulEvents.VISITOR_ID_UPDATED, { visitorId: UserLeap.visitorId });
|
|
210
211
|
}
|
|
211
212
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
UserLeap.widgetGetVID = function() {
|
|
213
|
+
function widgetGetVID() {
|
|
215
214
|
return window.previewMode ? 0 : UserLeap.visitorId;
|
|
216
|
-
}
|
|
215
|
+
}
|
|
217
216
|
|
|
218
|
-
|
|
217
|
+
function trackPageView(location) {
|
|
219
218
|
if (!UserLeap.localStorageAvailable) return;
|
|
220
219
|
if (location.endsWith('mock_snippet.html')) {
|
|
221
220
|
return;
|
|
@@ -283,7 +282,7 @@ UserLeap.trackPageView = function(location) {
|
|
|
283
282
|
console.warn(`[Sprig] (ERR-425) Failed to update page views in local storage`);
|
|
284
283
|
UserLeap.reportError('trackPageView', err);
|
|
285
284
|
}
|
|
286
|
-
}
|
|
285
|
+
}
|
|
287
286
|
|
|
288
287
|
function bindTrackingEvents() {
|
|
289
288
|
const historyRef = 'Backbone' in window && window.Backbone && Backbone.history ? Backbone.history : window.history;
|
|
@@ -308,8 +307,8 @@ function bindTrackingEvents() {
|
|
|
308
307
|
registerEventListeners();
|
|
309
308
|
}
|
|
310
309
|
|
|
311
|
-
|
|
312
|
-
const visitorId =
|
|
310
|
+
async function getQuestions(options, submitAnswers) {
|
|
311
|
+
const visitorId = widgetGetVID();
|
|
313
312
|
if (options && !submitAnswers) {
|
|
314
313
|
UserLeap._config.mode = APP_MODES.test;
|
|
315
314
|
}
|
|
@@ -322,10 +321,10 @@ UserLeap.getQuestions = async function(options, submitAnswers) {
|
|
|
322
321
|
return { success: false, surveyState: SURVEY_STATE.NO_SURVEY };
|
|
323
322
|
}
|
|
324
323
|
response.json.delay && (await delay(response.json.delay));
|
|
325
|
-
return
|
|
326
|
-
}
|
|
324
|
+
return displayQuestions(response.json);
|
|
325
|
+
}
|
|
327
326
|
|
|
328
|
-
|
|
327
|
+
function displayQuestions(responseJson) {
|
|
329
328
|
const { vid, uuid, questions, surveyId, context, locale, responseGroupUid, endCard, productConfig } = responseJson;
|
|
330
329
|
const experimentFlags = responseJson.experimentFlags || {};
|
|
331
330
|
const headers = getHttpHeaders(UserLeap);
|
|
@@ -435,8 +434,7 @@ UserLeap.displayQuestions = function(responseJson) {
|
|
|
435
434
|
}
|
|
436
435
|
|
|
437
436
|
if (config.installationMethod === INSTALLATION_METHOD.NPM) {
|
|
438
|
-
|
|
439
|
-
frameScript.textContent = atob(encodedViewJs.default);
|
|
437
|
+
frameScript.textContent = atob(encodedViewJs);
|
|
440
438
|
} else {
|
|
441
439
|
frameScript.src = frameSrc;
|
|
442
440
|
contentWindow.addEventListener(
|
|
@@ -454,7 +452,7 @@ UserLeap.displayQuestions = function(responseJson) {
|
|
|
454
452
|
}
|
|
455
453
|
contentWinDocHead.appendChild(frameScript);
|
|
456
454
|
return { success: true, surveyState: SURVEY_STATE.READY };
|
|
457
|
-
}
|
|
455
|
+
}
|
|
458
456
|
|
|
459
457
|
function calculateUseMobileStyling(headers) {
|
|
460
458
|
if (UserLeap.useMobileStyling !== undefined) return UserLeap.useMobileStyling;
|
|
@@ -486,9 +484,10 @@ function shuffleInteractiveEvents(events) {
|
|
|
486
484
|
* Gather identifier data, retrieve questions, and render widget
|
|
487
485
|
* @param {Object} config [description]
|
|
488
486
|
*/
|
|
489
|
-
|
|
487
|
+
function widgetInitialize(config) {
|
|
490
488
|
if (!config) return;
|
|
491
489
|
UserLeap._config = config;
|
|
490
|
+
|
|
492
491
|
if (config.mute) {
|
|
493
492
|
// Userleap.mute isn't defined yet
|
|
494
493
|
UserLeap._queue.pause();
|
|
@@ -501,7 +500,7 @@ UserLeap.widgetInitialize = function(config) {
|
|
|
501
500
|
bindTrackingEvents();
|
|
502
501
|
locationChangeHandler();
|
|
503
502
|
}
|
|
504
|
-
}
|
|
503
|
+
}
|
|
505
504
|
|
|
506
505
|
async function authenticatedFetch(url, options, attempt = 0, shouldDropOnRateLimit = false) {
|
|
507
506
|
options.headers = Object.assign(getHttpHeaders(UserLeap), options.headers);
|
|
@@ -533,13 +532,18 @@ const __enableUserLeapAPIActions = function(config) {
|
|
|
533
532
|
return;
|
|
534
533
|
}
|
|
535
534
|
|
|
536
|
-
const identifyAndTrackHelper = async (payload) => {
|
|
535
|
+
const identifyAndTrackHelper = async (payload = {}) => {
|
|
537
536
|
const { userId, anonymousId, metadata = {} } = payload;
|
|
538
537
|
let { eventName } = payload;
|
|
539
538
|
if (UserLeap.debugMode && eventName !== PAGE_URL_EVENT_NAME) console.log('[DEBUG] Sprig track', arguments);
|
|
540
539
|
if (config.mode === 'test') {
|
|
541
540
|
return;
|
|
542
541
|
}
|
|
542
|
+
if (config.requireUserIdForTracking && !UserLeap.userId && !userId) {
|
|
543
|
+
const message = '[Sprig] - Skipping tracking without userId';
|
|
544
|
+
console.warn(message);
|
|
545
|
+
return { success: false, message, surveyState: SURVEY_STATE.NO_SURVEY };
|
|
546
|
+
}
|
|
543
547
|
if (!eventName || eventName.trim().length === 0) {
|
|
544
548
|
eventName = eventName ? String(eventName) : '';
|
|
545
549
|
const message = `[Sprig] - Invalid event name ` + eventName;
|
|
@@ -583,7 +587,7 @@ const __enableUserLeapAPIActions = function(config) {
|
|
|
583
587
|
const responseBody = result.json;
|
|
584
588
|
responseBody.delay && (await delay(responseBody.delay));
|
|
585
589
|
if (shouldDisplaySurveyAfterDelay(responseBody.eventId, trackStartUrl)) {
|
|
586
|
-
return
|
|
590
|
+
return displayQuestions(responseBody);
|
|
587
591
|
} else {
|
|
588
592
|
return {
|
|
589
593
|
success: false,
|
|
@@ -597,17 +601,17 @@ const __enableUserLeapAPIActions = function(config) {
|
|
|
597
601
|
// Triggers displaying specified survey. Does submit answers!
|
|
598
602
|
async displaySurvey(surveyId) {
|
|
599
603
|
UserLeap('dismissActiveSurvey', DISMISS_REASONS.OVERRIDE);
|
|
600
|
-
return
|
|
604
|
+
return getQuestions({ surveyId }, true);
|
|
601
605
|
},
|
|
602
606
|
// Triggers displaying specified survey template. Does not submit answers
|
|
603
607
|
previewSurvey(surveyTemplateId) {
|
|
604
608
|
UserLeap('dismissActiveSurvey', DISMISS_REASONS.OVERRIDE);
|
|
605
|
-
|
|
609
|
+
getQuestions({ surveyTemplateId }, false);
|
|
606
610
|
},
|
|
607
611
|
// Triggers displaying specified survey. Does not submit answers
|
|
608
612
|
reviewSurvey(surveyId) {
|
|
609
613
|
UserLeap('dismissActiveSurvey', DISMISS_REASONS.OVERRIDE);
|
|
610
|
-
|
|
614
|
+
getQuestions({ surveyId }, false);
|
|
611
615
|
},
|
|
612
616
|
mute() {
|
|
613
617
|
UserLeap._queue.pause();
|
|
@@ -629,6 +633,11 @@ const __enableUserLeapAPIActions = function(config) {
|
|
|
629
633
|
async setAttributes(attributes) {
|
|
630
634
|
if (UserLeap.debugMode) console.log('[DEBUG] Sprig setAttributes', arguments);
|
|
631
635
|
if (config.mode === 'test') return;
|
|
636
|
+
if (config.requireUserIdForTracking && !UserLeap.userId) {
|
|
637
|
+
const message = '[Sprig] - Skipping tracking without userId';
|
|
638
|
+
console.warn(message);
|
|
639
|
+
return { success: false, message };
|
|
640
|
+
}
|
|
632
641
|
if (attributes === null || attributes === undefined || Object.keys(attributes).length === 0) {
|
|
633
642
|
const message = `[Sprig] - Disregarding empty attributes provided`;
|
|
634
643
|
console.warn(message);
|
|
@@ -659,6 +668,12 @@ const __enableUserLeapAPIActions = function(config) {
|
|
|
659
668
|
}
|
|
660
669
|
const { userId, anonymousId, attributes } = payload;
|
|
661
670
|
|
|
671
|
+
if (config.requireUserIdForTracking && !UserLeap.userId && !userId) {
|
|
672
|
+
const message = '[Sprig] - Skipping tracking without userId';
|
|
673
|
+
console.warn(message);
|
|
674
|
+
return { success: false, message };
|
|
675
|
+
}
|
|
676
|
+
|
|
662
677
|
if (
|
|
663
678
|
// no attributes to set, and the provided userId and/or anonymousId are already set locally; nothing to do.
|
|
664
679
|
!attributes &&
|
|
@@ -711,6 +726,11 @@ const __enableUserLeapAPIActions = function(config) {
|
|
|
711
726
|
console.warn(message);
|
|
712
727
|
return { success: false, message };
|
|
713
728
|
}
|
|
729
|
+
if (config.requireUserIdForTracking && !UserLeap.userId) {
|
|
730
|
+
const message = '[Sprig] - Skipping tracking without userId';
|
|
731
|
+
console.warn(message);
|
|
732
|
+
return { success: false, message };
|
|
733
|
+
}
|
|
714
734
|
const result = await authenticatedFetch(apiUrl(1, [PATH_ENV, PATH_VISITOR], 'attributes'), {
|
|
715
735
|
body: JSON.stringify({ delete: attributes }),
|
|
716
736
|
method: 'DELETE',
|
|
@@ -864,7 +884,7 @@ const __enableUserLeapAPIActions = function(config) {
|
|
|
864
884
|
* Pulls down presentation config settings from server and
|
|
865
885
|
* applies them to supplied config dict
|
|
866
886
|
*/
|
|
867
|
-
|
|
887
|
+
async function applyRemoteConfig(config) {
|
|
868
888
|
const headers = UserLeap.mobileHeadersJSON ? JSON.parse(UserLeap.mobileHeadersJSON) : {};
|
|
869
889
|
let response = await ulFetch(apiUrl(1, [PATH_ENV], 'config'), { headers });
|
|
870
890
|
|
|
@@ -893,10 +913,10 @@ UserLeap.applyRemoteConfig = async function(config) {
|
|
|
893
913
|
return newConfig;
|
|
894
914
|
};
|
|
895
915
|
|
|
896
|
-
|
|
916
|
+
async function reportError(action, err) {
|
|
897
917
|
const mode = window.__cfg && window.__cfg.mode;
|
|
898
918
|
const fetchFreshIfNotSet = false;
|
|
899
|
-
const vid =
|
|
919
|
+
const vid = widgetGetVID(fetchFreshIfNotSet);
|
|
900
920
|
const envId = UserLeap.envId;
|
|
901
921
|
const pde = window.document.documentElement;
|
|
902
922
|
const meta = {
|
|
@@ -928,9 +948,9 @@ UserLeap.reportError = async function(action, err) {
|
|
|
928
948
|
if (!result.ok) {
|
|
929
949
|
console.warn(`[Sprig] (ERR-444) Failed to report error to API`, err);
|
|
930
950
|
}
|
|
931
|
-
}
|
|
951
|
+
}
|
|
932
952
|
|
|
933
|
-
|
|
953
|
+
function logoutUser() {
|
|
934
954
|
if (UserLeap.debugMode) console.log('[DEBUG] Sprig logout');
|
|
935
955
|
//clear in-memory
|
|
936
956
|
UserLeap.visitorId = null;
|
|
@@ -949,7 +969,7 @@ UserLeap.logoutUser = function() {
|
|
|
949
969
|
if (UserLeap._queue.isPaused()) UserLeap._queue.empty();
|
|
950
970
|
generateVisitorId();
|
|
951
971
|
UserLeap._queue.unpause();
|
|
952
|
-
}
|
|
972
|
+
}
|
|
953
973
|
|
|
954
974
|
/**
|
|
955
975
|
* Initialize frame and bootstrap data
|
|
@@ -961,6 +981,9 @@ UserLeap.logoutUser = function() {
|
|
|
961
981
|
export default function sprigInitializer(config = {}) {
|
|
962
982
|
async function load() {
|
|
963
983
|
if (UserLeap.loaded) return;
|
|
984
|
+
UserLeap.UPDATES = ulEvents;
|
|
985
|
+
UserLeap.reportError = reportError;
|
|
986
|
+
UserLeap.logoutUser = logoutUser;
|
|
964
987
|
UserLeap.loaded = true;
|
|
965
988
|
//combine compile-provided config and installation-snippet config
|
|
966
989
|
UserLeap._config = Object.assign({}, config, UserLeap.config);
|
|
@@ -1005,7 +1028,7 @@ export default function sprigInitializer(config = {}) {
|
|
|
1005
1028
|
//Note: UserLeap._queue is an array at this point (defined in installation snippet)
|
|
1006
1029
|
const queueItems = [...UserLeap._queue];
|
|
1007
1030
|
//converts [] -> Queue()
|
|
1008
|
-
UserLeap._queue = new
|
|
1031
|
+
UserLeap._queue = new UserLeapQueue(UserLeap, []);
|
|
1009
1032
|
UserLeap._queue.pause();
|
|
1010
1033
|
for (let i = 0; i < queueItems.length; i++) {
|
|
1011
1034
|
UserLeap._queue.push(queueItems[i]);
|
|
@@ -1021,9 +1044,9 @@ export default function sprigInitializer(config = {}) {
|
|
|
1021
1044
|
if (UserLeap.localStorageAvailable) localStorage.removeItem(credentialsStorageKey);
|
|
1022
1045
|
generateVisitorId();
|
|
1023
1046
|
}
|
|
1024
|
-
const remoteConfig = await
|
|
1047
|
+
const remoteConfig = await applyRemoteConfig(config);
|
|
1025
1048
|
__enableUserLeapAPIActions(remoteConfig);
|
|
1026
|
-
await
|
|
1049
|
+
await widgetInitialize(remoteConfig);
|
|
1027
1050
|
UserLeap._queue.unpause();
|
|
1028
1051
|
eventEmitter.emit(ulEvents.SDK_READY);
|
|
1029
1052
|
eventEmitter.emit(ulEvents.VISITOR_ID_UPDATED, { visitorId: UserLeap.visitorId });
|