From 1e7af313691a168b44e9b1dbbcb03d7c1fe9f4bd Mon Sep 17 00:00:00 2001
From: eletallbetagouv <107104509+eletallbetagouv@users.noreply.github.com>
Date: Thu, 19 Sep 2024 18:54:54 +0300
Subject: [PATCH 1/2] Revert "Track companyKind in Matomo as a custom
dimension"
This reverts commit 3fa73762f075b077f5fef2315e867ffbce6ac094.
---
website/src/analytic/AnalyticContext.tsx | 2 --
website/src/analytic/analytic.ts | 18 ------------------
.../reportFlow/Problem/Problem.tsx | 16 ++++++----------
3 files changed, 6 insertions(+), 30 deletions(-)
diff --git a/website/src/analytic/AnalyticContext.tsx b/website/src/analytic/AnalyticContext.tsx
index 4df49677e..4929d4a80 100644
--- a/website/src/analytic/AnalyticContext.tsx
+++ b/website/src/analytic/AnalyticContext.tsx
@@ -5,7 +5,6 @@ import {Analytic} from './analytic'
export interface AnalyticContextProps {
trackEvent: Analytic['trackEvent']
trackSearch: Analytic['trackSearch']
- setTrackedCompanyKind: Analytic['setTrackedCompanyKind']
}
interface Props {
@@ -24,7 +23,6 @@ export const AnalyticProvider = ({analytic, children}: Props) => {
// analytics are not available server-side
trackEvent: analytic?.trackEvent ?? (() => {}),
trackSearch: analytic?.trackSearch ?? (() => {}),
- setTrackedCompanyKind: analytic?.setTrackedCompanyKind ?? (() => {}),
}}
>
{children}
diff --git a/website/src/analytic/analytic.ts b/website/src/analytic/analytic.ts
index fe522ef0b..40d8fc37a 100644
--- a/website/src/analytic/analytic.ts
+++ b/website/src/analytic/analytic.ts
@@ -1,7 +1,6 @@
import {appConfig} from '@/core/appConfig'
import {usePathname, useSearchParams} from 'next/navigation'
import {useEffect} from 'react'
-import {CompanyKind} from 'shared/anomalies/Anomaly'
import {Eularian} from '../plugins/eularian'
import {Matomo} from '../plugins/matomo'
@@ -58,23 +57,6 @@ export class Analytic {
}
}
}
-
- readonly setTrackedCompanyKind = (companyKind: CompanyKind) => {
- const customDimensionId = 1
- const args = ['setCustomDimension', customDimensionId, companyKind]
- this.log(...args)
- try {
- // https://developer.matomo.org/guides/tracking-javascript-guide#custom-dimensions
- // This doesn't send anything
- // but should set the custom dimension "companykind" for the events after it
- this.matomo?.push(args)
- } catch (e: any) {
- console.error('[Analytic]', e)
- if (!(e instanceof ReferenceError)) {
- throw e
- }
- }
- }
}
export function PageChangesListener({analytic}: {analytic: Analytic}) {
diff --git a/website/src/components_feature/reportFlow/Problem/Problem.tsx b/website/src/components_feature/reportFlow/Problem/Problem.tsx
index 932328164..94898c1a1 100644
--- a/website/src/components_feature/reportFlow/Problem/Problem.tsx
+++ b/website/src/components_feature/reportFlow/Problem/Problem.tsx
@@ -1,10 +1,10 @@
-import {AnalyticContextProps, useAnalyticContext} from '@/analytic/AnalyticContext'
+import {useAnalyticContext} from '@/analytic/AnalyticContext'
import {EventCategories, ReportEventActions} from '@/analytic/analytic'
import {NextStepButton} from '@/components_feature/reportFlow/reportFlowStepper/NextStepButton'
import {StepNavigation} from '@/components_feature/reportFlow/reportFlowStepper/ReportFlowStepper'
import {OpenFfWelcomeText, useOpenFfSetupLoaded as useHandleOpenFfSetupLoaded, useOpenFfSetup} from '@/feature/openFoodFacts'
import {RappelConsoWelcome, useHandleRcSetupLoaded, useRappelConsoSetup} from '@/feature/rappelConso'
-import {getCompanyKind, hasStep0, hasStep1Full} from '@/feature/reportUtils'
+import {hasStep0, hasStep1Full} from '@/feature/reportUtils'
import {initiateReport} from '@/feature/reportUtils2'
import {useI18n} from '@/i18n/I18n'
import {Step2Model} from '@/model/Step2Model'
@@ -41,7 +41,6 @@ export function Problem({anomaly, isWebView, stepNavigation}: Props) {
}
function ProblemInner({anomaly, isWebView, stepNavigation}: Props) {
- const _analytic = useAnalyticContext()
const {report, setReport, sendReportEvent} = useReportFlowContext()
if (!hasStep0(report)) {
throw new Error('Report should have a lang and a category already (in Problem)')
@@ -51,7 +50,7 @@ function ProblemInner({anomaly, isWebView, stepNavigation}: Props) {
useHandleOpenFfSetupLoaded(openFfSetup, setReport)
useHandleRcSetupLoaded(rappelConsoSetup, setReport)
const specialCategoriesNotLoading = openFfSetup.status !== 'loading' && rappelConsoSetup.status !== 'loading'
- const onNext = buildOnNext({sendReportEvent, setReport, stepNavigation, _analytic})
+ const onNext = buildOnNext({sendReportEvent, setReport, stepNavigation})
return (
<>
@@ -75,19 +74,16 @@ function buildOnNext({
setReport: setReport,
stepNavigation,
sendReportEvent,
- _analytic,
}: {
setReport: SetReport
stepNavigation: StepNavigation
sendReportEvent: SendReportEvent
- _analytic: AnalyticContextProps
}) {
- return function (next: () => void): void {
+ return function onNext(next: () => void): void {
setReport(draft => {
- if (!hasStep0(draft) || !hasStep1Full(draft)) {
- throw new Error(`Report is not ready to go to step2`)
+ if (!hasStep1Full(draft)) {
+ throw new Error(`Report is not ready to go to next step, step1 is not full`)
}
- _analytic.setTrackedCompanyKind(getCompanyKind(draft))
// In the openFf scenario
// Only if we got all the data, then we build the company/product from it.
// If we only have partial data, then we will build it in step 2.
From f2f0ac74688b6efc03fad21d59dc50cc4695ab87 Mon Sep 17 00:00:00 2001
From: eletallbetagouv <107104509+eletallbetagouv@users.noreply.github.com>
Date: Thu, 19 Sep 2024 18:55:01 +0300
Subject: [PATCH 2/2] Revert "Add search tracking in Matomo"
This reverts commit 3655c27bc72482b18c6cf3d6db460aeeb9dd7e88.
---
website/src/analytic/AnalyticContext.tsx | 8 +++----
website/src/analytic/analytic.ts | 22 +-----------------
.../Company/CompanySearchByIdentifier.tsx | 6 ++---
.../Company/CompanySearchByName.tsx | 23 ++++++++-----------
.../CompanySearchByNameAndPostalCode.tsx | 7 ++----
.../CompanySmartIdentification.tsx | 6 +----
6 files changed, 20 insertions(+), 52 deletions(-)
diff --git a/website/src/analytic/AnalyticContext.tsx b/website/src/analytic/AnalyticContext.tsx
index 4929d4a80..ccaf43ba3 100644
--- a/website/src/analytic/AnalyticContext.tsx
+++ b/website/src/analytic/AnalyticContext.tsx
@@ -4,7 +4,6 @@ import {Analytic} from './analytic'
export interface AnalyticContextProps {
trackEvent: Analytic['trackEvent']
- trackSearch: Analytic['trackSearch']
}
interface Props {
@@ -20,9 +19,10 @@ export const AnalyticProvider = ({analytic, children}: Props) => {
return (
{}),
- trackSearch: analytic?.trackSearch ?? (() => {}),
+ trackEvent:
+ analytic?.trackEvent ??
+ // analytics are not available server-side
+ ((...args: any[]) => {}),
}}
>
{children}
diff --git a/website/src/analytic/analytic.ts b/website/src/analytic/analytic.ts
index 40d8fc37a..f8141a1b9 100644
--- a/website/src/analytic/analytic.ts
+++ b/website/src/analytic/analytic.ts
@@ -11,7 +11,7 @@ export class Analytic {
return new Analytic(matomo, eularian)
}
- private log = (...args: unknown[]) => {
+ private log = (...args: (string | undefined)[]) => {
console.debug('[Analytic]', ...args)
}
@@ -37,26 +37,6 @@ export class Analytic {
}
}
}
-
- readonly trackSearch = (
- inputs: {q: string; postalCode?: string; departmentCode?: string},
- searchCategory: 'companysearch_smart' | 'companysearch_nameandpostalcode' | 'companysearch_name' | 'companysearch_siret',
- nbResults: number,
- ) => {
- const {q, postalCode, departmentCode} = inputs
- const trackedSearch = `${postalCode ? `[${postalCode}] ` : ''}${departmentCode ? `[${departmentCode}] ` : ''}${q}`
- const args = ['[trackSiteSearch]', trackedSearch, searchCategory, nbResults]
- this.log(...args)
- try {
- // https://developer.matomo.org/guides/tracking-javascript-guide#internal-search-tracking
- this.matomo?.push(args)
- } catch (e: any) {
- console.error('[Analytic]', e)
- if (!(e instanceof ReferenceError)) {
- throw e
- }
- }
- }
}
export function PageChangesListener({analytic}: {analytic: Analytic}) {
diff --git a/website/src/components_feature/reportFlow/Company/CompanySearchByIdentifier.tsx b/website/src/components_feature/reportFlow/Company/CompanySearchByIdentifier.tsx
index 520a5a410..fd5c7bb18 100644
--- a/website/src/components_feature/reportFlow/Company/CompanySearchByIdentifier.tsx
+++ b/website/src/components_feature/reportFlow/Company/CompanySearchByIdentifier.tsx
@@ -39,11 +39,9 @@ export const CompanySearchByIdentifier = ({children}: Props) => {
const [submittedIdentity, setSubmittedIdentity] = useState(undefined)
const _searchByIdentity = useQuery({
queryKey: ['searchCompaniesByIdentity', submittedIdentity],
- queryFn: async () => {
+ queryFn: () => {
if (submittedIdentity) {
- const res = await companyApiClient.searchCompaniesByIdentity(submittedIdentity, false, currentLang)
- _analytic.trackSearch({q: submittedIdentity}, 'companysearch_siret', res.length)
- return res
+ return companyApiClient.searchCompaniesByIdentity(submittedIdentity, false, currentLang)
}
return null
},
diff --git a/website/src/components_feature/reportFlow/Company/CompanySearchByName.tsx b/website/src/components_feature/reportFlow/Company/CompanySearchByName.tsx
index 4b2266c94..8472560a3 100644
--- a/website/src/components_feature/reportFlow/Company/CompanySearchByName.tsx
+++ b/website/src/components_feature/reportFlow/Company/CompanySearchByName.tsx
@@ -1,17 +1,17 @@
+import {CompanySearchResult} from '@/model/Company'
+import {ReactNode, useState} from 'react'
+import {useI18n} from '@/i18n/I18n'
+import {useApiClients} from '@/context/ApiClientsContext'
+import {useQuery} from '@tanstack/react-query'
+import {useToastOnQueryError} from '@/clients/apiHooks'
import {useAnalyticContext} from '@/analytic/AnalyticContext'
+import {useForm} from 'react-hook-form'
import {CompanySearchEventActions, EventCategories} from '@/analytic/analytic'
-import {useToastOnQueryError} from '@/clients/apiHooks'
import {Animate} from '@/components_simple/Animate'
import {RequiredFieldsLegend} from '@/components_simple/RequiredFieldsLegend'
-import {ButtonWithLoader} from '@/components_simple/buttons/Buttons'
import {ScTextInput} from '@/components_simple/formInputs/ScTextInput'
-import {useApiClients} from '@/context/ApiClientsContext'
-import {useI18n} from '@/i18n/I18n'
-import {CompanySearchResult} from '@/model/Company'
+import {ButtonWithLoader} from '@/components_simple/buttons/Buttons'
import {ifDefined} from '@/utils/utils'
-import {useQuery} from '@tanstack/react-query'
-import {ReactNode, useState} from 'react'
-import {useForm} from 'react-hook-form'
interface Form {
name: string
@@ -27,12 +27,9 @@ export const CompanySearchByName = ({children}: Props) => {
const [submittedForm, setSubmittedForm] = useState