diff --git a/.changeset/big-lions-refuse.md b/.changeset/big-lions-refuse.md new file mode 100644 index 000000000000..ba178690e929 --- /dev/null +++ b/.changeset/big-lions-refuse.md @@ -0,0 +1,5 @@ +--- +"live-mobile": patch +--- + +LLM - Flushes all analytics events when the app goes in the background diff --git a/apps/ledger-live-mobile/src/analytics/SegmentSetup.tsx b/apps/ledger-live-mobile/src/analytics/SegmentSetup.tsx index 545af745ea7d..c40e79eb4453 100644 --- a/apps/ledger-live-mobile/src/analytics/SegmentSetup.tsx +++ b/apps/ledger-live-mobile/src/analytics/SegmentSetup.tsx @@ -1,6 +1,7 @@ import { useEffect } from "react"; import { useStore } from "react-redux"; import { start } from "./segment"; +import useFlushInBackground from "./useFlushInBackground"; const SegmentSetup = (): null => { const store = useStore(); @@ -10,6 +11,8 @@ const SegmentSetup = (): null => { // eslint-disable-next-line react-hooks/exhaustive-deps }, []); + useFlushInBackground(); + return null; }; diff --git a/apps/ledger-live-mobile/src/analytics/segment.ts b/apps/ledger-live-mobile/src/analytics/segment.ts index bf70f149af19..26b9b56b7c2a 100644 --- a/apps/ledger-live-mobile/src/analytics/segment.ts +++ b/apps/ledger-live-mobile/src/analytics/segment.ts @@ -371,6 +371,11 @@ export const trackWithRoute = ( }; track(event, newProperties, mandatory); }; + +export const flush = () => { + segmentClient?.flush(); +}; + export const useTrack = () => { const route = useRoute(); const track = useCallback( diff --git a/apps/ledger-live-mobile/src/analytics/useFlushInBackground.tsx b/apps/ledger-live-mobile/src/analytics/useFlushInBackground.tsx new file mode 100644 index 000000000000..34cf07716c7b --- /dev/null +++ b/apps/ledger-live-mobile/src/analytics/useFlushInBackground.tsx @@ -0,0 +1,13 @@ +import { useEffect } from "react"; +import useIsAppInBackground from "../components/useIsAppInBackground"; +import { flush } from "./segment"; + +export default function useFlushInBackground() { + const isAppInBakcground = useIsAppInBackground(); + + useEffect(() => { + if (isAppInBakcground) { + flush(); + } + }, [isAppInBakcground]); +}