From 7119a85d8aad97d00b3fe3b076d1ce97b459a3e1 Mon Sep 17 00:00:00 2001 From: Maxime Golfier <25312957+maxgfr@users.noreply.github.com> Date: Mon, 7 Aug 2023 16:01:46 +0200 Subject: [PATCH] fix(events): refactor `pushAgreements` (#5302) --- .../src/lib/matomo/types.ts | 3 +++ .../Agreement/tracking/pushAgreementEvents.ts | 23 ++++++++++--------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/packages/code-du-travail-frontend/src/lib/matomo/types.ts b/packages/code-du-travail-frontend/src/lib/matomo/types.ts index 0aec03829d..669e3504c5 100644 --- a/packages/code-du-travail-frontend/src/lib/matomo/types.ts +++ b/packages/code-du-travail-frontend/src/lib/matomo/types.ts @@ -22,6 +22,9 @@ export enum MatomoSearchAgreementCategory { ENTERPRISE_SELECT = "enterprise_select", AGREEMENT_SELECT_P1 = "cc_select_p1", AGREEMENT_SELECT_P2 = "cc_select_p2", + PARCOURS_1 = "click_p1", + PARCOURS_2 = "click_p2", + PARCOURS_3 = "click_p3", ENTERPRISE_SEARCH = "enterprise_search", AGREEMENT_SEARCH = "cc_search", AGREEMENT_SEARCH_TYPE_OF_USERS = "cc_search_type_of_users", diff --git a/packages/code-du-travail-frontend/src/outils/common/Agreement/tracking/pushAgreementEvents.ts b/packages/code-du-travail-frontend/src/outils/common/Agreement/tracking/pushAgreementEvents.ts index 843347f06c..a3b49d70c0 100644 --- a/packages/code-du-travail-frontend/src/outils/common/Agreement/tracking/pushAgreementEvents.ts +++ b/packages/code-du-travail-frontend/src/outils/common/Agreement/tracking/pushAgreementEvents.ts @@ -17,22 +17,25 @@ const pushAgreementEvents = ( // no agreement section, no event to send. Should never happen. return; } - let eventName = ""; + let parcours: MatomoSearchAgreementCategory | undefined = undefined; + let agreementSelect: MatomoSearchAgreementCategory | undefined = undefined; switch (values.route) { - case "not-selected": - eventName = "click_p3"; - break; case "agreement": - eventName = "click_p1"; + parcours = MatomoSearchAgreementCategory.PARCOURS_1; + agreementSelect = MatomoSearchAgreementCategory.AGREEMENT_SELECT_P1; break; case "enterprise": - eventName = "click_p2"; + parcours = MatomoSearchAgreementCategory.PARCOURS_2; + agreementSelect = MatomoSearchAgreementCategory.AGREEMENT_SELECT_P2; + break; + case "not-selected": + parcours = MatomoSearchAgreementCategory.PARCOURS_3; break; } matopush([ MatomoBaseEvent.TRACK_EVENT, MatomoSearchAgreementCategory.AGREEMENT_SEARCH_TYPE_OF_USERS, - eventName, + parcours, simulatorTitle, ]); if (values.enterprise) { @@ -46,12 +49,10 @@ const pushAgreementEvents = ( }), ]); } - if (values.selected) { + if (values.selected && agreementSelect) { matopush([ MatomoBaseEvent.TRACK_EVENT, - values.route === "agreement" - ? MatomoSearchAgreementCategory.AGREEMENT_SELECT_P1 - : MatomoSearchAgreementCategory.AGREEMENT_SELECT_P2, + agreementSelect, simulatorTitle, `idcc${values.selected.num?.toString()}`, ]);