From c9a0c5d6de4aa5f85d29f5197df6630284596092 Mon Sep 17 00:00:00 2001 From: Ryan Date: Fri, 6 Dec 2024 19:52:03 +0000 Subject: [PATCH 1/6] feat: adding party town --- packages/react-use-intercom/src/initialize.ts | 19 +++++++++++++++++-- packages/react-use-intercom/src/provider.tsx | 3 ++- packages/react-use-intercom/src/types.ts | 4 ++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/packages/react-use-intercom/src/initialize.ts b/packages/react-use-intercom/src/initialize.ts index ba454aec..006aa7f7 100644 --- a/packages/react-use-intercom/src/initialize.ts +++ b/packages/react-use-intercom/src/initialize.ts @@ -1,13 +1,24 @@ +interface InitializeProps { + appId: string; + timeout?: number; + isPartyTown?: boolean; +} + // @ts-nocheck /** * Snippet to initialize the Intercom instance * * @param appId - Intercom app id * @param [timeout=0] - Amount of milliseconds that the initialization should be delayed, defaults to 0 + * @param [isPartyTown=false] - If intercom should be initialized using party town * * @see {@link https://developers.intercom.com/installing-intercom/docs/basic-javascript} */ -const initialize = (appId: string, timeout = 0) => { +const initialize = ({ + appId, + timeout = 0, + isPartyTown = false, +}: InitializeProps) => { var w = window; var ic = w.Intercom; if (typeof ic === 'function') { @@ -26,11 +37,15 @@ const initialize = (appId: string, timeout = 0) => { var l = function () { setTimeout(function () { var s = d.createElement('script'); - s.type = 'text/javascript'; + s.type = isPartyTown ? 'text/partytown' : 'text/javascript'; s.async = true; s.src = 'https://widget.intercom.io/widget/' + appId; var x = d.getElementsByTagName('script')[0]; x.parentNode.insertBefore(s, x); + + if (isPartyTown) { + window.dispatchEvent(new CustomEvent('ptupdate')); + } }, timeout); }; if (document.readyState === 'complete') { diff --git a/packages/react-use-intercom/src/provider.tsx b/packages/react-use-intercom/src/provider.tsx index 6145ef5e..1523367d 100644 --- a/packages/react-use-intercom/src/provider.tsx +++ b/packages/react-use-intercom/src/provider.tsx @@ -28,6 +28,7 @@ export const IntercomProvider: React.FC< shouldInitialize = !isSSR, apiBase, initializeDelay, + isPartyTown = false, ...rest }) => { const isBooted = React.useRef(false); @@ -102,7 +103,7 @@ export const IntercomProvider: React.FC< React.useEffect(() => { if (!isSSR && shouldInitialize && !isInitialized.current) { - initialize(appId, initializeDelay); + initialize({ appId, timeout: initializeDelay, isPartyTown }); if (autoBoot) { boot(autoBootProps); diff --git a/packages/react-use-intercom/src/types.ts b/packages/react-use-intercom/src/types.ts index 4f6d3ce7..da58a4b4 100644 --- a/packages/react-use-intercom/src/types.ts +++ b/packages/react-use-intercom/src/types.ts @@ -511,6 +511,10 @@ export type IntercomProviderProps = { * @remarks If not set delay is set to 0ms * */ initializeDelay?: number; + /** + * Pass properties to `boot` method when `autoBoot` is `true` + */ + isPartyTown?: boolean; /** * Pass properties to `boot` method when `autoBoot` is `true` */ From 4312904539b71f1daf6cf09bf1a6f813cae3c403 Mon Sep 17 00:00:00 2001 From: Ryan Date: Fri, 6 Dec 2024 19:57:20 +0000 Subject: [PATCH 2/6] feat: update comment --- packages/react-use-intercom/src/types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-use-intercom/src/types.ts b/packages/react-use-intercom/src/types.ts index da58a4b4..f5dd2f55 100644 --- a/packages/react-use-intercom/src/types.ts +++ b/packages/react-use-intercom/src/types.ts @@ -512,7 +512,7 @@ export type IntercomProviderProps = { * */ initializeDelay?: number; /** - * Pass properties to `boot` method when `autoBoot` is `true` + * If intercom should be initialized using party town */ isPartyTown?: boolean; /** From 154817e4559eea172d1002edfe6e256ece1ff455 Mon Sep 17 00:00:00 2001 From: Ryan Date: Fri, 6 Dec 2024 20:00:10 +0000 Subject: [PATCH 3/6] feat: adding changeset --- .changeset/fifty-spiders-burn.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/fifty-spiders-burn.md diff --git a/.changeset/fifty-spiders-burn.md b/.changeset/fifty-spiders-burn.md new file mode 100644 index 00000000..9e469d4e --- /dev/null +++ b/.changeset/fifty-spiders-burn.md @@ -0,0 +1,5 @@ +--- +'react-use-intercom': minor +--- + +Adding party town as an option From 3fa4af21f72c2e7d0e89f47e5398ecd6ed09672b Mon Sep 17 00:00:00 2001 From: Ryan Date: Fri, 6 Dec 2024 20:01:38 +0000 Subject: [PATCH 4/6] fix:fix lint issues --- packages/react-use-intercom/src/initialize.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/react-use-intercom/src/initialize.ts b/packages/react-use-intercom/src/initialize.ts index 006aa7f7..9d4cc021 100644 --- a/packages/react-use-intercom/src/initialize.ts +++ b/packages/react-use-intercom/src/initialize.ts @@ -1,10 +1,10 @@ +// @ts-nocheck + interface InitializeProps { appId: string; timeout?: number; isPartyTown?: boolean; } - -// @ts-nocheck /** * Snippet to initialize the Intercom instance * @@ -14,6 +14,7 @@ interface InitializeProps { * * @see {@link https://developers.intercom.com/installing-intercom/docs/basic-javascript} */ + const initialize = ({ appId, timeout = 0, From d4a5600119c6673983939647e2571bcfcb324673 Mon Sep 17 00:00:00 2001 From: Ryan Date: Fri, 6 Dec 2024 20:04:43 +0000 Subject: [PATCH 5/6] feat: update readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 65616e20..93cd131e 100644 --- a/README.md +++ b/README.md @@ -90,6 +90,7 @@ Place the `IntercomProvider` as high as possible in your application. This will | shouldInitialize | boolean | indicates if the Intercom should be initialized. Can be used in multistaged environment | false | true | | apiBase | string | If you need to route your Messenger requests through a different endpoint than the default. Generally speaking, this is not needed.
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 | | +| isPartyTown | boolean | Indicates if the intercom initialization with party town. See https://github.com/devrnt/react-use-intercom/pull/236 | false | false | | autoBootProps | IntercomProps | Pass properties to `boot` method when `autoBoot` is `true` | false | | #### Example From 1a6573819ac9a87095c31c14827056eb82fd5316 Mon Sep 17 00:00:00 2001 From: Ryan Date: Fri, 6 Dec 2024 20:05:36 +0000 Subject: [PATCH 6/6] feat: update readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 93cd131e..ae393148 100644 --- a/README.md +++ b/README.md @@ -90,7 +90,7 @@ Place the `IntercomProvider` as high as possible in your application. This will | shouldInitialize | boolean | indicates if the Intercom should be initialized. Can be used in multistaged environment | false | true | | apiBase | string | If you need to route your Messenger requests through a different endpoint than the default. Generally speaking, this is not needed.
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 | | -| isPartyTown | boolean | Indicates if the intercom initialization with party town. See https://github.com/devrnt/react-use-intercom/pull/236 | false | false | +| isPartyTown | boolean | Indicates if the intercom initialization with party town. See https://github.com/devrnt/react-use-intercom/pull/742 | false | false | | autoBootProps | IntercomProps | Pass properties to `boot` method when `autoBoot` is `true` | false | | #### Example