Skip to content

Commit

Permalink
feat: add intercom (#1201)
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenFluin authored Dec 3, 2024
1 parent aecf625 commit c4a5bdc
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 2 deletions.
5 changes: 4 additions & 1 deletion astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ export default defineConfig({
}),
],
site: "https://docs.axelar.dev",

trailingSlash: "always",
devToolbar: {
enabled: false,
},
markdown: {
remarkPlugins: [
remarkDirective,
Expand Down
8 changes: 7 additions & 1 deletion src/layouts/MainLayout.astro
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ const canonicalURL = new URL(Astro.url.pathname, Astro.site);

gtag("config", "G-81ZT0BK1ZB");
</script>
<script>
window.intercomSettings = {
api_base: "https://api-iam.intercom.io",
app_id: "rxsoqwkv",
};
</script>
<script src="/src/scripts/index.ts"></script>
<script is:inline>
const root = document.documentElement;
Expand Down Expand Up @@ -157,7 +163,7 @@ const canonicalURL = new URL(Astro.url.pathname, Astro.site);
localStorage.setItem("theme", isDark ? "dark" : "light");
document.documentElement.setAttribute(
"data-theme",
isDark ? "vitesse-dark" : "light-plus",
isDark ? "vitesse-dark" : "light-plus"
);
};

Expand Down
2 changes: 2 additions & 0 deletions src/scripts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ import "./prism.js";
import "./safelinks";
import { showToast } from "./toast";
import "./wrapTables";
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);
}

0 comments on commit c4a5bdc

Please sign in to comment.