Skip to content

Commit

Permalink
switch intercom to module
Browse files Browse the repository at this point in the history
  • Loading branch information
ap-justin committed Dec 21, 2023
1 parent 9768a0c commit 8b79883
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 78 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
"react-redux": "^8.0.5",
"react-router-dom": "^6.2.0",
"react-scripts": "5.0.1",
"react-use-intercom": "^5.3.0",
"type-fest": "^3.9.0",
"yup": "1.3.0"
},
Expand Down
77 changes: 0 additions & 77 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -158,83 +158,6 @@
/>
</noscript>
<!-- END LinkedIn Tracking Script -->
<!-- Intercom code -->
<script>
window.intercomSettings = {
api_base: "https://api-iam.intercom.io",
app_id: "fh3v40sb",
};
</script>
<script>
(function () {
if ("%REACT_APP_APP_TYPE%" !== "AST") {
var w = window;
var ic = w.Intercom;
if (typeof ic === "function") {
ic("reattach_activator");
ic("update", w.intercomSettings);
} else {
var d = document;
var i = function () {
i.c(arguments);
};
i.q = [];
i.c = function (args) {
i.q.push(args);
};
w.Intercom = i;
var l = function () {
var s = d.createElement("script");
s.type = "text/javascript";
s.async = true;
s.onload = async function () {
const offset = 100;
const initDelay = 200;
const debounceTime = 200;
//wait a bit to initialize launcher after loading script
await new Promise((r) => setTimeout(r, initDelay));
const launcher = document.querySelector(".intercom-launcher");

function debounce(callback) {
let timeout;
const debounced = (args) => {
if (timeout) {
window.clearTimeout(timeout);
}
timeout = window.setTimeout(() => {
callback.apply(null, args);
}, debounceTime);
};
return debounced;
}
const intercomHandleScroll = debounce(function () {
launcher.style.display =
window.innerHeight + window.scrollY >=
document.body.offsetHeight - offset
? "none"
: "block";
});
window.addEventListener("scroll", intercomHandleScroll, {
passive: true,
});
};
s.src = "https://widget.intercom.io/widget/fh3v40sb";
var x = d.getElementsByTagName("script")[0];
x.parentNode.insertBefore(s, x);
};

if (document.readyState === "complete") {
l();
} else if (w.attachEvent) {
w.attachEvent("onload", l);
} else {
w.addEventListener("load", l, false);
}
}
}
})();
</script>
<!-- END Intercom code -->
<script
async
src="https://www.googletagmanager.com/gtag/js?id=G-Z2YP33XHHD"
Expand Down
5 changes: 4 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { StrictMode, Suspense, lazy } from "react";
import { createRoot } from "react-dom/client";
import { Provider } from "react-redux";
import { BrowserRouter } from "react-router-dom";
import { IntercomProvider } from "react-use-intercom";
import Loader from "components/Loader";
import { store } from "store/store";
import ErrorBoundary from "errors/ErrorBoundary";
Expand Down Expand Up @@ -34,7 +35,9 @@ root.render(
<BrowserRouter>
<Suspense fallback={<LoaderComponent />}>
<Authenticator.Provider>
<App />
<IntercomProvider appId="fh3v40sb" autoBoot>
<App />
</IntercomProvider>
</Authenticator.Provider>
</Suspense>
</BrowserRouter>
Expand Down
11 changes: 11 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7109,6 +7109,7 @@ __metadata:
react-router-dom: ^6.2.0
react-scripts: 5.0.1
react-test-renderer: ^18.2.0
react-use-intercom: ^5.3.0
source-map-explorer: ^2.5.2
tailwindcss: 3.3.0
tsc-files: ^1.1.3
Expand Down Expand Up @@ -16828,6 +16829,16 @@ __metadata:
languageName: node
linkType: hard

"react-use-intercom@npm:^5.3.0":
version: 5.3.0
resolution: "react-use-intercom@npm:5.3.0"
peerDependencies:
react: ">=16.8.0"
react-dom: ">=16.8.0"
checksum: b08e1aa92b93ebeea01aa89f799eaed51d27887026a5983458800e13a7cf20fc267b59b3d12e78eb04335428f3000ceb779c92b4cbd4348cd70811c733d12d8c
languageName: node
linkType: hard

"react@npm:^18.2.0":
version: 18.2.0
resolution: "react@npm:18.2.0"
Expand Down

0 comments on commit 8b79883

Please sign in to comment.