Skip to content

Commit

Permalink
Merge pull request #8232 from LedgerHQ/bugfix/llm-analytics-events-de…
Browse files Browse the repository at this point in the history
…layed

📈 LLM - Flush analytics events when putting the app in background
  • Loading branch information
cgrellard-ledger authored Oct 29, 2024
2 parents b93a421 + 7ef2a7d commit 18973b7
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/big-lions-refuse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"live-mobile": patch
---

LLM - Flushes all analytics events when the app goes in the background
3 changes: 3 additions & 0 deletions apps/ledger-live-mobile/src/analytics/SegmentSetup.tsx
Original file line number Diff line number Diff line change
@@ -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();
Expand All @@ -10,6 +11,8 @@ const SegmentSetup = (): null => {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

useFlushInBackground();

return null;
};

Expand Down
5 changes: 5 additions & 0 deletions apps/ledger-live-mobile/src/analytics/segment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
13 changes: 13 additions & 0 deletions apps/ledger-live-mobile/src/analytics/useFlushInBackground.tsx
Original file line number Diff line number Diff line change
@@ -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]);
}

0 comments on commit 18973b7

Please sign in to comment.