Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add intercom #1201

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ export default defineConfig({
integrations: [react(), mdx(), sitemap()],
site: "https://docs.axelar.dev",
trailingSlash: "always",
devToolbar: {
enabled: false,
},
markdown: {
remarkPlugins: [
setDefaultLayout,
Expand Down
11 changes: 9 additions & 2 deletions src/layouts/MainLayout.astro
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,15 @@ const canonicalURL = new URL(Astro.url.pathname, 'https://docs.axelar.dev');
}
</script>

</script>
<script src="/src/scripts/index.ts"></script>
</script>
<script>
window.intercomSettings = {
api_base: "https://api-iam.intercom.io",
app_id: "rxsoqwkv",
};
</script>
<script src="/src/scripts/index.ts"></script>

</head>
<body>
<nav>
Expand Down
1 change: 1 addition & 0 deletions src/scripts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ import "./menu";
import "./dark";
import { showToast } from "./toast";
import "./collapsible-nav";
import "./intercom";

window["showToast"] = showToast;
43 changes: 43 additions & 0 deletions src/scripts/intercom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
function loadIntercom() {
(function () {
const w: any = window;
const ic = w.Intercom;
if (typeof ic === "function") {
ic("reattach_activator");
ic("update", w.intercomSettings);
} else {
const d = document;
const i = function () {
i.c(arguments);
};
i.q = [];
i.c = function (args) {
i.q.push(args);
};
w.Intercom = i;
const s = d.createElement("script");
s.type = "text/javascript";
s.async = true;
s.src = "https://widget.intercom.io/widget/rxsoqwkv";
const x = d.getElementsByTagName("script")[0];
if (x && x.parentNode) {
x.parentNode.insertBefore(s, x);
console.log("intercom loading.");
}
}
})();
}

function checkAndLoadIntercom() {
if (document.readyState === "complete") {
// Wait 15 seconds after document ready and network idle
setTimeout(loadIntercom, 15000);
}
}

// Check for document ready and network idle
if (document.readyState === "complete") {
checkAndLoadIntercom();
} else {
window.addEventListener("load", checkAndLoadIntercom, false);
}