Skip to content

Commit a9f532b

Browse files
committed
feat(recherche): mise en place A/B Testing sur les labels pour les contributions.
1 parent d425440 commit a9f532b

11 files changed

Lines changed: 72 additions & 203 deletions

File tree

packages/code-du-travail-frontend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"@socialgouv/cdtn-elasticsearch": "^2.72.1",
4242
"@socialgouv/cdtn-types": "^2.71.0",
4343
"@socialgouv/cdtn-utils": "link:../code-du-travail-utils",
44-
"@socialgouv/matomo-next": "^1.11.0",
44+
"@socialgouv/matomo-next": "^1.13.1",
4545
"@socialgouv/modeles-social": "link:../code-du-travail-modeles",
4646
"date-fns": "^4.1.0",
4747
"debounce-promise": "^3.1.2",

packages/code-du-travail-frontend/src/config.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ export const PACKAGE_VERSION = version;
1414
export const PIWIK_SITE_ID = process.env.NEXT_PUBLIC_PIWIK_SITE_ID ?? "3";
1515
export const PIWIK_URL =
1616
process.env.NEXT_PUBLIC_PIWIK_URL ?? "https://matomo.fabrique.social.gouv.fr";
17-
export const AB_TESTING_ENABLED =
18-
process.env.NEXT_PUBLIC_ENABLE_AB_TESTING === "true";
1917
export const IS_PREPROD =
2018
process.env.NEXT_PUBLIC_IS_PREPRODUCTION_DEPLOYMENT ?? false;
2119
export const IS_PROD =

packages/code-du-travail-frontend/src/modules/config/MatomoAnalytics.tsx

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,9 @@
22

33
import { usePathname, useSearchParams } from "next/navigation";
44
import { Suspense, useEffect } from "react";
5-
import {
6-
AB_TESTING_ENABLED,
7-
PIWIK_SITE_ID,
8-
PIWIK_URL,
9-
WIDGETS_PATH,
10-
SITE_URL,
11-
} from "../../config";
5+
import { PIWIK_SITE_ID, PIWIK_URL, WIDGETS_PATH } from "../../config";
126
import { getStoredConsent } from "../utils/consent";
137
import { push, trackAppRouter } from "@socialgouv/matomo-next";
14-
import { initABTesting } from "./initABTesting";
158
import { AB_TESTS } from "./abTests";
169

1710
type MatomoComponentProps = {
@@ -39,6 +32,7 @@ function MatomoComponent({ heatmapEnabled }: MatomoComponentProps) {
3932
},
4033

4134
searchKeyword: "query",
35+
abTests: AB_TESTS,
4236

4337
onInitialization: () => {
4438
const referrerUrl = document?.referrer || searchParams.get("src_url");
@@ -50,13 +44,6 @@ function MatomoComponent({ heatmapEnabled }: MatomoComponentProps) {
5044
if (pathname && pathname.match(WIDGETS_PATH)) {
5145
push(["setCookieSameSite", "None"]);
5246
}
53-
54-
initABTesting({
55-
enabled: AB_TESTING_ENABLED,
56-
pathname: pathname ?? "",
57-
excludeUrlsPatterns: [WIDGETS_PATH],
58-
tests: AB_TESTS,
59-
});
6047
},
6148
});
6249
};
Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,38 @@
1-
import type { ABTestDefinition } from "./initABTesting";
1+
import type { ABTestDefinition } from "@socialgouv/matomo-next";
2+
3+
export enum LabelSearchCardVariations {
4+
ORIGINAL = "original",
5+
FICHE_PRATIQUE = "fiche-pratique",
6+
SELON_MA_CC = "selon-ma-cc",
7+
REPONSE_PERSONNALISEE = "reponse-personnalisee",
8+
SELON_ENTREPRISE = "selon-entreprise",
9+
}
210

311
/**
412
* Central place to register Matomo A/B tests.
513
*
614
* Keep this empty by default; add tests here when needed.
715
*/
8-
export const AB_TESTS: ABTestDefinition[] = [];
16+
export const AB_TESTS: ABTestDefinition[] = [
17+
{
18+
name: "LabelCardSearch",
19+
percentage: 100,
20+
variations: [
21+
{
22+
name: LabelSearchCardVariations.ORIGINAL,
23+
},
24+
{
25+
name: LabelSearchCardVariations.FICHE_PRATIQUE,
26+
},
27+
{
28+
name: LabelSearchCardVariations.SELON_MA_CC,
29+
},
30+
{
31+
name: LabelSearchCardVariations.REPONSE_PERSONNALISEE,
32+
},
33+
{
34+
name: LabelSearchCardVariations.SELON_ENTREPRISE,
35+
},
36+
],
37+
},
38+
];

packages/code-du-travail-frontend/src/modules/config/initABTesting.ts

Lines changed: 0 additions & 117 deletions
This file was deleted.

