Skip to content

Commit

Permalink
📈 send answer in question event (#861)
Browse files Browse the repository at this point in the history
  • Loading branch information
Clemog authored Feb 19, 2025
1 parent 6378b2d commit fb3be26
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 33 deletions.
6 changes: 1 addition & 5 deletions src/components/form/Question.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -109,7 +106,6 @@ export default function Question({
setTempValue(value)
}
setValue(value, { questionDottedName: question })
trackEvent(questionTypeAnswer({ question, answer: value }))
}}
isMissing={isMissing}
min={0}
Expand Down
18 changes: 3 additions & 15 deletions src/components/form/question/mosaic/MosaicQuestion.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -40,14 +37,6 @@ export default function MosaicQuestion({
questionDottedName: parentMosaic,
questionsOfMosaicFromSibling,
})

trackEvent(
questionTypeAnswer({
question: parentMosaic,
answer: parent,
mosaicValue: value,
})
)
}}
parentMosaic={parentMosaic}
index={index}
Expand All @@ -68,9 +57,8 @@ export default function MosaicQuestion({

trackEvent(
questionChooseAnswer({
question: parentMosaic,
answer: parent,
mosaicValue: value,
question: parent,
answer: value,
})
)
}}
Expand Down
7 changes: 6 additions & 1 deletion src/constants/tracking/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]
20 changes: 10 additions & 10 deletions src/constants/tracking/question.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) => [
Expand Down
2 changes: 1 addition & 1 deletion src/design-system/layout/Breadcrumbs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default function Breadcrumbs({
if (isDisabled) {
e.preventDefault()
}
trackEvent(breadcrumbClickLink)
trackEvent(breadcrumbClickLink(href))
}}
aria-current={isActive}
className={twMerge(
Expand Down
1 change: 0 additions & 1 deletion src/utils/analytics/trackEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ declare global {

export const trackEvent = (args: (string | null)[]) => {
if (shouldUseDevTracker || !window?._paq) {
console.log(args)
console.debug(args.join(' => '))
return
}
Expand Down

0 comments on commit fb3be26

Please sign in to comment.