File tree Expand file tree Collapse file tree 3 files changed +32
-4
lines changed
features/settings/pages/general Expand file tree Collapse file tree 3 files changed +32
-4
lines changed Original file line number Diff line number Diff line change @@ -75,7 +75,7 @@ <h1>{{ 'core.settings.general' | translate }}</h1>
7575 </ ion-label >
7676 < ion-toggle [(ngModel)] ="debugDisplay " (ionChange) ="debugDisplayChanged($event) " slot ="end "> </ ion-toggle >
7777 </ ion-item >
78- < ion-item class ="ion-text-wrap " *ngIf ="analyticsSupported ">
78+ < ion-item class ="ion-text-wrap " *ngIf ="analyticsAvailable ">
7979 < ion-label >
8080 < p class ="item-heading "> {{ 'core.settings.enableanalytics' | translate }}</ p >
8181 < p > {{ 'core.settings.enableanalyticsdescription' | translate }}</ p >
Original file line number Diff line number Diff line change @@ -44,7 +44,7 @@ export class CoreSettingsGeneralPage {
4444 selectedZoomLevel = CoreZoomLevel . NONE ;
4545 richTextEditor = true ;
4646 debugDisplay = false ;
47- analyticsSupported = false ;
47+ analyticsAvailable = false ;
4848 analyticsEnabled = false ;
4949 colorSchemes : CoreColorScheme [ ] = [ ] ;
5050 selectedScheme : CoreColorScheme = CoreColorScheme . LIGHT ;
@@ -101,8 +101,8 @@ export class CoreSettingsGeneralPage {
101101
102102 this . debugDisplay = await CoreConfig . get ( CoreConstants . SETTINGS_DEBUG_DISPLAY , false ) ;
103103
104- this . analyticsSupported = CoreAnalytics . hasHandlers ( ) ;
105- if ( this . analyticsSupported ) {
104+ this . analyticsAvailable = await CoreAnalytics . isAnalyticsAvailable ( ) ;
105+ if ( this . analyticsAvailable ) {
106106 this . analyticsEnabled = await CoreConfig . get ( CoreConstants . SETTINGS_ANALYTICS_ENABLED , true ) ;
107107 }
108108
Original file line number Diff line number Diff line change @@ -57,6 +57,29 @@ export class CoreAnalyticsService extends CoreDelegate<CoreAnalyticsHandler> {
5757 }
5858 }
5959
60+ /**
61+ * Check if analytics is available for the app/site.
62+ *
63+ * @returns True if available, false otherwise.
64+ */
65+ async isAnalyticsAvailable ( ) : Promise < boolean > {
66+ if ( Object . keys ( this . enabledHandlers ) . length > 0 ) {
67+ // There is an enabled handler, analytics is available.
68+ return true ;
69+ }
70+
71+ // Check if there is a handler that is enabled at app level (enabled handlers are only set when logged in).
72+ const enabledList = await Promise . all ( Object . values ( this . handlers ) . map ( handler => {
73+ if ( ! handler . appLevelEnabled ) {
74+ return false ;
75+ }
76+
77+ return handler . isEnabled ( ) ;
78+ } ) ) ;
79+
80+ return enabledList . includes ( true ) ;
81+ }
82+
6083 /**
6184 * Log an event for the current site.
6285 *
@@ -108,6 +131,11 @@ export const CoreAnalytics = makeSingleton(CoreAnalyticsService);
108131 */
109132export interface CoreAnalyticsHandler extends CoreDelegateHandler {
110133
134+ /**
135+ * If true it means that the handler is enabled or not for the whole app, it doesn't depend on the site.
136+ */
137+ appLevelEnabled ?: boolean ;
138+
111139 /**
112140 * Log an event.
113141 *
You can’t perform that action at this time.
0 commit comments