diff --git a/www/apps/api-reference/components/Feedback/index.tsx b/www/apps/api-reference/components/Feedback/index.tsx index ecac5f34b8..083b285acf 100644 --- a/www/apps/api-reference/components/Feedback/index.tsx +++ b/www/apps/api-reference/components/Feedback/index.tsx @@ -1,23 +1,24 @@ "use client" -import { Feedback as UiFeedback, FeedbackProps } from "docs-ui" -import { usePathname } from "next/navigation" +import { + Feedback as UiFeedback, + FeedbackProps, + DocsTrackingEvents, +} from "docs-ui" import { useArea } from "../../providers/area" export const Feedback = (props: Partial) => { - const pathname = usePathname() const { area } = useArea() return ( ) } diff --git a/www/apps/book/components/Feedback/index.tsx b/www/apps/book/components/Feedback/index.tsx index a7926f57a2..bd25d24ac6 100644 --- a/www/apps/book/components/Feedback/index.tsx +++ b/www/apps/book/components/Feedback/index.tsx @@ -1,24 +1,17 @@ "use client" import { + DocsTrackingEvents, Feedback as UiFeedback, FeedbackProps as UiFeedbackProps, } from "docs-ui" -import { usePathname } from "next/navigation" -import { basePathUrl } from "../../utils/base-path-url" -import { useMemo } from "react" type FeedbackProps = Omit const Feedback = (props: FeedbackProps) => { - const pathname = usePathname() - - const feedbackPathname = useMemo(() => basePathUrl(pathname), [pathname]) - return ( diff --git a/www/apps/cloud/components/Feedback/index.tsx b/www/apps/cloud/components/Feedback/index.tsx index 345e93244c..20231a708d 100644 --- a/www/apps/cloud/components/Feedback/index.tsx +++ b/www/apps/cloud/components/Feedback/index.tsx @@ -1,24 +1,17 @@ "use client" import { + DocsTrackingEvents, Feedback as UiFeedback, FeedbackProps as UiFeedbackProps, } from "docs-ui" -import { usePathname } from "next/navigation" -import { basePathUrl } from "../../utils/base-path-url" -import { useMemo } from "react" type FeedbackProps = Omit const Feedback = (props: FeedbackProps) => { - const pathname = usePathname() - - const feedbackPathname = useMemo(() => basePathUrl(pathname), [pathname]) - return ( diff --git a/www/apps/resources/components/Feedback/index.tsx b/www/apps/resources/components/Feedback/index.tsx index 77cc4fdc0b..dfb6cefedd 100644 --- a/www/apps/resources/components/Feedback/index.tsx +++ b/www/apps/resources/components/Feedback/index.tsx @@ -1,24 +1,17 @@ "use client" import { + DocsTrackingEvents, Feedback as UiFeedback, FeedbackProps as UiFeedbackProps, } from "docs-ui" -import { usePathname } from "next/navigation" -import { useMemo } from "react" -import { basePathUrl } from "../../utils/base-path-url" type FeedbackProps = Omit export const Feedback = (props: FeedbackProps) => { - const pathname = usePathname() - - const feedbackPathname = useMemo(() => basePathUrl(pathname), [pathname]) - return ( diff --git a/www/apps/ui/components/Feedback/index.tsx b/www/apps/ui/components/Feedback/index.tsx index 345e93244c..20231a708d 100644 --- a/www/apps/ui/components/Feedback/index.tsx +++ b/www/apps/ui/components/Feedback/index.tsx @@ -1,24 +1,17 @@ "use client" import { + DocsTrackingEvents, Feedback as UiFeedback, FeedbackProps as UiFeedbackProps, } from "docs-ui" -import { usePathname } from "next/navigation" -import { basePathUrl } from "../../utils/base-path-url" -import { useMemo } from "react" type FeedbackProps = Omit const Feedback = (props: FeedbackProps) => { - const pathname = usePathname() - - const feedbackPathname = useMemo(() => basePathUrl(pathname), [pathname]) - return ( diff --git a/www/apps/user-guide/components/Feedback/index.tsx b/www/apps/user-guide/components/Feedback/index.tsx index 345e93244c..20231a708d 100644 --- a/www/apps/user-guide/components/Feedback/index.tsx +++ b/www/apps/user-guide/components/Feedback/index.tsx @@ -1,24 +1,17 @@ "use client" import { + DocsTrackingEvents, Feedback as UiFeedback, FeedbackProps as UiFeedbackProps, } from "docs-ui" -import { usePathname } from "next/navigation" -import { basePathUrl } from "../../utils/base-path-url" -import { useMemo } from "react" type FeedbackProps = Omit const Feedback = (props: FeedbackProps) => { - const pathname = usePathname() - - const feedbackPathname = useMemo(() => basePathUrl(pathname), [pathname]) - return ( diff --git a/www/packages/docs-ui/src/components/AiAssistant/ChatWindow/Input/index.tsx b/www/packages/docs-ui/src/components/AiAssistant/ChatWindow/Input/index.tsx index fd0c92b20b..477627a538 100644 --- a/www/packages/docs-ui/src/components/AiAssistant/ChatWindow/Input/index.tsx +++ b/www/packages/docs-ui/src/components/AiAssistant/ChatWindow/Input/index.tsx @@ -1,10 +1,15 @@ import React, { useEffect, useMemo, useRef } from "react" import clsx from "clsx" import { ArrowUpCircleSolid, LightBulb, LightBulbSolid } from "@medusajs/icons" -import { useAiAssistant, useIsBrowser } from "../../../../providers" +import { + useAiAssistant, + useAnalytics, + useIsBrowser, +} from "../../../../providers" import { useChat, useDeepThinking } from "@kapaai/react-sdk" import { useAiAssistantChatNavigation } from "../../../../hooks" import { Tooltip } from "../../../Tooltip" +import { DocsTrackingEvents } from "../../../../constants" type AiAssistantChatWindowInputProps = { chatWindowRef: React.RefObject @@ -16,6 +21,7 @@ export const AiAssistantChatWindowInput = ({ const { chatOpened, inputRef, loading, setChatOpened, isCaptchaLoaded } = useAiAssistant() const { submitQuery, conversation } = useChat() + const { track } = useAnalytics() const { active, toggle } = useDeepThinking() const { isBrowser } = useIsBrowser() const { searchQuery, searchQueryType } = useMemo(() => { @@ -38,6 +44,13 @@ export const AiAssistantChatWindowInput = ({ ) => { e?.preventDefault() submitQuery(overrideQuestion || question) + if (!conversation.length) { + track({ + event: { + event: DocsTrackingEvents.AI_ASSISTANT_START_CHAT, + }, + }) + } setQuestion("") } diff --git a/www/packages/docs-ui/src/components/CodeBlock/Actions/Copy/index.tsx b/www/packages/docs-ui/src/components/CodeBlock/Actions/Copy/index.tsx index 935b42301c..8ab206df26 100644 --- a/www/packages/docs-ui/src/components/CodeBlock/Actions/Copy/index.tsx +++ b/www/packages/docs-ui/src/components/CodeBlock/Actions/Copy/index.tsx @@ -1,7 +1,7 @@ "use client" import React, { useEffect, useState } from "react" -import { CopyButton } from "../../../.." +import { CopyButton, DocsTrackingEvents, useAnalytics } from "../../../.." import clsx from "clsx" import { CheckMini, SquareTwoStack } from "@medusajs/icons" @@ -15,6 +15,7 @@ export const CodeBlockCopyAction = ({ inHeader, }: CodeBlockCopyActionProps) => { const [copied, setCopied] = useState(false) + const { track } = useAnalytics() useEffect(() => { if (copied) { @@ -22,6 +23,12 @@ export const CodeBlockCopyAction = ({ setCopied(false) }, 1000) } + + track({ + event: { + event: DocsTrackingEvents.CODE_BLOCK_COPY, + }, + }) }, [copied]) const iconClassName = [ diff --git a/www/packages/docs-ui/src/components/CodeBlock/index.tsx b/www/packages/docs-ui/src/components/CodeBlock/index.tsx index a5af122df4..8d2d10508c 100644 --- a/www/packages/docs-ui/src/components/CodeBlock/index.tsx +++ b/www/packages/docs-ui/src/components/CodeBlock/index.tsx @@ -4,13 +4,13 @@ import React, { useEffect, useMemo, useRef, useState } from "react" import clsx from "clsx" import { Highlight, HighlightProps, themes, Token } from "prism-react-renderer" import { ApiRunner } from "@/components" -import { useColorMode } from "@/providers" +import { useAnalytics, useColorMode } from "@/providers" import { CodeBlockHeader, CodeBlockHeaderMeta } from "./Header" import { CodeBlockLine } from "./Line" import { ApiAuthType, ApiDataOptions, ApiMethod } from "types" // @ts-expect-error can't install the types package because it doesn't support React v19 import { CSSTransition } from "react-transition-group" -import { useCollapsibleCodeLines } from "../.." +import { DocsTrackingEvents, useCollapsibleCodeLines } from "../.." import { HighlightProps as CollapsibleHighlightProps } from "@/hooks" import { CodeBlockActions, CodeBlockActionsProps } from "./Actions" import { CodeBlockCollapsibleButton } from "./Collapsible/Button" @@ -103,6 +103,7 @@ export const CodeBlock = ({ } const { colorMode } = useColorMode() + const { track } = useAnalytics() const [showTesting, setShowTesting] = useState(false) const codeContainerRef = useRef(null) const codeRef = useRef(null) @@ -296,6 +297,14 @@ export const CodeBlock = ({ ) }, [codeContainerRef.current, codeRef.current]) + const trackCopy = () => { + track({ + event: { + event: DocsTrackingEvents.CODE_BLOCK_COPY, + }, + }) + } + const actionsProps: Omit = useMemo( () => ({ source, @@ -435,6 +444,7 @@ export const CodeBlock = ({ "pl-docs_1", preClassName )} + onCopy={trackCopy} > { - const trackers = Array.isArray(event.tracker) - ? event.tracker - : [event.tracker] + const trackers = !event.tracker + ? [DEFAULT_TRACKER] + : Array.isArray(event.tracker) + ? event.tracker + : [event.tracker] + + event.options = { + url: pathname, + label: document.title, + os: window.navigator.userAgent, + ...event.options, + } + await Promise.all( trackers.map(async (tracker) => { switch (tracker) { @@ -73,7 +87,7 @@ export const AnalyticsProvider = ({ }) ) }, - [trackWithSegment, trackWithPostHog] + [trackWithSegment, trackWithPostHog, pathname] ) const track = ({ event }: { event: TrackedEvent }) => {