diff --git a/.talismanrc b/.talismanrc index 496404a86..7a91949fd 100644 --- a/.talismanrc +++ b/.talismanrc @@ -3,12 +3,16 @@ fileignoreconfig: checksum: f7719ba0d36160d97e80ee15cb5415b601354576929e36df0596c7d192465cfb - filename: README.md checksum: df312ccb4c75fc4c2441a1f7f2c7817ee98ffb3065c78d5d7d6addf6ab129176 +- filename: frontend/.env.example + checksum: 7e2a5ff197c49ff9f715b3d189da7282bdb40de53ea49735e9f183ece19168fc - filename: frontend/src/components/Draft/DraftSender.tsx checksum: cfcc1023edac4d29c305f00a4bd86f27d491e4e9535bec2bd905a917b3f396b7 - filename: frontend/src/components/Draft/DraftSignature.tsx checksum: 8abd2b819601d46cc6a3d0a61a60b76391601f2d89d9126f5167b684878bd2d1 - filename: frontend/src/index.tsx checksum: 25a58ba4ecfb8606daf5efbae6a1f0f2efe4e87a4a8a18e745712b39198d93a5 +- filename: frontend/src/utils/config.ts + checksum: 2916d5a89dbd4b6425e9b6980e235007cb0f09a3dd0f2cc8b49f43c0e79d5d5f - filename: packages/api-sdk/src/test/campaign-api.test.ts checksum: b200d9e1fec310660a91e99cd048b24cbe983e0f9f965861d061a7f0992af43e - filename: packages/healthcheck/src/checks/brevo.ts diff --git a/frontend/.env.example b/frontend/.env.example index 5b1de3bad..d4f453086 100644 --- a/frontend/.env.example +++ b/frontend/.env.example @@ -1,3 +1,5 @@ REACT_APP_API_URL=http://localhost:3001 REACT_APP_METABASE_STATS_DASHBOARD=UUID REACT_APP_FEATURE_OCCUPANCY=ct1,ct2,ct3 +REACT_APP_POSTHOG_ENABLED=false +REACT_APP_POSTHOG_API_KEY=key diff --git a/frontend/src/components/HousingListFilters/HousingListFiltersSidemenu.tsx b/frontend/src/components/HousingListFilters/HousingListFiltersSidemenu.tsx index 80d49b9ad..88f4725f7 100644 --- a/frontend/src/components/HousingListFilters/HousingListFiltersSidemenu.tsx +++ b/frontend/src/components/HousingListFilters/HousingListFiltersSidemenu.tsx @@ -6,6 +6,7 @@ import { CSSObject, styled, Theme } from '@mui/material/styles'; import Grid from '@mui/material/Unstable_Grid2'; import Typography from '@mui/material/Typography'; import classNames from 'classnames'; +import posthog from 'posthog-js'; import { isDefined } from '@zerologementvacant/utils'; import { Icon, SearchableSelect, Text } from '../_dsfr'; @@ -223,10 +224,10 @@ function HousingListFiltersSidemenu(props: Props) { label="Sous-statut de suivi" options={getSubStatusListOptions(filters.statusList ?? [])} initialValues={filters.subStatus} - onChange={(values) => - onChangeFilters({ subStatus: values }, 'Sous-statut') - } - data-testid="filtre-sous-statut-suivi" + onChange={(values) => { + onChangeFilters({ subStatus: values }, 'Sous-statut'); + posthog.capture('filtre-sous-statut-suivi'); + }} /> {campaigns && ( @@ -234,10 +235,10 @@ function HousingListFiltersSidemenu(props: Props) { ) => - onChangeFilters({ campaignIds: values }, 'Campagne') - } - data-testid="filtre-campagne" + onChange={(values: Array) => { + onChangeFilters({ campaignIds: values }, 'Campagne'); + posthog.capture('filtre-campagne'); + }} /> )} @@ -246,10 +247,10 @@ function HousingListFiltersSidemenu(props: Props) { label="Prise de contact" options={campaignsCountOptions} initialValues={filters.campaignsCounts} - onChange={(values) => - onChangeFilters({ campaignsCounts: values }, 'Prise de contact') - } - data-testid="filtre-prise-de-contact" + onChange={(values) => { + onChangeFilters({ campaignsCounts: values }, 'Prise de contact'); + posthog.capture('filtre-prise-de-contact'); + }} /> @@ -266,10 +267,10 @@ function HousingListFiltersSidemenu(props: Props) { label="Statut d’occupation" options={allOccupancyOptions} initialValues={filters.occupancies} - onChange={(values) => - onChangeFilters({ occupancies: values }, 'Statut d’occupation') - } - data-testid="filtre-statut-occupation" + onChange={(values) => { + onChangeFilters({ occupancies: values }, 'Statut d’occupation'); + posthog.capture('filtre-statut-occupation'); + }} /> {filters?.occupancies?.includes(Occupancy.VACANT) && ( @@ -319,6 +320,7 @@ function HousingListFiltersSidemenu(props: Props) { { intercommunalities: values.map((value) => value.id) }, 'Intercommunalité' ); + posthog.capture('filtre-intercommunalite'); } } }} @@ -328,7 +330,6 @@ function HousingListFiltersSidemenu(props: Props) { placeholder: 'Rechercher une intercommunalité' } }} - data-testid="filtre-commune" /> @@ -342,9 +343,9 @@ function HousingListFiltersSidemenu(props: Props) { { localities: concat(filters.localities, value) }, 'Commune' ); + posthog.capture('filtre-commune'); } }} - data-testid="filtre-commune" /> @@ -352,10 +353,10 @@ function HousingListFiltersSidemenu(props: Props) { label="Type de commune" options={localityKindsOptions} initialValues={filters.localityKinds} - onChange={(values) => - onChangeFilters({ localityKinds: values }, 'Type de commune') - } - data-testid="filtre-type-de-commune" + onChange={(values) => { + onChangeFilters({ localityKinds: values }, 'Type de commune'); + posthog.capture('filtre-commune'); + }} /> @@ -377,9 +378,9 @@ function HousingListFiltersSidemenu(props: Props) { }, 'Périmètre inclus' ); + posthog.capture('filtre-perimetre-inclus'); } }} - data-testid="filtre-perimetre-inclus" /> @@ -401,9 +402,9 @@ function HousingListFiltersSidemenu(props: Props) { }, 'Périmètre exclu' ); + posthog.capture('filtre-perimetre-exclu'); } }} - data-testid="filtre-perimetre-exclu" /> {!isVisitor && } @@ -420,13 +421,13 @@ function HousingListFiltersSidemenu(props: Props) { label="Nombre de logements" options={housingCountOptions} initialValues={filters.housingCounts} - onChange={(values) => + onChange={(values) => { onChangeFilters( { housingCounts: values }, 'Nombre de logements' - ) - } - data-testid="filtre-nombre-de-logements" + ); + posthog.capture('filtre-nombre-de-logements'); + }} /> @@ -434,10 +435,10 @@ function HousingListFiltersSidemenu(props: Props) { label="Taux de vacance" options={vacancyRateOptions} initialValues={filters.vacancyRates} - onChange={(values) => - onChangeFilters({ vacancyRates: values }, 'Taux de vacance') - } - data-testid="filtre-taux-de-vacance" + onChange={(values) => { + onChangeFilters({ vacancyRates: values }, 'Taux de vacance'); + posthog.capture('filtre-taux-de-vacance'); + }} /> @@ -445,13 +446,13 @@ function HousingListFiltersSidemenu(props: Props) { label="Étiquette DPE représentatif (CSTB)" options={energyConsumptionOptions} initialValues={filters.energyConsumption} - onChange={(values) => + onChange={(values) => { onChangeFilters( { energyConsumption: values }, 'Étiquette DPE représentatif (CSTB)' - ) - } - data-testid="filtre-etiquette-dpe" + ); + posthog.capture('filtre-etiquette-dpe'); + }} /> @@ -463,10 +464,10 @@ function HousingListFiltersSidemenu(props: Props) { label="Type de logement" options={housingKindOptions} initialValues={filters.housingKinds} - onChange={(values) => - onChangeFilters({ housingKinds: values }, 'Type') - } - data-testid="filtre-type-logement" + onChange={(values) => { + onChangeFilters({ housingKinds: values }, 'Type'); + posthog.capture('filtre-type-logement'); + }} /> @@ -474,13 +475,13 @@ function HousingListFiltersSidemenu(props: Props) { label="Date de construction" options={buildingPeriodOptions} initialValues={filters.buildingPeriods} - onChange={(values) => + onChange={(values) => { onChangeFilters( { buildingPeriods: values }, 'Date de construction' - ) - } - data-testid="filtre-date-construction" + ); + posthog.capture('filtre-date-construction'); + }} /> @@ -488,10 +489,10 @@ function HousingListFiltersSidemenu(props: Props) { label="Surface" options={housingAreaOptions} initialValues={filters.housingAreas} - onChange={(values) => - onChangeFilters({ housingAreas: values }, 'Surface') - } - data-testid="filtre-surface" + onChange={(values) => { + onChangeFilters({ housingAreas: values }, 'Surface'); + posthog.capture('filtre-surface'); + }} /> @@ -499,10 +500,10 @@ function HousingListFiltersSidemenu(props: Props) { label="Nombre de pièces" options={roomsCountOptions} initialValues={filters.roomsCounts ?? []} - onChange={(values) => - onChangeFilters({ roomsCounts: values }, 'Nombre de pièces') - } - data-testid="filtre-nombre-de-pieces" + onChange={(values) => { + onChangeFilters({ roomsCounts: values }, 'Nombre de pièces'); + posthog.capture('filtre-nombre-de-pieces'); + }} /> @@ -512,15 +513,15 @@ function HousingListFiltersSidemenu(props: Props) { initialValues={filters.isTaxedValues?.map((value) => value ? 'true' : 'false' )} - onChange={(values) => + onChange={(values) => { onChangeFilters( { isTaxedValues: values.map((value) => value === 'true') }, 'Taxé' - ) - } - data-testid="filtre-taxe" + ); + posthog.capture('filtre-taxe'); + }} /> @@ -528,13 +529,13 @@ function HousingListFiltersSidemenu(props: Props) { label="Classement cadastral" options={cadastralClassificationOptions} initialValues={filters.cadastralClassifications} - onChange={(values) => + onChange={(values) => { onChangeFilters( { cadastralClassifications: values }, 'Classement cadastral' - ) - } - data-testid="filtre-classement-cadastral" + ); + posthog.capture('filtre-classement-cadastral'); + }} /> @@ -542,10 +543,10 @@ function HousingListFiltersSidemenu(props: Props) { label="Type de propriété" options={ownershipKindsOptions} initialValues={filters.ownershipKinds} - onChange={(values) => - onChangeFilters({ ownershipKinds: values }, 'Type de propriété') - } - data-testid="filtre-type-propriete" + onChange={(values) => { + onChangeFilters({ ownershipKinds: values }, 'Type de propriété'); + posthog.capture('filtre-type-propriete'); + }} /> @@ -560,10 +561,10 @@ function HousingListFiltersSidemenu(props: Props) { label="Type de propriétaire" options={ownerKindOptions} initialValues={filters.ownerKinds} - onChange={(values) => - onChangeFilters({ ownerKinds: values }, 'Type') - } - data-testid="filtre-type-proprietaire" + onChange={(values) => { + onChangeFilters({ ownerKinds: values }, 'Type'); + posthog.capture('filtre-type-proprietaire'); + }} /> @@ -572,10 +573,10 @@ function HousingListFiltersSidemenu(props: Props) { label="Âge" options={ownerAgeOptions} initialValues={filters.ownerAges} - onChange={(values) => - onChangeFilters({ ownerAges: values }, 'Âge') - } - data-testid="filtre-age" + onChange={(values) => { + onChangeFilters({ ownerAges: values }, 'Âge'); + posthog.capture('filtre-age'); + }} /> @@ -585,13 +586,13 @@ function HousingListFiltersSidemenu(props: Props) { initialValues={filters.multiOwners?.map((value) => value ? 'true' : 'false' )} - onChange={(values) => + onChange={(values) => { onChangeFilters( { multiOwners: values?.map((value) => value === 'true') }, 'Multi-propriétaire' - ) - } - data-testid="filtre-multi-propriétaire" + ); + posthog.capture('filtre-multi-proprietaire'); + }} /> @@ -599,13 +600,13 @@ function HousingListFiltersSidemenu(props: Props) { label="Propriétaires secondaires" options={beneficiaryCountOptions} initialValues={filters.beneficiaryCounts} - onChange={(values) => + onChange={(values) => { onChangeFilters( { beneficiaryCounts: values }, 'Propriétaires secondaires' - ) - } - data-testid="filtre-proprietaires-secondaires" + ); + posthog.capture('filtre-proprietaires-secondaires'); + }} /> @@ -619,13 +620,13 @@ function HousingListFiltersSidemenu(props: Props) { initialValues={(filters.dataFileYearsIncluded ?? []).map((_) => String(_) )} - onChange={(values) => + onChange={(values) => { onChangeFilters( { dataFileYearsIncluded: values }, 'Sources et Millésimes inclus' - ) - } - data-testid="filtre-sources-millesimes-inclus" + ); + posthog.capture('filtre-sources-millesimes-inclus'); + }} /> @@ -636,13 +637,13 @@ function HousingListFiltersSidemenu(props: Props) { initialValues={(filters.dataFileYearsExcluded ?? []).map((_) => String(_) )} - onChange={(values) => + onChange={(values) => { onChangeFilters( { dataFileYearsExcluded: values }, 'Sources et millésime exclus' - ) - } - data-testid="filtre-sources-millesimes-exclu" + ); + posthog.capture('filtre-sources-millesimes-exclus'); + }} /> diff --git a/frontend/src/index.tsx b/frontend/src/index.tsx index 233cbd8c3..d69e05caa 100644 --- a/frontend/src/index.tsx +++ b/frontend/src/index.tsx @@ -24,7 +24,7 @@ declare module '@codegouvfr/react-dsfr/spa' { } if (config.posthog.enabled) { - posthog.init('phc_Thondx9VvGONN5SZK0OuDttJDIorIANsudwCL2gU3O7', { + posthog.init(config.posthog.apiKey, { api_host: 'https://eu.i.posthog.com', person_profiles: 'identified_only' }); diff --git a/frontend/src/utils/config.ts b/frontend/src/utils/config.ts index 4145177f8..6e1ccefd4 100644 --- a/frontend/src/utils/config.ts +++ b/frontend/src/utils/config.ts @@ -12,7 +12,8 @@ const config = { enabled: process.env.REACT_APP_POSTHOG_ENABLED !== undefined ? process.env.REACT_APP_POSTHOG_ENABLED === 'true' - : process.env.NODE_ENV === 'production' + : process.env.NODE_ENV === 'production', + apiKey: process.env.REACT_APP_POSTHOG_API_KEY ?? '' }, dataYear: 2023, banEligibleScore: 0.8,