react-use-intercom
Advanced tools
Comparing version 5.2.0 to 5.3.0
@@ -225,3 +225,3 @@ import * as React from 'react'; | ||
}; | ||
type IntercomMethod = 'boot' | 'shutdown' | 'update' | 'hide' | 'show' | 'showMessages' | 'showNewMessage' | 'startSurvey' | 'onHide' | 'onShow' | 'onUnreadCountChange' | 'onUserEmailSupplied' | 'trackEvent' | 'getVisitorId' | 'startTour' | 'showArticle' | 'showSpace' | 'showNews'; | ||
type IntercomMethod = 'boot' | 'shutdown' | 'update' | 'hide' | 'show' | 'showMessages' | 'showNewMessage' | 'startSurvey' | 'onHide' | 'onShow' | 'onUnreadCountChange' | 'onUserEmailSupplied' | 'trackEvent' | 'getVisitorId' | 'startTour' | 'startChecklist' | 'showArticle' | 'showSpace' | 'showNews'; | ||
type RawIntercomProps = RawMessengerAttributes & RawDataAttributes; | ||
@@ -339,6 +339,19 @@ type RawIntercomBootProps = { | ||
* | ||
* @see {@link https://developers.intercom.com/installing-intercom/docs/intercom-javascript#section-intercomstarttour-tourid} | ||
* @see {@link https://developers.intercom.com/installing-intercom/docs/intercom-javascript#intercomstarttour-tourid} | ||
*/ | ||
startTour: (tourId: number) => void; | ||
/** | ||
* Triggers a checklist based on an action a user or visitor takes in your site or application, | ||
* You need to call this method with the id of the checklist you wish to show. | ||
* | ||
* The id of the checklist can be found in the “Aditional ways to share your checklist” section | ||
* of the tour editor. | ||
* | ||
* @remarks Please note that checklists shown via this API must be published. | ||
* If you're calling this API using an invalid tour id, nothing will happen. | ||
* | ||
* @see {@link https://developers.intercom.com/installing-intercom/web/methods/#intercomstartchecklist-checklistid} | ||
*/ | ||
startChecklist: (checklistId: number) => void; | ||
/** | ||
* Submits an event, this will associate the event with the currently | ||
@@ -345,0 +358,0 @@ * tracked visitor, lead or user and send it to Intercom |
@@ -25,7 +25,7 @@ 'use strict'; | ||
var ne=Object.defineProperty;var R=Object.getOwnPropertySymbols;var F=Object.prototype.hasOwnProperty,H=Object.prototype.propertyIsEnumerable;var j=(e,t,r)=>t in e?ne(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,m=(e,t)=>{for(var r in t||(t={}))F.call(t,r)&&j(e,r,t[r]);if(R)for(var r of R(t))H.call(t,r)&&j(e,r,t[r]);return e};var K=(e,t)=>{var r={};for(var c in e)F.call(e,c)&&t.indexOf(c)<0&&(r[c]=e[c]);if(e!=null&&R)for(var c of R(e))t.indexOf(c)<0&&H.call(e,c)&&(r[c]=e[c]);return r};var p=(e,t)=>{let r="[react-use-intercom]";switch(e){case"info":console.log(`${r} ${t}`);break;case"warn":console.warn(`${r} ${t}`);break;case"error":console.error(`${r} ${t}`);break;default:console.log(`${r} ${t}`);}};var h=typeof window=="undefined",A=e=>(Object.keys(e).forEach(t=>{e[t]&&typeof e[t]=="object"?A(e[t]):e[t]===void 0&&delete e[t];}),e);var ae=(e,...t)=>{if(!h&&window.Intercom)return window.Intercom.apply(null,[e,...t]);p("error",`${e} Intercom instance is not initalized yet`);},s=ae;var se=o__namespace.createContext(void 0),P=se;var ce=(e,t=0)=>{var r=window,c=r.Intercom;if(typeof c=="function")c("reattach_activator"),c("update",r.intercomSettings);else {var w=document,l=function(){l.c(arguments);};l.q=[],l.c=function(u){l.q.push(u);},r.Intercom=l;var f=function(){setTimeout(function(){var u=w.createElement("script");u.type="text/javascript",u.async=!0,u.src="https://widget.intercom.io/widget/"+e;var d=w.getElementsByTagName("script")[0];d.parentNode.insertBefore(u,d);},t);};document.readyState==="complete"?f():r.attachEvent?r.attachEvent("onload",f):r.addEventListener("load",f,!1);}},Q=ce;var ie=e=>({custom_launcher_selector:e.customLauncherSelector,alignment:e.alignment,vertical_padding:e.verticalPadding,horizontal_padding:e.horizontalPadding,hide_default_launcher:e.hideDefaultLauncher,session_duration:e.sessionDuration,action_color:e.actionColor,background_color:e.backgroundColor}),X=e=>m({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),me=e=>({type:e.type,image_url:e.imageUrl}),le=e=>{var t;return m({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&&me(e.avatar),user_hash:e.userHash,company:e.company&&X(e.company),companies:(t=e.companies)==null?void 0:t.map(X)},e.customAttributes)},b=e=>A(m(m({},ie(e)),le(e)));var ue=pe=>{var y=pe,{appId:e,autoBoot:t=!1,autoBootProps:r,children:c,onHide:w,onShow:l,onUnreadCountChange:f,onUserEmailSupplied:u,shouldInitialize:d=!h,apiBase:v,initializeDelay:Z}=y,ee=K(y,["appId","autoBoot","autoBootProps","children","onHide","onShow","onUnreadCountChange","onUserEmailSupplied","shouldInitialize","apiBase","initializeDelay"]);let g=o__namespace.useRef(!1),_=o__namespace.useRef(!1),x=Object.keys(ee).filter(n=>!n.startsWith("data-"));x.length>0&&p("warn",["some invalid props were passed to IntercomProvider. ",`Please check following props: ${x.join(", ")}.`].join(""));let C=o__namespace.useCallback(n=>{if(!window.Intercom&&!d){p("warn","Intercom instance is not initialized because `shouldInitialize` is set to `false` in `IntercomProvider`");return}let i=m(m({app_id:e},v&&{api_base:v}),n&&b(n));window.intercomSettings=i,s("boot",i),g.current=!0;},[v,e,d]),[k,I]=o__namespace.useState(!1),te=o__namespace.useCallback(()=>{I(!1),w&&w();},[w,I]),oe=o__namespace.useCallback(()=>{I(!0),l&&l();},[l,I]);!h&&d&&!_.current&&(Q(e,Z),s("onHide",te),s("onShow",oe),s("onUserEmailSupplied",u),f&&s("onUnreadCountChange",f),t&&C(r),_.current=!0);let a=o__namespace.useCallback((n,i)=>{if(!window.Intercom&&!d){p("warn","Intercom instance is not initialized because `shouldInitialize` is set to `false` in `IntercomProvider`");return}if(!g.current){p("warn",[`"${n}" was called but Intercom has not booted yet. `,`Please call 'boot' before calling '${n}' or `,"set 'autoBoot' to true in the IntercomProvider."].join(""));return}return i()},[d]),S=o__namespace.useCallback(()=>{g.current&&(s("shutdown"),delete window.intercomSettings,g.current=!1);},[]),D=o__namespace.useCallback(()=>{g.current&&(s("shutdown"),delete window.Intercom,delete window.intercomSettings,g.current=!1);},[]),M=o__namespace.useCallback(()=>{a("update",()=>{let n=Math.floor(new Date().getTime()/1e3);s("update",{last_request_at:n});});},[a]),E=o__namespace.useCallback(n=>{a("update",()=>{if(!n){M();return}let i=b(n);window.intercomSettings=m(m({},window.intercomSettings),i),s("update",i);});},[a,M]),T=o__namespace.useCallback(()=>{a("hide",()=>{s("hide");});},[a]),$=o__namespace.useCallback(()=>{a("show",()=>s("show"));},[a]),N=o__namespace.useCallback(()=>{a("showMessages",()=>{s("showMessages");});},[a]),V=o__namespace.useCallback(n=>{a("showNewMessage",()=>{n?s("showNewMessage",n):s("showNewMessage");});},[a]),z=o__namespace.useCallback(()=>a("getVisitorId",()=>s("getVisitorId")),[a]),L=o__namespace.useCallback(n=>{a("startTour",()=>{s("startTour",n);});},[a]),q=o__namespace.useCallback((n,i)=>{a("trackEvent",()=>{i?s("trackEvent",n,i):s("trackEvent",n);});},[a]),O=o__namespace.useCallback(n=>a("showArticle",()=>{s("showArticle",n);}),[a]),B=o__namespace.useCallback(n=>a("showSpace",()=>{s("showSpace",n);}),[a]),U=o__namespace.useCallback(n=>{a("startSurvey",()=>{s("startSurvey",n);});},[a]),W=o__namespace.useCallback(n=>a("showNews",()=>{s("showNews",n);}),[a]),re=o__namespace.useMemo(()=>({boot:C,shutdown:S,hardShutdown:D,update:E,hide:T,show:$,isOpen:k,showMessages:N,showNewMessage:V,getVisitorId:z,startTour:L,trackEvent:q,showArticle:O,startSurvey:U,showSpace:B,showNews:W}),[C,S,D,E,T,$,k,N,V,z,L,q,O,U,B,W]);return o__namespace.createElement(P.Provider,{value:re},c)},Y=()=>{let e=o__namespace.useContext(P);if(e===void 0)throw new Error('"useIntercom" must be used within `IntercomProvider`.');return e};var de=()=>Y(); | ||
var ae=Object.defineProperty;var R=Object.getOwnPropertySymbols;var H=Object.prototype.hasOwnProperty,K=Object.prototype.propertyIsEnumerable;var F=(e,t,n)=>t in e?ae(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,m=(e,t)=>{for(var n in t||(t={}))H.call(t,n)&&F(e,n,t[n]);if(R)for(var n of R(t))K.call(t,n)&&F(e,n,t[n]);return e};var G=(e,t)=>{var n={};for(var c in e)H.call(e,c)&&t.indexOf(c)<0&&(n[c]=e[c]);if(e!=null&&R)for(var c of R(e))t.indexOf(c)<0&&K.call(e,c)&&(n[c]=e[c]);return n};var p=(e,t)=>{let n="[react-use-intercom]";switch(e){case"info":console.log(`${n} ${t}`);break;case"warn":console.warn(`${n} ${t}`);break;case"error":console.error(`${n} ${t}`);break;default:console.log(`${n} ${t}`);}};var h=typeof window=="undefined",A=e=>(Object.keys(e).forEach(t=>{e[t]&&typeof e[t]=="object"?A(e[t]):e[t]===void 0&&delete e[t];}),e);var se=(e,...t)=>{if(!h&&window.Intercom)return window.Intercom.apply(null,[e,...t]);p("error",`${e} Intercom instance is not initalized yet`);},s=se;var ce=o__namespace.createContext(void 0),P=ce;var ie=(e,t=0)=>{var n=window,c=n.Intercom;if(typeof c=="function")c("reattach_activator"),c("update",n.intercomSettings);else {var w=document,l=function(){l.c(arguments);};l.q=[],l.c=function(u){l.q.push(u);},n.Intercom=l;var f=function(){setTimeout(function(){var u=w.createElement("script");u.type="text/javascript",u.async=!0,u.src="https://widget.intercom.io/widget/"+e;var d=w.getElementsByTagName("script")[0];d.parentNode.insertBefore(u,d);},t);};document.readyState==="complete"?f():n.attachEvent?n.attachEvent("onload",f):n.addEventListener("load",f,!1);}},X=ie;var me=e=>({custom_launcher_selector:e.customLauncherSelector,alignment:e.alignment,vertical_padding:e.verticalPadding,horizontal_padding:e.horizontalPadding,hide_default_launcher:e.hideDefaultLauncher,session_duration:e.sessionDuration,action_color:e.actionColor,background_color:e.backgroundColor}),Y=e=>m({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),le=e=>({type:e.type,image_url:e.imageUrl}),ue=e=>{var t;return m({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&&le(e.avatar),user_hash:e.userHash,company:e.company&&Y(e.company),companies:(t=e.companies)==null?void 0:t.map(Y)},e.customAttributes)},b=e=>A(m(m({},me(e)),ue(e)));var de=we=>{var k=we,{appId:e,autoBoot:t=!1,autoBootProps:n,children:c,onHide:w,onShow:l,onUnreadCountChange:f,onUserEmailSupplied:u,shouldInitialize:d=!h,apiBase:v,initializeDelay:ee}=k,te=G(k,["appId","autoBoot","autoBootProps","children","onHide","onShow","onUnreadCountChange","onUserEmailSupplied","shouldInitialize","apiBase","initializeDelay"]);let g=o__namespace.useRef(!1),y=o__namespace.useRef(!1),_=Object.keys(te).filter(r=>!r.startsWith("data-"));_.length>0&&p("warn",["some invalid props were passed to IntercomProvider. ",`Please check following props: ${_.join(", ")}.`].join(""));let C=o__namespace.useCallback(r=>{if(!window.Intercom&&!d){p("warn","Intercom instance is not initialized because `shouldInitialize` is set to `false` in `IntercomProvider`");return}let i=m(m({app_id:e},v&&{api_base:v}),r&&b(r));window.intercomSettings=i,s("boot",i),g.current=!0;},[v,e,d]),[x,I]=o__namespace.useState(!1),oe=o__namespace.useCallback(()=>{I(!1),w&&w();},[w,I]),re=o__namespace.useCallback(()=>{I(!0),l&&l();},[l,I]);!h&&d&&!y.current&&(X(e,ee),s("onHide",oe),s("onShow",re),s("onUserEmailSupplied",u),f&&s("onUnreadCountChange",f),t&&C(n),y.current=!0);let a=o__namespace.useCallback((r,i)=>{if(!window.Intercom&&!d){p("warn","Intercom instance is not initialized because `shouldInitialize` is set to `false` in `IntercomProvider`");return}if(!g.current){p("warn",[`"${r}" was called but Intercom has not booted yet. `,`Please call 'boot' before calling '${r}' or `,"set 'autoBoot' to true in the IntercomProvider."].join(""));return}return i()},[d]),S=o__namespace.useCallback(()=>{g.current&&(s("shutdown"),delete window.intercomSettings,g.current=!1);},[]),D=o__namespace.useCallback(()=>{g.current&&(s("shutdown"),delete window.Intercom,delete window.intercomSettings,g.current=!1);},[]),M=o__namespace.useCallback(()=>{a("update",()=>{let r=Math.floor(new Date().getTime()/1e3);s("update",{last_request_at:r});});},[a]),E=o__namespace.useCallback(r=>{a("update",()=>{if(!r){M();return}let i=b(r);window.intercomSettings=m(m({},window.intercomSettings),i),s("update",i);});},[a,M]),T=o__namespace.useCallback(()=>{a("hide",()=>{s("hide");});},[a]),$=o__namespace.useCallback(()=>{a("show",()=>s("show"));},[a]),N=o__namespace.useCallback(()=>{a("showMessages",()=>{s("showMessages");});},[a]),V=o__namespace.useCallback(r=>{a("showNewMessage",()=>{r?s("showNewMessage",r):s("showNewMessage");});},[a]),z=o__namespace.useCallback(()=>a("getVisitorId",()=>s("getVisitorId")),[a]),L=o__namespace.useCallback(r=>{a("startTour",()=>{s("startTour",r);});},[a]),q=o__namespace.useCallback(r=>{a("startChecklist",()=>{s("startChecklist",r);});},[a]),O=o__namespace.useCallback((r,i)=>{a("trackEvent",()=>{i?s("trackEvent",r,i):s("trackEvent",r);});},[a]),B=o__namespace.useCallback(r=>a("showArticle",()=>{s("showArticle",r);}),[a]),U=o__namespace.useCallback(r=>a("showSpace",()=>{s("showSpace",r);}),[a]),W=o__namespace.useCallback(r=>{a("startSurvey",()=>{s("startSurvey",r);});},[a]),j=o__namespace.useCallback(r=>a("showNews",()=>{s("showNews",r);}),[a]),ne=o__namespace.useMemo(()=>({boot:C,shutdown:S,hardShutdown:D,update:E,hide:T,show:$,isOpen:x,showMessages:N,showNewMessage:V,getVisitorId:z,startTour:L,startChecklist:q,trackEvent:O,showArticle:B,startSurvey:W,showSpace:U,showNews:j}),[C,S,D,E,T,$,x,N,V,z,L,q,O,B,W,U,j]);return o__namespace.createElement(P.Provider,{value:ne},c)},Z=()=>{let e=o__namespace.useContext(P);if(e===void 0)throw new Error('"useIntercom" must be used within `IntercomProvider`.');return e};var pe=()=>Z(); | ||
exports.IntercomProvider = ue; | ||
exports.useIntercom = de; | ||
exports.IntercomProvider = de; | ||
exports.useIntercom = pe; | ||
//# sourceMappingURL=out.js.map | ||
//# sourceMappingURL=index.js.map |
@@ -7,3 +7,3 @@ { | ||
"homepage": "https://github.com/devrnt/react-use-intercom#readme", | ||
"version": "5.2.0", | ||
"version": "5.3.0", | ||
"license": "MIT", | ||
@@ -10,0 +10,0 @@ "main": "dist/index.js", |
@@ -147,2 +147,3 @@ <p align="center"><img src="https://raw.githubusercontent.com/devrnt/react-use-intercom/main/assets/logo.png" alt="Logo" height="120px" style="margin-top: 20px;"/></p> | ||
| startTour | (tourId: number) => void | starts a tour based on the `tourId` | | ||
| startChecklist | (checklistId: number) => void | starts a checklist based on the `checklistId` | | ||
| trackEvent | (event: string, metaData?: object) => void | submits an `event` with optional `metaData` | ||
@@ -179,2 +180,3 @@ | showArticle | (articleId: string) => void | opens the Messenger with the specified article by `articleId` | ||
startTour, | ||
startChecklist, | ||
trackEvent, | ||
@@ -192,2 +194,3 @@ showArticle, | ||
const handleStartTour = () => startTour(123); | ||
const handleStartChecklist = () => startChecklist(456); | ||
const handleTrackEvent = () => trackEvent('invited-friend'); | ||
@@ -219,2 +222,3 @@ const handleTrackEventWithMetaData = () => | ||
<button onClick={handleStartTour}>Start tour</button> | ||
<button onClick={handleStartChecklist}>Start checklist</button> | ||
<button onClick={handleTrackEvent}>Track event</button> | ||
@@ -221,0 +225,0 @@ <button onClick={handleTrackEventWithMetaData}> |
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
96536
542
288