From df132d901081f21875c2f42aaf0d53fef08e87a2 Mon Sep 17 00:00:00 2001 From: rithviknishad Date: Thu, 26 Sep 2024 18:57:08 +0530 Subject: [PATCH 1/4] Plausible: Track applied filters --- src/Common/hooks/useFilters.tsx | 4 ++++ src/Integrations/Plausible.tsx | 1 + 2 files changed, 5 insertions(+) diff --git a/src/Common/hooks/useFilters.tsx b/src/Common/hooks/useFilters.tsx index 188dec2229d..2d37d0e3217 100644 --- a/src/Common/hooks/useFilters.tsx +++ b/src/Common/hooks/useFilters.tsx @@ -6,6 +6,7 @@ import PaginationComponent from "../../Components/Common/Pagination"; import { classNames, humanizeStrings } from "../../Utils/utils"; import FiltersCache from "../../Utils/FiltersCache"; import careConfig from "@careConfig"; +import { triggerGoal } from "../../Integrations/Plausible"; export type FilterState = Record; @@ -42,6 +43,9 @@ export default function useFilters({ ) => { query = FiltersCache.utils.clean(query); _setQueryParams(query, options); + Object.keys(query).forEach((filter) => + triggerGoal("Advanced filter applied", { filter }), + ); updateCache(query); }; diff --git a/src/Integrations/Plausible.tsx b/src/Integrations/Plausible.tsx index 8001c8139d2..6a23c12233d 100644 --- a/src/Integrations/Plausible.tsx +++ b/src/Integrations/Plausible.tsx @@ -72,5 +72,6 @@ const plausible = (event: string, data: object = {}) => { * */ export const triggerGoal = (name: string, props: object) => { + console.debug("triggerGoal", { name, props }); plausible(name, { props }); }; From fdd89326e57a8c3bf7bf8985fb2d5a0648e28449 Mon Sep 17 00:00:00 2001 From: rithviknishad Date: Thu, 26 Sep 2024 18:57:23 +0530 Subject: [PATCH 2/4] remove debug --- src/Integrations/Plausible.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Integrations/Plausible.tsx b/src/Integrations/Plausible.tsx index 6a23c12233d..8001c8139d2 100644 --- a/src/Integrations/Plausible.tsx +++ b/src/Integrations/Plausible.tsx @@ -72,6 +72,5 @@ const plausible = (event: string, data: object = {}) => { * */ export const triggerGoal = (name: string, props: object) => { - console.debug("triggerGoal", { name, props }); plausible(name, { props }); }; From 3578ca23f74883899c6c1d28402cb5cebb8f7cc1 Mon Sep 17 00:00:00 2001 From: rithviknishad Date: Thu, 26 Sep 2024 19:00:06 +0530 Subject: [PATCH 3/4] track location --- src/Common/hooks/useFilters.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Common/hooks/useFilters.tsx b/src/Common/hooks/useFilters.tsx index 2d37d0e3217..341d1f19bdb 100644 --- a/src/Common/hooks/useFilters.tsx +++ b/src/Common/hooks/useFilters.tsx @@ -44,7 +44,10 @@ export default function useFilters({ query = FiltersCache.utils.clean(query); _setQueryParams(query, options); Object.keys(query).forEach((filter) => - triggerGoal("Advanced filter applied", { filter }), + triggerGoal("Advanced filter applied", { + filter, + location: location.pathname, + }), ); updateCache(query); }; From c0327fa5a8a38e68f469b7bbaa13920851257ad7 Mon Sep 17 00:00:00 2001 From: rithviknishad Date: Thu, 26 Sep 2024 19:09:05 +0530 Subject: [PATCH 4/4] add comments --- src/Common/hooks/useFilters.tsx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Common/hooks/useFilters.tsx b/src/Common/hooks/useFilters.tsx index 341d1f19bdb..a6974a5a43b 100644 --- a/src/Common/hooks/useFilters.tsx +++ b/src/Common/hooks/useFilters.tsx @@ -43,12 +43,17 @@ export default function useFilters({ ) => { query = FiltersCache.utils.clean(query); _setQueryParams(query, options); + + // For each of the newly applied filters (additional filters compared to + // previously applied ones), trigger a plausible goal "Advanced filter + // applied" with the applied filter's query key and current location as tags. Object.keys(query).forEach((filter) => triggerGoal("Advanced filter applied", { filter, location: location.pathname, }), ); + updateCache(query); };