forked from bombastictranz/demo-editor
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
integrations
80 lines (75 loc) · 2.6 KB
/
integrations
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
(function(FS) {
var session = FS.getCurrentSession(), sessionUrl = FS.getCurrentSessionURL();
function retryWithBackoff(condition, callback, maxWait, failureMsg, timeoutCallback) {
var totalTimeExpired = 0;
var wait = 64;
var resultFn = function() {
if (condition()) {
callback();
return;
}
wait = Math.min(wait * 2, 1024);
if (totalTimeExpired > maxWait) {
FS.log('warn', failureMsg);
!!timeoutCallback && timeoutCallback(failureMsg);
return;
}
totalTimeExpired += wait
setTimeout(resultFn, wait);
};
return resultFn;
}
function loadSession(key) {
var lastSession = window['localStorage'].getItem(key);
if (!lastSession) {
lastSession = FS._cookies()[key];
}
return lastSession
}
function saveSession(key, session) {
window['localStorage'].setItem(key, session);
}
var intercomSessionUrl = sessionUrl + '?integration_src=intercom';
function intercomOnPage() {
return window['Intercom'] && typeof(Intercom)=="function";
}
function intercomBooted() {
return document.querySelector(".intercom-app, .intercom-lightweight-app");
}
function fsIntercomInit() {
var lastSession = loadSession('fs_intercom');
if (session != lastSession) {
saveSession('fs_intercom', session);
var fsMetadata = {
"Session Link": {
value: "Play in FullStory",
url: intercomSessionUrl
},
"Session Time": (new Date()).toUTCString()
};
Intercom('trackEvent', 'New FullStory Session', fsMetadata);
retryWithBackoff(intercomBooted, intercomUpdateAttrAsync, 8000, 'The FullStory integration with Intercom loaded, but did not detect that Intercom booted successfully.', intercomInitFailure)();
}
}
retryWithBackoff(intercomOnPage, fsIntercomInit, 30000, 'The FullStory integration with Intercom loaded, but did not detect Intercom on the page.', intercomInitFailure)();
function intercomUpdateAttrAsync() {
Intercom('update', {'Latest FullStory Session': intercomSessionUrl});
FS('stat', {
eventType: 'INTEGRATION_INITIALIZED',
payload: {
provider_id: 'intercom',
event_status: 'SUCCESS'
}
});
}
function intercomInitFailure(message) {
FS('stat', {
eventType: 'INTEGRATION_INITIALIZED',
payload: {
provider_id: 'intercom',
event_status: 'FAILURE',
metadata: { detail: message }
}
});
}
})(window['_fs_namespace'] ? window[window['_fs_namespace']] : window['FS'])