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

feat: add posthog tracking to inkeep + prepare for support handover #1030

Merged
merged 1 commit into from
Nov 28, 2024
Merged
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
53 changes: 33 additions & 20 deletions components/inkeep/useInkeepSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,18 @@ import type {
} from "@inkeep/uikit";
import { useTheme } from "nextra-theme-docs";
import { openChat } from "../supportChat";
import { MessageCircle } from "lucide-react";
import { InkeepCallbackEvent } from "@inkeep/uikit";
import { type PostHog, usePostHog } from "posthog-js/react";

const customAnalyticsCallback = (
event: InkeepCallbackEvent,
posthog: PostHog
): void => {
const { interactionType } = event.commonProperties;
posthog.capture(`inkeep:${event.eventName}`, {
interactionType,
});
};

type InkeepSharedSettings = {
baseSettings: InkeepBaseSettings;
Expand All @@ -17,6 +28,7 @@ type InkeepSharedSettings = {

const useInkeepSettings = (): InkeepSharedSettings => {
const { resolvedTheme } = useTheme();
const posthog = usePostHog();

const baseSettings: InkeepBaseSettings = {
apiKey: process.env.NEXT_PUBLIC_INKEEP_API_KEY!,
Expand All @@ -28,6 +40,7 @@ const useInkeepSettings = (): InkeepSharedSettings => {
colorMode: {
forcedColorMode: resolvedTheme, // to sync dark mode with the widget
},
logEventCallback: (event) => customAnalyticsCallback(event, posthog),
theme: {
components: {
SearchBarTrigger: {
Expand All @@ -52,25 +65,25 @@ const useInkeepSettings = (): InkeepSharedSettings => {
// optional settings
chatSubjectName: "Langfuse",
botAvatarSrcUrl: "/icon256.png", // use your own bot avatar
// includeAIAnnotations: {
// shouldEscalateToSupport: true,
// },
// aiAnnotationPolicies: {
// shouldEscalateToSupport: [
// {
// threshold: "STANDARD", // "STRICT" or "STANDARD"
// action: {
// type: "SHOW_SUPPORT_BUTTON",
// label: "Contact Support",
// icon: { builtIn: "LuUsers" },
// action: {
// type: "INVOKE_CALLBACK",
// callback: () => openChat(),
// },
// },
// },
// ],
// },
includeAIAnnotations: {
shouldEscalateToSupport: true,
},
aiAnnotationPolicies: {
shouldEscalateToSupport: [
{
threshold: "STANDARD", // "STRICT" or "STANDARD"
action: {
type: "SHOW_SUPPORT_BUTTON",
label: "Contact Support",
icon: { builtIn: "LuUsers" },
action: {
type: "INVOKE_CALLBACK",
callback: () => openChat(),
},
},
},
],
},
getHelpCallToActions: [
{
name: "Chat with us",
Expand Down