35 lines
774 B
TypeScript
35 lines
774 B
TypeScript
export type AnalyticsNudgeState = {
|
|
decisionMade: boolean;
|
|
analyticsConsent: boolean;
|
|
snoozedUntil: number | null;
|
|
now: number;
|
|
activeSeconds: number;
|
|
routeCount: number;
|
|
thresholdSeconds: number;
|
|
thresholdRoutes: number;
|
|
isUpload: boolean;
|
|
};
|
|
|
|
export function isUploadPath(pathname: string): boolean {
|
|
return /\/upload(?:\/|$)/.test(pathname);
|
|
}
|
|
|
|
export function shouldShowAnalyticsNudge(state: AnalyticsNudgeState): boolean {
|
|
if (state.decisionMade || state.analyticsConsent) {
|
|
return false;
|
|
}
|
|
|
|
if (state.isUpload) {
|
|
return false;
|
|
}
|
|
|
|
if (state.snoozedUntil && state.snoozedUntil > state.now) {
|
|
return false;
|
|
}
|
|
|
|
return (
|
|
state.activeSeconds >= state.thresholdSeconds &&
|
|
state.routeCount >= state.thresholdRoutes
|
|
);
|
|
}
|