MOBILE-4368 analytics: Limit cases where setting is displayed

Now the setting will only be displayed if there is an active handler
main
Dani Palou 2023-10-31 11:42:29 +01:00
parent 93b8ce274c
commit 379156bfa7
3 changed files with 32 additions and 4 deletions

View File

@ -75,7 +75,7 @@
</ion-label> </ion-label>
<ion-toggle [(ngModel)]="debugDisplay" (ionChange)="debugDisplayChanged($event)" slot="end"></ion-toggle> <ion-toggle [(ngModel)]="debugDisplay" (ionChange)="debugDisplayChanged($event)" slot="end"></ion-toggle>
</ion-item> </ion-item>
<ion-item class="ion-text-wrap" *ngIf="analyticsSupported"> <ion-item class="ion-text-wrap" *ngIf="analyticsAvailable">
<ion-label> <ion-label>
<p class="item-heading">{{ 'core.settings.enableanalytics' | translate }}</p> <p class="item-heading">{{ 'core.settings.enableanalytics' | translate }}</p>
<p>{{ 'core.settings.enableanalyticsdescription' | translate }}</p> <p>{{ 'core.settings.enableanalyticsdescription' | translate }}</p>

View File

@ -44,7 +44,7 @@ export class CoreSettingsGeneralPage {
selectedZoomLevel = CoreZoomLevel.NONE; selectedZoomLevel = CoreZoomLevel.NONE;
richTextEditor = true; richTextEditor = true;
debugDisplay = false; debugDisplay = false;
analyticsSupported = false; analyticsAvailable = false;
analyticsEnabled = false; analyticsEnabled = false;
colorSchemes: CoreColorScheme[] = []; colorSchemes: CoreColorScheme[] = [];
selectedScheme: CoreColorScheme = CoreColorScheme.LIGHT; selectedScheme: CoreColorScheme = CoreColorScheme.LIGHT;
@ -101,8 +101,8 @@ export class CoreSettingsGeneralPage {
this.debugDisplay = await CoreConfig.get(CoreConstants.SETTINGS_DEBUG_DISPLAY, false); this.debugDisplay = await CoreConfig.get(CoreConstants.SETTINGS_DEBUG_DISPLAY, false);
this.analyticsSupported = CoreAnalytics.hasHandlers(); this.analyticsAvailable = await CoreAnalytics.isAnalyticsAvailable();
if (this.analyticsSupported) { if (this.analyticsAvailable) {
this.analyticsEnabled = await CoreConfig.get(CoreConstants.SETTINGS_ANALYTICS_ENABLED, true); this.analyticsEnabled = await CoreConfig.get(CoreConstants.SETTINGS_ANALYTICS_ENABLED, true);
} }

View File

@ -57,6 +57,29 @@ export class CoreAnalyticsService extends CoreDelegate<CoreAnalyticsHandler> {
} }
} }
/**
* Check if analytics is available for the app/site.
*
* @returns True if available, false otherwise.
*/
async isAnalyticsAvailable(): Promise<boolean> {
if (Object.keys(this.enabledHandlers).length > 0) {
// There is an enabled handler, analytics is available.
return true;
}
// Check if there is a handler that is enabled at app level (enabled handlers are only set when logged in).
const enabledList = await Promise.all(Object.values(this.handlers).map(handler => {
if (!handler.appLevelEnabled) {
return false;
}
return handler.isEnabled();
}));
return enabledList.includes(true);
}
/** /**
* Log an event for the current site. * Log an event for the current site.
* *
@ -108,6 +131,11 @@ export const CoreAnalytics = makeSingleton(CoreAnalyticsService);
*/ */
export interface CoreAnalyticsHandler extends CoreDelegateHandler { export interface CoreAnalyticsHandler extends CoreDelegateHandler {
/**
* If true it means that the handler is enabled or not for the whole app, it doesn't depend on the site.
*/
appLevelEnabled?: boolean;
/** /**
* Log an event. * Log an event.
* *