Skip to content

Commit 634bef4

Browse files
committed
👔 add historical actions
1 parent 2823bdd commit 634bef4

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/adapters/matomo/client.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,17 @@ export const ReferrerKind = {
2020

2121
export const MatomoActions = {
2222
firstAnswer: 'Simulation First answer',
23-
finishedSimulations: 'Simulation Completed',
23+
finishedSimulations: ['A terminé la simulation', 'Simulation Completed'],
2424
} as const
2525

26+
export const MatomoActionsSet: Record<
27+
keyof typeof MatomoActions,
28+
Set<string>
29+
> = {
30+
firstAnswer: new Set(MatomoActions.firstAnswer),
31+
finishedSimulations: new Set(MatomoActions.finishedSimulations),
32+
}
33+
2634
const ReferrerBaseSchema = z
2735
.object({
2836
label: z.string(),
@@ -177,7 +185,9 @@ export const matomoClientFactory = (client: AxiosInstance) => {
177185
method: 'Events.getAction',
178186
'label[]': [
179187
encodeURIComponent(MatomoActions.firstAnswer),
180-
encodeURIComponent(MatomoActions.finishedSimulations),
188+
...MatomoActions.finishedSimulations.map((action) =>
189+
encodeURIComponent(action)
190+
),
181191
],
182192
period: 'day',
183193
date,
@@ -188,12 +198,13 @@ export const matomoClientFactory = (client: AxiosInstance) => {
188198
const actions = z.array(DayActionSchema).parse(data)
189199

190200
const firstAnswer = +(
191-
actions.find(({ label }) => label === MatomoActions.firstAnswer)
201+
actions.find(({ label }) => MatomoActionsSet.firstAnswer.has(label))
192202
?.nb_visits || '0'
193203
)
194204
const finishedSimulations = +(
195-
actions.find(({ label }) => label === MatomoActions.finishedSimulations)
196-
?.nb_visits || '0'
205+
actions.find(({ label }) =>
206+
MatomoActionsSet.finishedSimulations.has(label)
207+
)?.nb_visits || '0'
197208
)
198209

199210
return { firstAnswer, finishedSimulations }

0 commit comments

Comments
 (0)