From fb3be26f614ea359d99c294380307e4884a08cb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment?= <55186402+Clemog@users.noreply.github.com> Date: Wed, 19 Feb 2025 10:29:04 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=88=20send=20answer=20in=20question=20?= =?UTF-8?q?event=20(#861)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/form/Question.tsx | 6 +----- .../form/question/mosaic/MosaicQuestion.tsx | 18 +++-------------- src/constants/tracking/layout.ts | 7 ++++++- src/constants/tracking/question.ts | 20 +++++++++---------- src/design-system/layout/Breadcrumbs.tsx | 2 +- src/utils/analytics/trackEvent.ts | 1 - 6 files changed, 21 insertions(+), 33 deletions(-) diff --git a/src/components/form/Question.tsx b/src/components/form/Question.tsx index 2757ecce2..9a2406b6a 100644 --- a/src/components/form/Question.tsx +++ b/src/components/form/Question.tsx @@ -12,10 +12,7 @@ import { DEFAULT_FOCUS_ELEMENT_ID, QUESTION_DESCRIPTION_BUTTON_ID, } from '@/constants/accessibility' -import { - questionChooseAnswer, - questionTypeAnswer, -} from '@/constants/tracking/question' +import { questionChooseAnswer } from '@/constants/tracking/question' import Button from '@/design-system/inputs/Button' import { useRule } from '@/publicodes-state' import { trackEvent } from '@/utils/analytics/trackEvent' @@ -109,7 +106,6 @@ export default function Question({ setTempValue(value) } setValue(value, { questionDottedName: question }) - trackEvent(questionTypeAnswer({ question, answer: value })) }} isMissing={isMissing} min={0} diff --git a/src/components/form/question/mosaic/MosaicQuestion.tsx b/src/components/form/question/mosaic/MosaicQuestion.tsx index 6dee1f160..c8d22a130 100644 --- a/src/components/form/question/mosaic/MosaicQuestion.tsx +++ b/src/components/form/question/mosaic/MosaicQuestion.tsx @@ -1,9 +1,6 @@ 'use client' -import { - questionChooseAnswer, - questionTypeAnswer, -} from '@/constants/tracking/question' +import { questionChooseAnswer } from '@/constants/tracking/question' import { useRule } from '@/publicodes-state' import { trackEvent } from '@/utils/analytics/trackEvent' import type { DottedName } from '@incubateur-ademe/nosgestesclimat' @@ -40,14 +37,6 @@ export default function MosaicQuestion({ questionDottedName: parentMosaic, questionsOfMosaicFromSibling, }) - - trackEvent( - questionTypeAnswer({ - question: parentMosaic, - answer: parent, - mosaicValue: value, - }) - ) }} parentMosaic={parentMosaic} index={index} @@ -68,9 +57,8 @@ export default function MosaicQuestion({ trackEvent( questionChooseAnswer({ - question: parentMosaic, - answer: parent, - mosaicValue: value, + question: parent, + answer: value, }) ) }} diff --git a/src/constants/tracking/layout.ts b/src/constants/tracking/layout.ts index 3d40c54f7..02a0d897a 100644 --- a/src/constants/tracking/layout.ts +++ b/src/constants/tracking/layout.ts @@ -99,4 +99,9 @@ export const footerClickLanguage = (locale: string) => [ ] // Figma comment #18 -export const breadcrumbClickLink = ['trackEvent', 'Breadcrumb', 'Click link'] +export const breadcrumbClickLink = (href: string) => [ + 'trackEvent', + 'Breadcrumb', + 'Click link', + href, +] diff --git a/src/constants/tracking/question.ts b/src/constants/tracking/question.ts index ac89c3d21..a1cd9a2bd 100644 --- a/src/constants/tracking/question.ts +++ b/src/constants/tracking/question.ts @@ -6,7 +6,6 @@ import type { DottedName, NodeValue } from '@incubateur-ademe/nosgestesclimat' type Props = { question: DottedName answer?: DottedName | NodeValue | string - mosaicValue?: NodeValue | string timeSpentOnQuestion?: number } // Figma comment #45 @@ -55,22 +54,23 @@ export const questionClickPrevious = ({ question }: Props) => [ ] // Figma comment #46 -export const questionChooseAnswer = ({ question, mosaicValue }: Props) => [ +export const questionChooseAnswer = ({ question, answer }: Props) => [ 'trackEvent', 'Simulateur', 'Choose Answer', question, - String(mosaicValue), + String(answer), ] // Figma comment #51 -export const questionTypeAnswer = ({ question, mosaicValue }: Props) => [ - 'trackEvent', - 'Simulateur', - 'Type Answer', - question, - String(mosaicValue), -] +// An event is sent on every change of the input, it's too much ! +// export const questionTypeAnswer = ({ question, answer }: Props) => [ +// 'trackEvent', +// 'Simulateur', +// 'Type Answer', +// question, +// String(answer), +// ] // Figma comment #50 export const questionClickSuggestion = ({ question, answer }: Props) => [ diff --git a/src/design-system/layout/Breadcrumbs.tsx b/src/design-system/layout/Breadcrumbs.tsx index cff36d6ba..aeefd6bbb 100644 --- a/src/design-system/layout/Breadcrumbs.tsx +++ b/src/design-system/layout/Breadcrumbs.tsx @@ -30,7 +30,7 @@ export default function Breadcrumbs({ if (isDisabled) { e.preventDefault() } - trackEvent(breadcrumbClickLink) + trackEvent(breadcrumbClickLink(href)) }} aria-current={isActive} className={twMerge( diff --git a/src/utils/analytics/trackEvent.ts b/src/utils/analytics/trackEvent.ts index 12fc19264..6070475fa 100644 --- a/src/utils/analytics/trackEvent.ts +++ b/src/utils/analytics/trackEvent.ts @@ -10,7 +10,6 @@ declare global { export const trackEvent = (args: (string | null)[]) => { if (shouldUseDevTracker || !window?._paq) { - console.log(args) console.debug(args.join(' => ')) return }