MOBILE-4368 analytics: Limit cases where setting is displayed
Now the setting will only be displayed if there is an active handlermain
parent
93b8ce274c
commit
379156bfa7
|
@ -75,7 +75,7 @@
|
|||
</ion-label>
|
||||
<ion-toggle [(ngModel)]="debugDisplay" (ionChange)="debugDisplayChanged($event)" slot="end"></ion-toggle>
|
||||
</ion-item>
|
||||
<ion-item class="ion-text-wrap" *ngIf="analyticsSupported">
|
||||
<ion-item class="ion-text-wrap" *ngIf="analyticsAvailable">
|
||||
<ion-label>
|
||||
<p class="item-heading">{{ 'core.settings.enableanalytics' | translate }}</p>
|
||||
<p>{{ 'core.settings.enableanalyticsdescription' | translate }}</p>
|
||||
|
|
|
@ -44,7 +44,7 @@ export class CoreSettingsGeneralPage {
|
|||
selectedZoomLevel = CoreZoomLevel.NONE;
|
||||
richTextEditor = true;
|
||||
debugDisplay = false;
|
||||
analyticsSupported = false;
|
||||
analyticsAvailable = false;
|
||||
analyticsEnabled = false;
|
||||
colorSchemes: CoreColorScheme[] = [];
|
||||
selectedScheme: CoreColorScheme = CoreColorScheme.LIGHT;
|
||||
|
@ -101,8 +101,8 @@ export class CoreSettingsGeneralPage {
|
|||
|
||||
this.debugDisplay = await CoreConfig.get(CoreConstants.SETTINGS_DEBUG_DISPLAY, false);
|
||||
|
||||
this.analyticsSupported = CoreAnalytics.hasHandlers();
|
||||
if (this.analyticsSupported) {
|
||||
this.analyticsAvailable = await CoreAnalytics.isAnalyticsAvailable();
|
||||
if (this.analyticsAvailable) {
|
||||
this.analyticsEnabled = await CoreConfig.get(CoreConstants.SETTINGS_ANALYTICS_ENABLED, true);
|
||||
}
|
||||
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
@ -108,6 +131,11 @@ export const CoreAnalytics = makeSingleton(CoreAnalyticsService);
|
|||
*/
|
||||
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.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue