react-use-intercom
Advanced tools
Comparing version 1.1.9 to 1.2.0
@@ -5,6 +5,7 @@ /** | ||
* @param appId - Intercom app id | ||
* @param [timeout=0] - Amount of milliseconds that the initialization should be delayed, defaults to 0 | ||
* | ||
* @see {@link https://developers.intercom.com/installing-intercom/docs/basic-javascript} | ||
*/ | ||
declare const initialize: (appId: string) => void; | ||
declare const initialize: (appId: string, timeout?: number) => void; | ||
export default initialize; |
@@ -151,6 +151,11 @@ 'use strict'; | ||
* @param appId - Intercom app id | ||
* @param [timeout=0] - Amount of milliseconds that the initialization should be delayed, defaults to 0 | ||
* | ||
* @see {@link https://developers.intercom.com/installing-intercom/docs/basic-javascript} | ||
*/ | ||
var initialize = function initialize(appId) { | ||
var initialize = function initialize(appId, timeout) { | ||
if (timeout === void 0) { | ||
timeout = 0; | ||
} | ||
var w = window; | ||
@@ -178,8 +183,10 @@ var ic = w.Intercom; | ||
var l = function l() { | ||
var s = d.createElement('script'); | ||
s.type = 'text/javascript'; | ||
s.async = true; | ||
s.src = 'https://widget.intercom.io/widget/' + appId; | ||
var x = d.getElementsByTagName('script')[0]; | ||
x.parentNode.insertBefore(s, x); | ||
setTimeout(function () { | ||
var s = d.createElement('script'); | ||
s.type = 'text/javascript'; | ||
s.async = true; | ||
s.src = 'https://widget.intercom.io/widget/' + appId; | ||
var x = d.getElementsByTagName('script')[0]; | ||
x.parentNode.insertBefore(s, x); | ||
}, timeout); | ||
}; | ||
@@ -269,12 +276,10 @@ | ||
apiBase = _ref.apiBase, | ||
rest = _objectWithoutPropertiesLoose(_ref, ["appId", "autoBoot", "children", "onHide", "onShow", "onUnreadCountChange", "shouldInitialize", "apiBase"]); | ||
initializeDelay = _ref.initializeDelay, | ||
rest = _objectWithoutPropertiesLoose(_ref, ["appId", "autoBoot", "children", "onHide", "onShow", "onUnreadCountChange", "shouldInitialize", "apiBase", "initializeDelay"]); | ||
var isBooted = React.useRef(autoBoot); | ||
if (!isEmptyObject(rest) && "development" !== "production") log('error', ['some invalid props were passed to IntercomProvider. ', "Please check following props: " + Object.keys(rest).join(', ') + "."].join('')); | ||
var memoizedAppId = React.useRef(appId); | ||
var memoizedApiBase = React.useRef(apiBase); | ||
var isBooted = React.useRef(autoBoot); | ||
var memoizedShouldInitialize = React.useRef(shouldInitialize); | ||
if (!isSSR && !window.Intercom && memoizedShouldInitialize.current) { | ||
initialize(memoizedAppId.current); // Only add listeners on initialization | ||
if (!isSSR && !window.Intercom && shouldInitialize) { | ||
initialize(appId, initializeDelay); // Only add listeners on initialization | ||
@@ -287,10 +292,10 @@ if (onHide) IntercomAPI('onHide', onHide); | ||
IntercomAPI('boot', _extends({ | ||
app_id: memoizedAppId.current | ||
}, memoizedApiBase.current && { | ||
api_base: memoizedApiBase.current | ||
app_id: appId | ||
}, apiBase && { | ||
api_base: apiBase | ||
})); | ||
window.intercomSettings = _extends({ | ||
app_id: memoizedAppId.current | ||
}, memoizedApiBase.current && { | ||
api_base: memoizedApiBase.current | ||
app_id: appId | ||
}, apiBase && { | ||
api_base: apiBase | ||
}); | ||
@@ -305,3 +310,3 @@ } | ||
if (!window.Intercom && !memoizedShouldInitialize.current) { | ||
if (!window.Intercom && !shouldInitialize) { | ||
log('warn', 'Intercom instance is not initialized because `shouldInitialize` is set to `false` in `IntercomProvider`'); | ||
@@ -317,5 +322,5 @@ return; | ||
return callback(); | ||
}, []); | ||
}, [shouldInitialize]); | ||
var boot = React.useCallback(function (props) { | ||
if (!window.Intercom && !memoizedShouldInitialize.current) { | ||
if (!window.Intercom && !shouldInitialize) { | ||
log('warn', 'Intercom instance is not initialized because `shouldInitialize` is set to `false` in `IntercomProvider`'); | ||
@@ -328,5 +333,5 @@ return; | ||
var metaData = _extends({ | ||
app_id: memoizedAppId.current | ||
}, memoizedApiBase.current && { | ||
api_base: memoizedApiBase.current | ||
app_id: appId | ||
}, apiBase && { | ||
api_base: apiBase | ||
}, props && mapIntercomPropsToRawIntercomProps(props)); | ||
@@ -337,3 +342,3 @@ | ||
isBooted.current = true; | ||
}, []); | ||
}, [apiBase, appId, shouldInitialize]); | ||
var shutdown = React.useCallback(function () { | ||
@@ -340,0 +345,0 @@ if (!isBooted.current) return; |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react");function t(){return(t=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}var n="undefined"==typeof window,r=function(e){if(!n&&window.Intercom){for(var t=arguments.length,r=new Array(t>1?t-1:0),o=1;o<t;o++)r[o-1]=arguments[o];return window.Intercom.apply(null,[e].concat(r))}},o=e.createContext({boot:function(){},shutdown:function(){},hardShutdown:function(){},update:function(){},hide:function(){},show:function(){},showMessages:function(){},showNewMessages:function(){},getVisitorId:function(){return""},startTour:function(){},trackEvent:function(){}}),a=function(e){return t({company_id:e.companyId,name:e.name,created_at:e.createdAt,plan:e.plan,monthly_spend:e.monthlySpend,user_count:e.userCount,size:e.size,website:e.website,industry:e.industry},e.customAttributes)},u=function(e){return{type:e.type,image_url:e.imageUrl}},i=function(e){return function e(t){return Object.keys(t).forEach((function(n){t[n]&&"object"==typeof t[n]?e(t[n]):void 0===t[n]&&delete t[n]})),t}(t({},{custom_launcher_selector:(n=e).customLauncherSelector,alignment:n.alignment,vertical_padding:n.verticalPadding,horizontal_padding:n.horizontalPadding,hide_default_launcher:n.hideDefaultLauncher,session_duration:n.sessionDuration,action_color:n.actionColor,background_color:n.backgroundColor},function(e){var n;return t({email:e.email,user_id:e.userId,created_at:e.createdAt,name:e.name,phone:e.phone,last_request_at:e.lastRequestAt,unsubscribed_from_emails:e.unsubscribedFromEmails,language_override:e.languageOverride,utm_campaign:e.utmCampaign,utm_content:e.utmContent,utm_medium:e.utmMedium,utm_source:e.utmSource,utm_term:e.utmTerm,avatar:e.avatar&&u(e.avatar),user_hash:e.userHash,company:e.company&&a(e.company),companies:null==(n=e.companies)?void 0:n.map(a)},e.customAttributes)}(e)));var n};exports.IntercomProvider=function(a){var u=a.appId,c=a.autoBoot,s=void 0!==c&&c,d=a.children,l=a.onHide,f=a.onShow,m=a.onUnreadCountChange,p=a.shouldInitialize,h=void 0===p?!n:p,w=a.apiBase,g=function(e,t){if(null==e)return{};var n,r,o={},a=Object.keys(e);for(r=0;r<a.length;r++)t.indexOf(n=a[r])>=0||(o[n]=e[n]);return o}(a,["appId","autoBoot","children","onHide","onShow","onUnreadCountChange","shouldInitialize","apiBase"]);Object.keys(g);var v=e.useRef(u),_=e.useRef(w),b=e.useRef(s),y=e.useRef(h);n||window.Intercom||!y.current||(function(e){var t=window,n=t.Intercom;if("function"==typeof n)n("reattach_activator"),n("update",t.intercomSettings);else{var r=document,o=function e(){e.c(arguments)};o.q=[],o.c=function(e){o.q.push(e)},t.Intercom=o;var a=function(){var t=r.createElement("script");t.type="text/javascript",t.async=!0,t.src="https://widget.intercom.io/widget/"+e;var n=r.getElementsByTagName("script")[0];n.parentNode.insertBefore(t,n)};"complete"===document.readyState?a():t.attachEvent?t.attachEvent("onload",a):t.addEventListener("load",a,!1)}}(v.current),l&&r("onHide",l),f&&r("onShow",f),m&&r("onUnreadCountChange",m),s&&(r("boot",t({app_id:v.current},_.current&&{api_base:_.current})),window.intercomSettings=t({app_id:v.current},_.current&&{api_base:_.current})));var C=e.useCallback((function(e,t){if((window.Intercom||y.current)&&b.current)return t()}),[]),k=e.useCallback((function(e){if((window.Intercom||y.current)&&!b.current){var n=t({app_id:v.current},_.current&&{api_base:_.current},e&&i(e));window.intercomSettings=n,r("boot",n),b.current=!0}}),[]),I=e.useCallback((function(){b.current&&(r("shutdown"),b.current=!1)}),[]),S=e.useCallback((function(){b.current&&(r("shutdown"),delete window.Intercom,delete window.intercomSettings,b.current=!1)}),[]),E=e.useCallback((function(){C("update",(function(){var e=(new Date).getTime();r("update",{last_requested_at:e})}))}),[C]),M=e.useCallback((function(e){C("update",(function(){if(e){var n=i(e);window.intercomSettings=t({},window.intercomSettings,n),r("update",n)}else E()}))}),[C,E]),O=e.useCallback((function(){C("hide",(function(){r("hide")}))}),[C]),j=e.useCallback((function(){C("show",(function(){return r("show")}))}),[C]),x=e.useCallback((function(){C("showMessages",(function(){r("showMessages")}))}),[C]),N=e.useCallback((function(e){C("showNewMessage",(function(){e?r("showNewMessage",e):r("showNewMessage")}))}),[C]),T=e.useCallback((function(){return C("getVisitorId",(function(){return r("getVisitorId")}))}),[C]),q=e.useCallback((function(e){C("startTour",(function(){r("startTour",e)}))}),[C]),z=e.useCallback((function(e,t){C("trackEvent",(function(){t?r("trackEvent",e,t):r("trackEvent",e)}))}),[C]),A=e.useMemo((function(){return{boot:k,shutdown:I,hardShutdown:S,update:M,hide:O,show:j,showMessages:x,showNewMessages:N,getVisitorId:T,startTour:q,trackEvent:z}}),[k,I,S,M,O,j,x,N,T,q,z]),B=e.useMemo((function(){return d}),[d]);return e.createElement(o.Provider,{value:A},B)},exports.useIntercom=function(){return e.useContext(o)}; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react");function t(){return(t=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e}).apply(this,arguments)}var n="undefined"==typeof window,o=function(e){if(!n&&window.Intercom){for(var t=arguments.length,o=new Array(t>1?t-1:0),a=1;a<t;a++)o[a-1]=arguments[a];return window.Intercom.apply(null,[e].concat(o))}},a=e.createContext({boot:function(){},shutdown:function(){},hardShutdown:function(){},update:function(){},hide:function(){},show:function(){},showMessages:function(){},showNewMessages:function(){},getVisitorId:function(){return""},startTour:function(){},trackEvent:function(){}}),r=function(e){return t({company_id:e.companyId,name:e.name,created_at:e.createdAt,plan:e.plan,monthly_spend:e.monthlySpend,user_count:e.userCount,size:e.size,website:e.website,industry:e.industry},e.customAttributes)},i=function(e){return{type:e.type,image_url:e.imageUrl}},u=function(e){return function e(t){return Object.keys(t).forEach((function(n){t[n]&&"object"==typeof t[n]?e(t[n]):void 0===t[n]&&delete t[n]})),t}(t({},{custom_launcher_selector:(n=e).customLauncherSelector,alignment:n.alignment,vertical_padding:n.verticalPadding,horizontal_padding:n.horizontalPadding,hide_default_launcher:n.hideDefaultLauncher,session_duration:n.sessionDuration,action_color:n.actionColor,background_color:n.backgroundColor},function(e){var n;return t({email:e.email,user_id:e.userId,created_at:e.createdAt,name:e.name,phone:e.phone,last_request_at:e.lastRequestAt,unsubscribed_from_emails:e.unsubscribedFromEmails,language_override:e.languageOverride,utm_campaign:e.utmCampaign,utm_content:e.utmContent,utm_medium:e.utmMedium,utm_source:e.utmSource,utm_term:e.utmTerm,avatar:e.avatar&&i(e.avatar),user_hash:e.userHash,company:e.company&&r(e.company),companies:null==(n=e.companies)?void 0:n.map(r)},e.customAttributes)}(e)));var n};exports.IntercomProvider=function(r){var i=r.appId,c=r.autoBoot,s=void 0!==c&&c,d=r.children,l=r.onHide,f=r.onShow,m=r.onUnreadCountChange,p=r.shouldInitialize,h=void 0===p?!n:p,w=r.apiBase,g=r.initializeDelay,v=function(e,t){if(null==e)return{};var n,o,a={},r=Object.keys(e);for(o=0;o<r.length;o++)t.indexOf(n=r[o])>=0||(a[n]=e[n]);return a}(r,["appId","autoBoot","children","onHide","onShow","onUnreadCountChange","shouldInitialize","apiBase","initializeDelay"]),_=e.useRef(s);Object.keys(v),n||window.Intercom||!h||(function(e,t){void 0===t&&(t=0);var n=window,o=n.Intercom;if("function"==typeof o)o("reattach_activator"),o("update",n.intercomSettings);else{var a=document,r=function e(){e.c(arguments)};r.q=[],r.c=function(e){r.q.push(e)},n.Intercom=r;var i=function(){setTimeout((function(){var t=a.createElement("script");t.type="text/javascript",t.async=!0,t.src="https://widget.intercom.io/widget/"+e;var n=a.getElementsByTagName("script")[0];n.parentNode.insertBefore(t,n)}),t)};"complete"===document.readyState?i():n.attachEvent?n.attachEvent("onload",i):n.addEventListener("load",i,!1)}}(i,g),l&&o("onHide",l),f&&o("onShow",f),m&&o("onUnreadCountChange",m),s&&(o("boot",t({app_id:i},w&&{api_base:w})),window.intercomSettings=t({app_id:i},w&&{api_base:w})));var b=e.useCallback((function(e,t){if((window.Intercom||h)&&_.current)return t()}),[h]),y=e.useCallback((function(e){if((window.Intercom||h)&&!_.current){var n=t({app_id:i},w&&{api_base:w},e&&u(e));window.intercomSettings=n,o("boot",n),_.current=!0}}),[w,i,h]),C=e.useCallback((function(){_.current&&(o("shutdown"),_.current=!1)}),[]),k=e.useCallback((function(){_.current&&(o("shutdown"),delete window.Intercom,delete window.intercomSettings,_.current=!1)}),[]),I=e.useCallback((function(){b("update",(function(){var e=(new Date).getTime();o("update",{last_requested_at:e})}))}),[b]),S=e.useCallback((function(e){b("update",(function(){if(e){var n=u(e);window.intercomSettings=t({},window.intercomSettings,n),o("update",n)}else I()}))}),[b,I]),E=e.useCallback((function(){b("hide",(function(){o("hide")}))}),[b]),M=e.useCallback((function(){b("show",(function(){return o("show")}))}),[b]),O=e.useCallback((function(){b("showMessages",(function(){o("showMessages")}))}),[b]),j=e.useCallback((function(e){b("showNewMessage",(function(){e?o("showNewMessage",e):o("showNewMessage")}))}),[b]),z=e.useCallback((function(){return b("getVisitorId",(function(){return o("getVisitorId")}))}),[b]),T=e.useCallback((function(e){b("startTour",(function(){o("startTour",e)}))}),[b]),x=e.useCallback((function(e,t){b("trackEvent",(function(){t?o("trackEvent",e,t):o("trackEvent",e)}))}),[b]),N=e.useMemo((function(){return{boot:y,shutdown:C,hardShutdown:k,update:S,hide:E,show:M,showMessages:O,showNewMessages:j,getVisitorId:z,startTour:T,trackEvent:x}}),[y,C,k,S,E,M,O,j,z,T,x]),q=e.useMemo((function(){return d}),[d]);return e.createElement(a.Provider,{value:N},q)},exports.useIntercom=function(){return e.useContext(a)}; | ||
//# sourceMappingURL=react-use-intercom.cjs.production.min.js.map |
@@ -147,6 +147,11 @@ import { createContext, useRef, useCallback, useMemo, createElement, useContext } from 'react'; | ||
* @param appId - Intercom app id | ||
* @param [timeout=0] - Amount of milliseconds that the initialization should be delayed, defaults to 0 | ||
* | ||
* @see {@link https://developers.intercom.com/installing-intercom/docs/basic-javascript} | ||
*/ | ||
var initialize = function initialize(appId) { | ||
var initialize = function initialize(appId, timeout) { | ||
if (timeout === void 0) { | ||
timeout = 0; | ||
} | ||
var w = window; | ||
@@ -174,8 +179,10 @@ var ic = w.Intercom; | ||
var l = function l() { | ||
var s = d.createElement('script'); | ||
s.type = 'text/javascript'; | ||
s.async = true; | ||
s.src = 'https://widget.intercom.io/widget/' + appId; | ||
var x = d.getElementsByTagName('script')[0]; | ||
x.parentNode.insertBefore(s, x); | ||
setTimeout(function () { | ||
var s = d.createElement('script'); | ||
s.type = 'text/javascript'; | ||
s.async = true; | ||
s.src = 'https://widget.intercom.io/widget/' + appId; | ||
var x = d.getElementsByTagName('script')[0]; | ||
x.parentNode.insertBefore(s, x); | ||
}, timeout); | ||
}; | ||
@@ -265,12 +272,10 @@ | ||
apiBase = _ref.apiBase, | ||
rest = _objectWithoutPropertiesLoose(_ref, ["appId", "autoBoot", "children", "onHide", "onShow", "onUnreadCountChange", "shouldInitialize", "apiBase"]); | ||
initializeDelay = _ref.initializeDelay, | ||
rest = _objectWithoutPropertiesLoose(_ref, ["appId", "autoBoot", "children", "onHide", "onShow", "onUnreadCountChange", "shouldInitialize", "apiBase", "initializeDelay"]); | ||
var isBooted = useRef(autoBoot); | ||
if (!isEmptyObject(rest) && process.env.NODE_ENV !== "production") log('error', ['some invalid props were passed to IntercomProvider. ', "Please check following props: " + Object.keys(rest).join(', ') + "."].join('')); | ||
var memoizedAppId = useRef(appId); | ||
var memoizedApiBase = useRef(apiBase); | ||
var isBooted = useRef(autoBoot); | ||
var memoizedShouldInitialize = useRef(shouldInitialize); | ||
if (!isSSR && !window.Intercom && memoizedShouldInitialize.current) { | ||
initialize(memoizedAppId.current); // Only add listeners on initialization | ||
if (!isSSR && !window.Intercom && shouldInitialize) { | ||
initialize(appId, initializeDelay); // Only add listeners on initialization | ||
@@ -283,10 +288,10 @@ if (onHide) IntercomAPI('onHide', onHide); | ||
IntercomAPI('boot', _extends({ | ||
app_id: memoizedAppId.current | ||
}, memoizedApiBase.current && { | ||
api_base: memoizedApiBase.current | ||
app_id: appId | ||
}, apiBase && { | ||
api_base: apiBase | ||
})); | ||
window.intercomSettings = _extends({ | ||
app_id: memoizedAppId.current | ||
}, memoizedApiBase.current && { | ||
api_base: memoizedApiBase.current | ||
app_id: appId | ||
}, apiBase && { | ||
api_base: apiBase | ||
}); | ||
@@ -301,3 +306,3 @@ } | ||
if (!window.Intercom && !memoizedShouldInitialize.current) { | ||
if (!window.Intercom && !shouldInitialize) { | ||
log('warn', 'Intercom instance is not initialized because `shouldInitialize` is set to `false` in `IntercomProvider`'); | ||
@@ -313,5 +318,5 @@ return; | ||
return callback(); | ||
}, []); | ||
}, [shouldInitialize]); | ||
var boot = useCallback(function (props) { | ||
if (!window.Intercom && !memoizedShouldInitialize.current) { | ||
if (!window.Intercom && !shouldInitialize) { | ||
log('warn', 'Intercom instance is not initialized because `shouldInitialize` is set to `false` in `IntercomProvider`'); | ||
@@ -324,5 +329,5 @@ return; | ||
var metaData = _extends({ | ||
app_id: memoizedAppId.current | ||
}, memoizedApiBase.current && { | ||
api_base: memoizedApiBase.current | ||
app_id: appId | ||
}, apiBase && { | ||
api_base: apiBase | ||
}, props && mapIntercomPropsToRawIntercomProps(props)); | ||
@@ -333,3 +338,3 @@ | ||
isBooted.current = true; | ||
}, []); | ||
}, [apiBase, appId, shouldInitialize]); | ||
var shutdown = useCallback(function () { | ||
@@ -336,0 +341,0 @@ if (!isBooted.current) return; |
@@ -394,2 +394,8 @@ /// <reference types="react" /> | ||
apiBase?: string; | ||
/** | ||
* Indicates if the intercom initialization should be delayed, delay is in ms | ||
* | ||
* @remarks If not set delay is set to 0ms | ||
* */ | ||
initializeDelay?: number; | ||
}; |
@@ -7,3 +7,3 @@ { | ||
"homepage": "https://github.com/devrnt/react-use-intercom#readme", | ||
"version": "1.1.9", | ||
"version": "1.2.0", | ||
"license": "MIT", | ||
@@ -29,3 +29,4 @@ "main": "dist/index.js", | ||
"require": "./dist/index.js", | ||
"import": "./dist/react-use-intercom.esm.js" | ||
"import": "./dist/react-use-intercom.esm.js", | ||
"browser": "./dist/react-use-intercom.esm.js" | ||
} | ||
@@ -87,6 +88,6 @@ }, | ||
"bundlesize": "^0.18.0", | ||
"cypress": "6.4.0", | ||
"dotenv": "^8.2.0", | ||
"cypress": "7.2.0", | ||
"dotenv": "^9.0.1", | ||
"eslint-plugin-simple-import-sort": "^7.0.0", | ||
"husky": "^5.0.9", | ||
"husky": "^6.0.0", | ||
"jsdom": "^16.4.0", | ||
@@ -93,0 +94,0 @@ "np": "^7.0.0", |
@@ -78,2 +78,3 @@ <p align="center"><img src="https://raw.githubusercontent.com/devrnt/react-use-intercom/master/assets/logo.png" alt="Logo" height="120px" style="margin-top: 20px;"/></p> | ||
| apiBase | string | If you need to route your Messenger requests through a different endpoint than the default. Generally speaking, this is not needed.<br/> Format: `https://${INTERCOM_APP_ID}.intercom-messenger.com` (See: [https://github.com/devrnt/react-use-intercom/pull/96](https://github.com/devrnt/react-use-intercom/pull/96)) | false | | | ||
| initializeDelay | number | Indicates if the intercom initialization should be delayed, delay is in ms, defaults to 0. See https://github.com/devrnt/react-use-intercom/pull/236 | false | | | ||
@@ -243,2 +244,11 @@ #### Example | ||
## Advanced | ||
### Delay initialization | ||
`<IntercomProvider />` uses an official intercom snippet and is directly initialized on load. In the background this snippet will load some external code that makes Intercom work. All of this magic happens on the initial load and in some use cases this can become problematic (E.g. when LCP is priority). | ||
Since [v1.2.0](https://github.com/devrnt/react-use-intercom/releases/tag/v1.2.0) it's possible to delay this initialisation by passing `initializeDelay` in `<IntercomProvider />` (it's in milliseconds). However most of the users won't need to mess with this. | ||
For reference see https://github.com/devrnt/react-use-intercom/pull/236 and https://forum.intercom.com/s/question/0D52G00004WxWLs/can-i-delay-loading-intercom-on-my-site-to-reduce-the-js-load | ||
### useCallback | ||
To reduce the amount of re-renders in your React application I suggest to make use of [`useCallback`](https://reactjs.org/docs/hooks-reference.html#usecallback) | ||
@@ -245,0 +255,0 @@ |
@@ -6,6 +6,7 @@ // @ts-nocheck | ||
* @param appId - Intercom app id | ||
* @param [timeout=0] - Amount of milliseconds that the initialization should be delayed, defaults to 0 | ||
* | ||
* @see {@link https://developers.intercom.com/installing-intercom/docs/basic-javascript} | ||
*/ | ||
const initialize = (appId: string) => { | ||
const initialize = (appId: string, timeout = 0) => { | ||
var w = window; | ||
@@ -27,8 +28,10 @@ var ic = w.Intercom; | ||
var l = function() { | ||
var s = d.createElement('script'); | ||
s.type = 'text/javascript'; | ||
s.async = true; | ||
s.src = 'https://widget.intercom.io/widget/' + appId; | ||
var x = d.getElementsByTagName('script')[0]; | ||
x.parentNode.insertBefore(s, x); | ||
setTimeout(function() { | ||
var s = d.createElement('script'); | ||
s.type = 'text/javascript'; | ||
s.async = true; | ||
s.src = 'https://widget.intercom.io/widget/' + appId; | ||
var x = d.getElementsByTagName('script')[0]; | ||
x.parentNode.insertBefore(s, x); | ||
}, timeout); | ||
}; | ||
@@ -35,0 +38,0 @@ if (document.readyState === 'complete') { |
@@ -422,2 +422,8 @@ export type RawMessengerAttributes = { | ||
apiBase?: string; | ||
/** | ||
* Indicates if the intercom initialization should be delayed, delay is in ms | ||
* | ||
* @remarks If not set delay is set to 0ms | ||
* */ | ||
initializeDelay?: number; | ||
}; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
174609
2114
289