Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

πŸ“ˆ LLM - Flush analytics events when putting the app in background #8232

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
themooneer marked this conversation as resolved.
Show resolved Hide resolved

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]);
}
Loading