From c8325c7354f48b653248d0d47d804b139eb01c24 Mon Sep 17 00:00:00 2001
From: Toufic Batache <taffou2a@gmail.com>
Date: Tue, 5 Mar 2024 11:01:00 +0100
Subject: [PATCH] =?UTF-8?q?Ajout=20des=20stats=20matomo=20pour=20tracker?=
 =?UTF-8?q?=20le=20bouton=20accord=C3=A9on=20des=20graphiques=20cas=20type?=
 =?UTF-8?q?s?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 src/lib/components/WaterfallView.svelte | 12 +++++++++---
 src/lib/matomo.ts                       | 17 +++++++++++++++++
 2 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/src/lib/components/WaterfallView.svelte b/src/lib/components/WaterfallView.svelte
index 8d98b00cc..6db857313 100644
--- a/src/lib/components/WaterfallView.svelte
+++ b/src/lib/components/WaterfallView.svelte
@@ -34,6 +34,7 @@
   import type { DisplayMode } from "$lib/displays"
   import { entityByKey, personEntityKey } from "$lib/entities"
   import type { VariableCustomization, VariableGraph } from "$lib/graphes"
+  import { trackTestCaseGraph } from "$lib/matomo"
   import {
     type CalculationByName,
     getSituationVariableValue,
@@ -1112,9 +1113,14 @@
     {#if firstPersonActivity !== "inactif"}
       <button
         class="w-full flex items-center gap-2 text-neutral-600 text-start border-b px-4 py-2 mt-10 hover:bg-neutral-100 active:bg-neutral-200 transition-all"
-        on:click={situation.slider === undefined
-          ? requestAxesCalculation
-          : removeSituationSlider}
+        on:click={() => {
+          if (situation.slider === undefined) {
+            requestAxesCalculation()
+            trackTestCaseGraph(firstPersonActivity)
+          } else {
+            removeSituationSlider()
+          }
+        }}
       >
         <iconify-icon class="text-lg" icon="ri-line-chart-fill" />
         <span class="flex-1 font-bold">
diff --git a/src/lib/matomo.ts b/src/lib/matomo.ts
index dad243d4c..12904890a 100644
--- a/src/lib/matomo.ts
+++ b/src/lib/matomo.ts
@@ -1,5 +1,6 @@
 import { browser } from "$app/environment"
 import type { ParametricReform } from "$lib/reforms"
+import type { VariableValue } from "$lib/variables"
 
 function trackEvent(category: string, action: string, name: string) {
   if (browser) {
@@ -206,3 +207,19 @@ export function trackTestCaseShowAllVariables() {
 export function trackTestCaseShare() {
   trackEvent("test_case", "share", "Partage d'une simulation cas type")
 }
+
+export function trackTestCaseGraph(activity: VariableValue | undefined) {
+  let variable = "revenu"
+  switch (activity) {
+    case "actif":
+      variable = "salaire"
+      break
+    case "retraite":
+      variable = "retraite"
+      break
+    case "chomeur":
+      variable = "chômage"
+      break
+  }
+  trackEvent("test_case", "show_graph", `Ouverture du graphique "${variable}"`)
+}
-- 
GitLab