Skip to content

Commit 7e89799

Browse files
committed
Extra check for intercom widget load. (#1302)
* Extra check for intercom widget load * Use error param
1 parent 649ab52 commit 7e89799

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

src/app/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
https://nexus-long-poller-b.intercom.io
2626
wss://nexus-websocket-a.intercom.io
2727
wss://nexus-websocket-b.intercom.io
28+
https://widget.intercom.io
29+
https://js.intercomcdn.com
2830
https://uploads.intercomcdn.com
2931
https://uploads.intercomusercontent.com
3032
https://app.getsentry.com
@@ -39,7 +41,6 @@
3941
https://app.intercom.io
4042
https://widget.intercom.io
4143
https://js.intercomcdn.com
42-
https://js.intercomcdn.com
4344
'unsafe-eval';
4445
font-src * https://js.intercomcdn.com;">
4546
</head>

src/internal-plugins/metrics/lib/setup.js

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ const INTERCOM_KEY = 'p57suhg7';
1818
const BUGSNAG_KEY = '0d11ab5f4d97452cc83d3365c21b491c';
1919

2020
module.exports = function() {
21+
let intercomBlocked = false;
22+
2123
metrics.configure({
2224
stitch: {
2325
appId: 'compass-metrics-irinb',
@@ -36,13 +38,32 @@ module.exports = function() {
3638
});
3739

3840
if (process.env.HADRON_PRODUCT !== 'mongodb-compass-community') {
39-
metrics.configure({
40-
intercom: {
41-
appId: INTERCOM_KEY,
42-
enabled: app.preferences.trackUsageStatistics,
43-
panelEnabled: app.preferences.enableFeedbackPanel
41+
const request = new XMLHttpRequest();
42+
request.onreadystatechange = () => {
43+
try {
44+
if (request.readyState === XMLHttpRequest.DONE) {
45+
if (request.status < 400) {
46+
metrics.configure({
47+
intercom: {
48+
appId: INTERCOM_KEY,
49+
enabled: app.preferences.trackUsageStatistics,
50+
panelEnabled: app.preferences.enableFeedbackPanel
51+
}
52+
});
53+
} else {
54+
intercomBlocked = true;
55+
}
56+
}
57+
} catch (e) {
58+
intercomBlocked = true;
4459
}
45-
});
60+
};
61+
try {
62+
request.open('GET', format('https://widget.intercom.io/widget/%s', INTERCOM_KEY), true);
63+
request.send();
64+
} catch (e) {
65+
intercomBlocked = true;
66+
}
4667
}
4768

4869
// create an app resource with name and version
@@ -142,7 +163,7 @@ module.exports = function() {
142163
* such that when a link is clicked, the event is properly
143164
* passed off to `app.router` and a web page actually opens.
144165
*/
145-
if (process.env.HADRON_PRODUCT !== 'mongodb-compass-community') {
166+
if (process.env.HADRON_PRODUCT !== 'mongodb-compass-community' && !intercomBlocked) {
146167
intercom.configure();
147168
}
148169

0 commit comments

Comments
 (0)