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

[Feature] Add telemetry for preview change #553

Merged
merged 6 commits into from
Dec 24, 2024
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
2 changes: 2 additions & 0 deletions js/src/components/lineage/NodeView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import { is } from "date-fns/locale";
import { run } from "node:test";
import { DisableTooltipMessages } from "@/constants/tooltipMessage";
import { PreviewChangeView } from "./PreviewChangeView";
import { trackPreviewChange } from "@/lib/api/track";

interface NodeViewProps {
node: LineageGraphNode;
Expand Down Expand Up @@ -154,6 +155,7 @@ export function NodeView({ node, onCloseNode }: NodeViewProps) {
);
}
onPreviewChangeOpen();
trackPreviewChange({ action: "explore", node: node.name });
}}
>
Preview Change (Experiment)
Expand Down
34 changes: 29 additions & 5 deletions js/src/components/lineage/PreviewChangeView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ import { useFeedbackCollectionToast } from "@/lib/hooks/useFeedbackCollectionToa
import { VscFeedback } from "react-icons/vsc";
import { localStorageKeys } from "@/lib/api/localStorageKeys";
import { useRecceQueryContext } from "@/lib/hooks/RecceQueryContext";
import {
trackPreviewChange,
trackPreviewChangeFeedback,
} from "@/lib/api/track";

interface PreviewChangeViewProps {
isOpen: boolean;
Expand Down Expand Up @@ -148,7 +152,6 @@ export function PreviewChangeView({
const queryFn = async () => {
const sqlTemplate = modifiedCode;
const runFn = submitQueryDiff;
console.log(primaryKeys);
const params: QueryParams = {
current_model: current?.name || "",
primary_keys: primaryKeys,
Expand All @@ -164,19 +167,39 @@ export function PreviewChangeView({
};
const { mutate: runQuery, isPending } = useMutation({
mutationFn: queryFn,
onSuccess(data, variables) {
if (data.error) {
trackPreviewChange({
action: "run",
node: current?.name,
status: "failure",
});
} else {
trackPreviewChange({
action: "run",
node: current?.name,
status: "success",
});
}
},
});
const { feedbackToast, closeToast } = useFeedbackCollectionToast({
feedbackId: localStorageKeys.previewChangeFeedbackID,
description: "Enjoy preview change?",

onFeedbackSubmit: (feedback: string) => {
switch (feedback) {
case "like":
console.log("Like");
// TODO: track feedback result
trackPreviewChangeFeedback({ feedback: "like", node: current?.name });
break;
case "dislike":
console.log("Dislike");
// TODO: track feedback result
trackPreviewChangeFeedback({
feedback: "dislike",
node: current?.name,
});
break;
case "link":
trackPreviewChangeFeedback({ feedback: "form", node: current?.name });
break;
default:
console.log("Not support feedback type");
Expand All @@ -196,6 +219,7 @@ export function PreviewChangeView({
onRunResultClose();
clearRunResult();
closeToast();
trackPreviewChange({ action: "close", node: current?.name });
}}
>
{/* <ModalOverlay /> */}
Expand Down
19 changes: 19 additions & 0 deletions js/src/lib/api/track.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,22 @@ interface HistoryActionProps {
export function trackHistoryAction(props: HistoryActionProps) {
amplitude.track("[Web] history_action", props);
}

interface PreviewChangeProps {
action: "explore" | "run" | "close";
node?: string;
status?: "success" | "failure";
}

export function trackPreviewChange(props: PreviewChangeProps) {
amplitude.track("[Experiment] preview_change", props);
}

interface PreviewChangeFeedbackProps {
feedback: "like" | "dislike" | "form";
node?: string;
}

export function trackPreviewChangeFeedback(props: PreviewChangeFeedbackProps) {
amplitude.track("[Experiment] preview_change", props);
}
12 changes: 11 additions & 1 deletion js/src/lib/hooks/useFeedbackCollectionToast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ function ReactionFeedback({
description,
onLike,
onDislike,
onClickLink,
externalLink,
externalLinkText,
}: {
description: string;
onLike: () => void;
onDislike: () => void;
onClickLink: () => void;
externalLink?: string;
externalLinkText?: string;
}) {
Expand Down Expand Up @@ -48,7 +50,12 @@ function ReactionFeedback({
onClick={onDislike}
/>
{externalLink && externalLinkText && (
<Link href={externalLink} isExternal textDecoration="underline">
<Link
href={externalLink}
isExternal
textDecoration="underline"
onClick={onClickLink}
>
{externalLinkText}
</Link>
)}
Expand Down Expand Up @@ -113,6 +120,9 @@ export function useFeedbackCollectionToast(options: {
}}
externalLink={externalLink}
externalLinkText={externalLinkText}
onClickLink={() => {
onFeedbackSubmit("link");
}}
/>
<CloseButton onClick={onClose} />
</HStack>
Expand Down
Loading