Skip to content

Commit bb29b5e

Browse files
committed
Adding optional prop for lazy load the intercom script
Fixing timeout prop
1 parent 743e8e9 commit bb29b5e

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/initialize.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* @see {@link https://developers.intercom.com/installing-intercom/docs/basic-javascript}
88
*/
9-
const initialize = (appId: string) => {
9+
const initialize = (appId: string, timeout = 0) => {
1010
var w = window;
1111
var ic = w.Intercom;
1212
if (typeof ic === 'function') {
@@ -23,12 +23,14 @@ const initialize = (appId: string) => {
2323
};
2424
w.Intercom = i;
2525
var l = function() {
26-
var s = d.createElement('script');
27-
s.type = 'text/javascript';
28-
s.async = true;
29-
s.src = 'https://widget.intercom.io/widget/' + appId;
30-
var x = d.getElementsByTagName('script')[0];
31-
x.parentNode.insertBefore(s, x);
26+
setTimeout(function () {
27+
var s = d.createElement('script');
28+
s.type = 'text/javascript';
29+
s.async = true;
30+
s.src = 'https://widget.intercom.io/widget/' + appId;
31+
var x = d.getElementsByTagName('script')[0];
32+
x.parentNode.insertBefore(s, x);
33+
}, timeout)
3234
};
3335
if (document.readyState === 'complete') {
3436
l();

0 commit comments

Comments
 (0)