diff --git a/_overrides/main.html b/_overrides/main.html
index 2707b4280..0fdc11520 100644
--- a/_overrides/main.html
+++ b/_overrides/main.html
@@ -61,6 +61,22 @@ https://plausible.io/docs/script-extensions?ref=ryansechrest.com#all-our-script-
{% block scripts %}
+
{{ super() }}
diff --git a/docs/_extra/javascript/init_kapa_widget.js b/docs/_extra/javascript/init_kapa_widget.js
deleted file mode 100644
index 4f5b06010..000000000
--- a/docs/_extra/javascript/init_kapa_widget.js
+++ /dev/null
@@ -1,18 +0,0 @@
-// https://docs.kapa.ai/integrations/website-widget/installation/mkdocs
-
-document.addEventListener("DOMContentLoaded", function () {
- var script = document.createElement("script");
- script.src = "https://widget.kapa.ai/kapa-widget.bundle.js";
- script.setAttribute("data-website-id", "d2598b63-bfa7-4ddd-a0ac-e6c69f4d0653");
- script.setAttribute("data-project-name", "n8n");
- script.setAttribute("data-project-color", "#EA4B71");
- script.setAttribute("data-project-logo", "/_images/assets/n8n-icon-kapa-modal.png");
- // Hide the Kapa widget
- script.setAttribute("data-button-hide", true);
- // MkDocs tries to squeeze the modal
- script.setAttribute("data-modal-size", "900px");
- // Make sure we don't track users, so we don't have to put this behind the cookie widget https://docs.kapa.ai/integrations/website-widget/user-tracking
- script.setAttribute("data-user-analytics-cookie-enabled", false);
- script.async = true;
- document.head.appendChild(script);
-});
\ No newline at end of file
diff --git a/docs/_extra/javascript/kapa_widget.js b/docs/_extra/javascript/kapa_widget.js
new file mode 100644
index 000000000..6e8100d13
--- /dev/null
+++ b/docs/_extra/javascript/kapa_widget.js
@@ -0,0 +1,67 @@
+// Initiate and configure the widget
+// https://docs.kapa.ai/integrations/website-widget/installation/mkdocs
+
+document.addEventListener("DOMContentLoaded", function () {
+ var script = document.createElement("script");
+ script.src = "https://widget.kapa.ai/kapa-widget.bundle.js";
+ script.setAttribute("data-website-id", "d2598b63-bfa7-4ddd-a0ac-e6c69f4d0653");
+ script.setAttribute("data-project-name", "n8n");
+ script.setAttribute("data-project-color", "#EA4B71");
+ script.setAttribute("data-project-logo", "/_images/assets/n8n-icon-kapa-modal.png");
+ // Hide the Kapa widget
+ script.setAttribute("data-button-hide", true);
+ // MkDocs tries to squeeze the modal
+ script.setAttribute("data-modal-size", "900px");
+ // Make sure we don't track users, so we don't have to put this behind the cookie widget https://docs.kapa.ai/integrations/website-widget/user-tracking
+ script.setAttribute("data-user-analytics-cookie-enabled", false);
+ script.async = true;
+ document.head.appendChild(script);
+});
+
+// Add tracking in Plausible
+// https://docs.kapa.ai/integrations/website-widget/javascript-api/events#onaskaianswercompleted
+
+Kapa(
+ "onAskAIAnswerCompleted",
+ ({ threadId, questionAnswerId, question, answer, conversation }) => {
+ let currentPage = window.location.href;
+ plausible("Kapa Question", {props: {
+ page: currentPage,
+ kapaThreadId: threadId,
+ question: question,
+ answer: answer
+ }})
+ },
+);
+
+// https://docs.kapa.ai/integrations/website-widget/javascript-api/events#onaskailinkclick
+
+Kapa(
+ "onAskAILinkClick",
+ ({ href, threadId, questionAnswerId, question, answer }) => {
+ let currentPage = window.location.href;
+ plausible("Kapa Link In Answer Clicked", {props: {
+ page: currentPage,
+ link: href,
+ kapaThreadId: threadId,
+ question: question,
+ answer: answer
+ }})
+ },
+);
+
+// https://docs.kapa.ai/integrations/website-widget/javascript-api/events#onaskaisourceclick
+
+Kapa(
+ "onAskAISourceClick",
+ ({ source, threadId, questionAnswerId, question, answer }) => {
+ let currentPage = window.location.href;
+ plausible("Kapa Link In Listed Sources Clicked", {props: {
+ page: currentPage,
+ source: source.url,
+ kapaThreadId: threadId,
+ question: question,
+ answer: answer
+ }})
+ },
+);
\ No newline at end of file
diff --git a/mkdocs.yml b/mkdocs.yml
index 7e7b7ae2a..1420df863 100644
--- a/mkdocs.yml
+++ b/mkdocs.yml
@@ -75,8 +75,7 @@ extra_css:
# https://squidfunk.github.io/mkdocs-material/customization/?h=#additional-javascript
extra_javascript:
- _extra/javascript/feedback.js
- - _extra/javascript/init_kapa_widget.js
-
+ - _extra/javascript/kapa_widget.js
watch:
- _snippets
- _overrides