packages/code-du-travail-frontend/src/modules/recherche/Card.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { css } from "@styled-system/css";
66
import DisplayContent from "../common/DisplayContent";
77
import { badgeColorClasses, getSourceLabel } from "./utils";
88
import { routeBySource } from "@socialgouv/cdtn-utils";
9+
import { useABTestVariant } from "@socialgouv/matomo-next";
910

1011
type SearchCardProps = {
1112
id?: string;
@@ -24,14 +25,16 @@ export const SearchCard: React.FC<SearchCardProps> = ({
2425
link,
2526
onClick,
2627
}) => {
28+
const variant = useABTestVariant("LabelCardSearch");
29+
2730
return (
2831
<Card
2932
start={
3033
source ? (
3134
<p
3235
className={`${fr.cx("fr-tag", "fr-tag--sm", "fr-text--xs", "fr-text--bold")} ${badgeColorClasses[source]}`}
3336
>
34-
{getSourceLabel(source)}
37+
{getSourceLabel(source, variant)}
3538
</p>
3639
) : null
3740
}

packages/code-du-travail-frontend/src/modules/recherche/__tests__/SearchPageClient.test.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ jest.mock("../tracking", () => ({
2929
// Mock matomo (used by Feedback component)
3030
jest.mock("@socialgouv/matomo-next", () => ({
3131
sendEvent: jest.fn(),
32+
useABTestVariant: jest.fn(() => ({
33+
variant: "original",
34+
})),
3235
}));
3336

3437
describe("SearchPageClient", () => {

packages/code-du-travail-frontend/src/modules/recherche/modal/SearchResultCard.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1+
"use client";
2+
13
import { fr } from "@codegouvfr/react-dsfr";
24
import { css } from "@styled-system/css";
35
import Link from "src/modules/common/Link";
46
import {
7+
badgeColorClasses,
58
generateSearchLink,
69
getSourceLabel,
7-
badgeColorClasses,
810
} from "../utils";
911
import { SearchResult } from "src/api";
12+
import { useABTestVariant } from "@socialgouv/matomo-next";
1013

1114
type Props = {
1215
result: SearchResult;
@@ -22,6 +25,7 @@ export const SearchResultCard = ({ result, onClick }: Props) => {
2225
result.parentSlug
2326
);
2427
const hasHash = href.includes("#");
28+
const variant = useABTestVariant("LabelCardSearch");
2529

2630
return (
2731
<Link
@@ -36,7 +40,7 @@ export const SearchResultCard = ({ result, onClick }: Props) => {
3640
<div className={cardContainer}>
3741
<div className={`${fr.cx("fr-mb-1w")} ${badgeContainer}`}>
3842
<span className={`${badgeBase} ${badgeColorClasses[result.source]}`}>
39-
{getSourceLabel(result.source)}
43+
{getSourceLabel(result.source, variant)}
4044
</span>
4145
</div>
4246
<span

packages/code-du-travail-frontend/src/modules/recherche/utils.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ import {
66
} from "@socialgouv/cdtn-utils";
77
import { SearchResult } from "../../api";
88
import { css } from "@styled-system/css";
9-
import { JSX } from "react";
10-
import { fr } from "@codegouvfr/react-dsfr";
9+
import { LabelSearchCardVariations } from "../config/abTests";
1110

1211
export const generateSearchLink = (
1312
source: keyof typeof routeBySource,
@@ -24,7 +23,10 @@ export const generateSearchLink = (
2423
return `/${getRouteBySource(source)}/${slug}`;
2524
};
2625

27-
export const getSourceLabel = (source: keyof typeof routeBySource): string => {
26+
export const getSourceLabel = (
27+
source: keyof typeof routeBySource,
28+
variant: string | null
29+
): string => {
2830
const ficheGeneriqueSourceTypes = [
2931
"fiches_ministere_travail",
3032
"fiches_service_public",
@@ -37,6 +39,16 @@ export const getSourceLabel = (source: keyof typeof routeBySource): string => {
3739
}
3840

3941
if (source === "contributions") {
42+
switch (variant) {
43+
case LabelSearchCardVariations.FICHE_PRATIQUE:
44+
return "FICHE PRATIQUE";
45+
case LabelSearchCardVariations.SELON_ENTREPRISE:
46+
return "SELON LE SECTEUR DE L'ENTREPRISE";
47+
case LabelSearchCardVariations.REPONSE_PERSONNALISEE:
48+
return "RÉPONSE PERSONNALISÉE";
49+
case LabelSearchCardVariations.SELON_MA_CC:
50+
return "SELON MA CONVENTION COLLECTIVE";
51+
}
4052
return "RÉPONSE SUR-MESURE";
4153
}
4254

packages/code-du-travail-frontend/src/modules/utils/useABTestVariant.ts

Lines changed: 0 additions & 54 deletions
This file was deleted.

0 commit comments

Comments
 (0)