Skip to content

Commit 7a0c695

Browse files
authored
feat: add Chatbase (#584)
1 parent e792720 commit 7a0c695

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

next-env.d.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/// <reference types="next" />
22
/// <reference types="next/image-types/global" />
3-
/// <reference types="next/navigation-types/compat/navigation" />
43

54
// NOTE: This file should not be edited
65
// see https://nextjs.org/docs/basic-features/typescript for more information.

src/lib/scripts/chatbase.ts

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
export const chatbaseScript = `
2+
(function(){
3+
if(!window.chatbase||window.chatbase("getState")!=="initialized"){
4+
window.chatbase=(...arguments)=>{
5+
if(!window.chatbase.q){window.chatbase.q=[]}
6+
window.chatbase.q.push(arguments)
7+
};
8+
window.chatbase=new Proxy(window.chatbase,{
9+
get(target,prop){
10+
if(prop==="q"){return target.q}
11+
return(...args)=>target(prop,...args)
12+
}
13+
})
14+
}
15+
const onLoad=function(){
16+
const script=document.createElement("script");
17+
script.src="https://www.chatbase.co/embed.min.js";
18+
script.id="HwoQ2Sf9rFFtdW59sbYKF";
19+
script.domain="www.chatbase.co";
20+
document.body.appendChild(script)
21+
};
22+
if(document.readyState==="complete"){
23+
onLoad()
24+
}else{
25+
window.addEventListener("load",onLoad)
26+
}
27+
})();
28+
`;

src/pages/_document.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import Document, { DocumentContext, Head, Html, Main, NextScript } from "next/do
33
import React from "react";
44

55
import { createEmotionCache } from "~/lib/helpers/createEmotionCache";
6+
import { chatbaseScript } from "~/lib/scripts/chatbase";
67

78
export default class MyDocument extends Document {
89
static async getInitialProps(ctx: DocumentContext) {
@@ -41,6 +42,7 @@ export default class MyDocument extends Document {
4142
<body className="no-scrollbar">
4243
<Main />
4344
<NextScript />
45+
<script dangerouslySetInnerHTML={{ __html: chatbaseScript }} />
4446
</body>
4547
</Html>
4648
);

0 commit comments

Comments
 (0)