Skip to content

Commit

Permalink
fix: send chat id with analytics events (#154)
Browse files Browse the repository at this point in the history
  • Loading branch information
mantagen authored Sep 25, 2024
1 parent bd2d2eb commit 7d201d1
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 19 deletions.
8 changes: 7 additions & 1 deletion apps/nextjs/src/app/aila/[id]/download/DownloadView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type DownloadViewProps = Readonly<{
chat: AilaPersistedChat;
}>;
export function DownloadView({ chat }: Readonly<DownloadViewProps>) {
const { lessonPlan } = chat;
const { lessonPlan, id } = chat;
const {
lessonSlidesExport,
worksheetExport,
Expand Down Expand Up @@ -82,6 +82,7 @@ export function DownloadView({ chat }: Readonly<DownloadViewProps>) {
>
<Flex direction="column" className="gap-14">
<DownloadButton
chatId={id}
onClick={() => lessonPlanExport.start()}
title="Lesson plan"
subTitle="Overview of the complete lesson"
Expand All @@ -93,6 +94,7 @@ export function DownloadView({ chat }: Readonly<DownloadViewProps>) {
lesson={lessonPlan}
/>
<DownloadButton
chatId={id}
onClick={() => starterQuizExport.start()}
title="Starter quiz"
subTitle="Questions and answers to assess prior knowledge"
Expand All @@ -103,6 +105,7 @@ export function DownloadView({ chat }: Readonly<DownloadViewProps>) {
lesson={lessonPlan}
/>
<DownloadButton
chatId={id}
onClick={() => lessonSlidesExport.start()}
data-testid="chat-download-slides-btn"
title="Slide deck"
Expand All @@ -114,6 +117,7 @@ export function DownloadView({ chat }: Readonly<DownloadViewProps>) {
lesson={lessonPlan}
/>
<DownloadButton
chatId={id}
onClick={() => worksheetExport.start()}
title="Worksheet"
subTitle="Practice tasks"
Expand All @@ -124,6 +128,7 @@ export function DownloadView({ chat }: Readonly<DownloadViewProps>) {
exportsType="worksheet"
/>
<DownloadButton
chatId={id}
onClick={() => exitQuizExport.start()}
title="Exit quiz"
subTitle="Questions and answers to assess understanding"
Expand All @@ -136,6 +141,7 @@ export function DownloadView({ chat }: Readonly<DownloadViewProps>) {
{lessonPlan.additionalMaterials &&
lessonPlan.additionalMaterials !== "None" && (
<DownloadButton
chatId={id}
onClick={() => additionalMaterialsExport.start()}
title="Additional materials"
subTitle="Document containing any additional materials"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const ShareChat = ({
const attemptToShareChat = async () => {
track.lessonPlanShared({
...getLessonTrackingProps({ lesson }),
chatId,
componentType: "go_to_share_page_button",
});
if (isShared) {
Expand Down
3 changes: 3 additions & 0 deletions apps/nextjs/src/components/DownloadButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import QuizIcon from "./SVGParts/QuizIcon";
import SlidesIcon from "./SVGParts/SlidesIcon";

export const DownloadButton = ({
chatId,
onClick,
lesson,
title,
Expand All @@ -28,6 +29,7 @@ export const DownloadButton = ({
exportsType,
"data-testid": dataTestId,
}: {
chatId: string;
onClick: () => void;
lesson: LooseLessonPlan;
title: string;
Expand All @@ -51,6 +53,7 @@ export const DownloadButton = ({

function trackDownload(resourceFileType: ResourceFileTypeValueType) {
track.lessonPlanResourcesDownloaded({
chatId,
...getLessonTrackingProps({ lesson }),
resourceType: [analyticsResourceType],
resourceFileType,
Expand Down
3 changes: 2 additions & 1 deletion apps/nextjs/src/lib/analytics/lessonPlanTrackingContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const lessonPlanTrackingContext =

const LessonPlanTrackingProvider: FC<{
children?: React.ReactNode;
chatId?: string;
chatId: string;
}> = ({ children, chatId }) => {
const { track } = useAnalytics();
const [action, setAction] = useState<UserAction | null>(null);
Expand All @@ -51,6 +51,7 @@ const LessonPlanTrackingProvider: FC<{
}
const isFirstMessage = messages.length === 2;
trackLessonPlanRefined({
chatId,
prevLesson,
nextLesson,
ailaMessageContent,
Expand Down
6 changes: 6 additions & 0 deletions apps/nextjs/src/lib/analytics/trackLessonPlanRefined.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ function actionToComponentType(
* changes, we still need to track the lesson plan as it progresses.
*/
export function trackLessonPlanRefined({
chatId,
prevLesson,
nextLesson,
userMessageContent,
Expand All @@ -53,6 +54,7 @@ export function trackLessonPlanRefined({
track,
action,
}: {
chatId: string;
prevLesson: LooseLessonPlan;
nextLesson: LooseLessonPlan;
userMessageContent: string;
Expand All @@ -75,6 +77,7 @@ export function trackLessonPlanRefined({
if (isFirstMessage) {
track.lessonPlanInitiated({
...getLessonTrackingProps({ lesson: nextLesson }),
chatId,
moderatedContentType: getModerationTypes(moderation),
text: userMessageContent,
componentType,
Expand All @@ -89,6 +92,7 @@ export function trackLessonPlanRefined({
);
track.lessonPlanRefined({
...getLessonTrackingProps({ lesson: nextLesson }),
chatId,
moderatedContentType: getModerationTypes(moderation),
text: userMessageContent,
componentType: isSelectingOakLesson ? "select_oak_lesson" : componentType,
Expand All @@ -104,6 +108,7 @@ export function trackLessonPlanRefined({
if (!isLessonComplete(prevLesson) && isLessonComplete(nextLesson)) {
track.lessonPlanCompleted({
...getLessonTrackingProps({ lesson: nextLesson }),
chatId,
moderatedContentType: getModerationTypes(moderation),
});
}
Expand All @@ -113,6 +118,7 @@ export function trackLessonPlanRefined({
const isTerminated = accountLocked || (moderation && isToxic(moderation));
if (isTerminated) {
track.lessonPlanTerminated({
chatId,
isUserBlocked: accountLocked,
isToxicContent: moderation ? isToxic(moderation) : false,
isThreatDetected: false, // @fixme currently we can't access threat detection here
Expand Down
Loading

0 comments on commit 7d201d1

Please sign in to comment.