Skip to content

[DASH-624] Add tracking in insight playground #5737

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

Merged
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export function CodeBlockContainer(props: {
scrollableContainerClassName?: string;
copyButtonClassName?: string;
shadowColor?: string;
onCopy?: (code: string) => void;
}) {
const { hasCopied, onCopy } = useClipboard(props.codeToCopy);

Expand All @@ -38,7 +39,10 @@ export function CodeBlockContainer(props: {
<Button
size="sm"
variant="outline"
onClick={onCopy}
onClick={() => {
onCopy();
props.onCopy?.(props.codeToCopy);
}}
className={cn(
"absolute top-3.5 right-3.5 h-auto bg-background p-2",
props.copyButtonClassName,
Expand Down
2 changes: 2 additions & 0 deletions apps/dashboard/src/@/components/ui/code/RenderCode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export function RenderCode(props: {
copyButtonClassName?: string;
scrollableContainerClassName?: string;
shadowColor?: string;
onCopy?: (code: string) => void;
}) {
return (
<CodeBlockContainer
Expand All @@ -17,6 +18,7 @@ export function RenderCode(props: {
scrollableClassName={props.scrollableClassName}
scrollableContainerClassName={props.scrollableContainerClassName}
shadowColor={props.shadowColor}
onCopy={props.onCopy}
>
<div
// biome-ignore lint/security/noDangerouslySetInnerHtml: we know what we're doing here
Expand Down
4 changes: 4 additions & 0 deletions apps/dashboard/src/@/components/ui/code/code.client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export type CodeProps = {
scrollableContainerClassName?: string;
shadowColor?: string;
ignoreFormattingErrors?: boolean;
onCopy?: (code: string) => void;
};

export const CodeClient: React.FC<CodeProps> = ({
Expand All @@ -27,6 +28,7 @@ export const CodeClient: React.FC<CodeProps> = ({
ignoreFormattingErrors,
scrollableContainerClassName,
shadowColor,
onCopy,
}) => {
const codeQuery = useQuery({
queryKey: ["html", code],
Expand All @@ -49,6 +51,7 @@ export const CodeClient: React.FC<CodeProps> = ({
copyButtonClassName={copyButtonClassName}
scrollableContainerClassName={scrollableContainerClassName}
shadowColor={shadowColor}
onCopy={onCopy}
/>
);
}
Expand All @@ -62,6 +65,7 @@ export const CodeClient: React.FC<CodeProps> = ({
copyButtonClassName={copyButtonClassName}
scrollableContainerClassName={scrollableContainerClassName}
shadowColor={shadowColor}
onCopy={onCopy}
/>
);
};
2 changes: 2 additions & 0 deletions apps/dashboard/src/@/components/ui/code/plaintext-code.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export function PlainTextCodeBlock(props: {
codeClassName?: string;
scrollableContainerClassName?: string;
shadowColor?: string;
onCopy?: (code: string) => void;
}) {
return (
<CodeBlockContainer
Expand All @@ -18,6 +19,7 @@ export function PlainTextCodeBlock(props: {
scrollableClassName={props.scrollableClassName}
scrollableContainerClassName={props.scrollableContainerClassName}
shadowColor={props.shadowColor}
onCopy={props.onCopy}
>
<code className={cn("block whitespace-pre", props.codeClassName)}>
{props.code}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@ import Link from "next/link";
import { useEffect, useMemo, useState } from "react";
import { type UseFormReturn, useForm } from "react-hook-form";
import { z } from "zod";
import { useTrack } from "../../../../../../hooks/analytics/useTrack";
import { getVercelEnv } from "../../../../../../lib/vercel-utils";
import type { BlueprintParameter, BlueprintPathMetadata } from "../utils";

const trackingCategory = "insightBlueprint";

export function BlueprintPlayground(props: {
metadata: BlueprintPathMetadata;
backLink: string;
Expand Down Expand Up @@ -151,6 +154,7 @@ export function BlueprintPlaygroundUI(props: {
projectSettingsLink: string;
supportedChainIds: number[];
}) {
const trackEvent = useTrack();
const parameters = useMemo(() => {
return modifyParametersForPlayground(props.metadata.parameters);
}, [props.metadata.parameters]);
Expand Down Expand Up @@ -182,6 +186,12 @@ export function BlueprintPlaygroundUI(props: {
intent: "run",
});

trackEvent({
category: trackingCategory,
action: "click",
label: "run",
url: url,
});
props.onRun(url);
}

Expand Down Expand Up @@ -306,6 +316,8 @@ function PlaygroundHeader(props: {
domain: string;
path: string;
}) {
const trackEvent = useTrack();

const [hasCopied, setHasCopied] = useState(false);
return (
<div className="border-b px-4 py-4 lg:flex lg:justify-center lg:py-3">
Expand All @@ -325,6 +337,14 @@ function PlaygroundHeader(props: {
values: props.getFormValues(),
intent: "copy",
});

trackEvent({
category: trackingCategory,
action: "click",
label: "copy-url",
url: url,
});

setTimeout(() => {
setHasCopied(false);
}, 500);
Expand Down Expand Up @@ -561,6 +581,7 @@ function ResponseSection(props: {
| undefined;
abortRequest: () => void;
}) {
const trackEvent = useTrack();
const formattedData = useMemo(() => {
if (!props.response?.data) return undefined;
try {
Expand Down Expand Up @@ -628,6 +649,13 @@ function ResponseSection(props: {
scrollableContainerClassName="h-full"
scrollableClassName="h-full"
shadowColor="hsl(var(--muted)/50%)"
onCopy={() => {
trackEvent({
category: trackingCategory,
action: "click",
label: "copy-response",
});
}}
/>
)}
</div>
Expand Down
Loading