MOBILE-3084 firebase: Allow disabling analytics at runtime
parent
6bec906dc5
commit
cd9a169e6c
|
@ -1778,6 +1778,8 @@
|
|||
"core.settings.disabled": "lesson",
|
||||
"core.settings.displayformat": "local_moodlemobileapp",
|
||||
"core.settings.enabledownloadsection": "local_moodlemobileapp",
|
||||
"core.settings.enablefirebaseanalytics": "local_moodlemobileapp",
|
||||
"core.settings.enablefirebaseanalyticsdescription": "local_moodlemobileapp",
|
||||
"core.settings.enablerichtexteditor": "local_moodlemobileapp",
|
||||
"core.settings.enablerichtexteditordescription": "local_moodlemobileapp",
|
||||
"core.settings.enablesyncwifi": "local_moodlemobileapp",
|
||||
|
|
|
@ -1779,6 +1779,8 @@
|
|||
"core.settings.disabled": "Disabled",
|
||||
"core.settings.displayformat": "Display format",
|
||||
"core.settings.enabledownloadsection": "Enable download sections",
|
||||
"core.settings.enablefirebaseanalytics": "Enable Firebase analytics",
|
||||
"core.settings.enablefirebaseanalyticsdescription": "If enabled, the app will collect anonymous data usage.",
|
||||
"core.settings.enablerichtexteditor": "Enable text editor",
|
||||
"core.settings.enablerichtexteditordescription": "If enabled, a text editor will be available when entering content.",
|
||||
"core.settings.enablesyncwifi": "Allow sync only when on Wi-Fi",
|
||||
|
|
|
@ -36,6 +36,7 @@ export class CoreConstants {
|
|||
static SETTINGS_REPORT_IN_BACKGROUND = 'CoreSettingsReportInBackground'; // @deprecated since 3.5.0
|
||||
static SETTINGS_SEND_ON_ENTER = 'CoreSettingsSendOnEnter';
|
||||
static SETTINGS_FONT_SIZE = 'CoreSettingsFontSize';
|
||||
static SETTINGS_ANALYTICS_ENABLED = 'CoreSettingsAnalyticsEnabled';
|
||||
|
||||
// WS constants.
|
||||
static WS_TIMEOUT = 30000;
|
||||
|
|
|
@ -240,6 +240,27 @@ export class CorePushNotificationsProvider {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable or disable Firebase analytics.
|
||||
*
|
||||
* @param {boolean} enable Whether to enable or disable.
|
||||
* @return {Promise<any>} Promise resolved when done.
|
||||
*/
|
||||
enableAnalytics(enable: boolean): Promise<any> {
|
||||
const win = <any> window; // This feature is only present in our fork of the plugin.
|
||||
|
||||
if (CoreConfigConstants.enableanalytics && win.PushNotification && win.PushNotification.enableAnalytics) {
|
||||
return new Promise((resolve, reject): void => {
|
||||
win.PushNotification.enableAnalytics(resolve, (error) => {
|
||||
this.logger.error('Error enabling or disabling Firebase analytics', enable, error);
|
||||
resolve();
|
||||
}, !!enable);
|
||||
});
|
||||
}
|
||||
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns options for push notifications based on device.
|
||||
*
|
||||
|
|
|
@ -21,6 +21,8 @@
|
|||
"disabled": "Disabled",
|
||||
"displayformat": "Display format",
|
||||
"enabledownloadsection": "Enable download sections",
|
||||
"enablefirebaseanalytics": "Enable Firebase analytics",
|
||||
"enablefirebaseanalyticsdescription": "If enabled, the app will collect anonymous data usage.",
|
||||
"enablerichtexteditor": "Enable text editor",
|
||||
"enablerichtexteditordescription": "If enabled, a text editor will be available when entering content.",
|
||||
"enablesyncwifi": "Allow sync only when on Wi-Fi",
|
||||
|
|
|
@ -34,4 +34,11 @@
|
|||
</ion-label>
|
||||
<ion-toggle [(ngModel)]="debugDisplay" (ngModelChange)="debugDisplayChanged()"></ion-toggle>
|
||||
</ion-item>
|
||||
<ion-item text-wrap *ngIf="analyticsSupported">
|
||||
<ion-label>
|
||||
<h2>{{ 'core.settings.enablefirebaseanalytics' | translate }}</h2>
|
||||
<p>{{ 'core.settings.enablefirebaseanalyticsdescription' | translate }}</p>
|
||||
</ion-label>
|
||||
<ion-toggle [(ngModel)]="analyticsEnabled" (ngModelChange)="analyticsEnabledChanged()"></ion-toggle>
|
||||
</ion-item>
|
||||
</ion-content>
|
||||
|
|
|
@ -22,6 +22,7 @@ import { CoreEventsProvider } from '@providers/events';
|
|||
import { CoreLangProvider } from '@providers/lang';
|
||||
import { CoreDomUtilsProvider } from '@providers/utils/dom';
|
||||
import { CoreLocalNotificationsProvider } from '@providers/local-notifications';
|
||||
import { CorePushNotificationsProvider } from '@core/pushnotifications/providers/pushnotifications';
|
||||
import { CoreConfigConstants } from '../../../../configconstants';
|
||||
|
||||
/**
|
||||
|
@ -41,10 +42,12 @@ export class CoreSettingsGeneralPage {
|
|||
rteSupported: boolean;
|
||||
richTextEditor: boolean;
|
||||
debugDisplay: boolean;
|
||||
analyticsSupported: boolean;
|
||||
analyticsEnabled: boolean;
|
||||
|
||||
constructor(appProvider: CoreAppProvider, private configProvider: CoreConfigProvider, fileProvider: CoreFileProvider,
|
||||
private eventsProvider: CoreEventsProvider, private langProvider: CoreLangProvider,
|
||||
private domUtils: CoreDomUtilsProvider,
|
||||
private domUtils: CoreDomUtilsProvider, private pushNotificationsProvider: CorePushNotificationsProvider,
|
||||
localNotificationsProvider: CoreLocalNotificationsProvider) {
|
||||
|
||||
// Get the supported languages.
|
||||
|
@ -93,6 +96,13 @@ export class CoreSettingsGeneralPage {
|
|||
this.configProvider.get(CoreConstants.SETTINGS_DEBUG_DISPLAY, false).then((debugDisplay) => {
|
||||
this.debugDisplay = !!debugDisplay;
|
||||
});
|
||||
|
||||
this.analyticsSupported = CoreConfigConstants.enableanalytics;
|
||||
if (this.analyticsSupported) {
|
||||
this.configProvider.get(CoreConstants.SETTINGS_ANALYTICS_ENABLED, true).then((enabled) => {
|
||||
this.analyticsEnabled = !!enabled;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ViewChild(Segment)
|
||||
|
@ -134,4 +144,13 @@ export class CoreSettingsGeneralPage {
|
|||
this.configProvider.set(CoreConstants.SETTINGS_DEBUG_DISPLAY, this.debugDisplay ? 1 : 0);
|
||||
this.domUtils.setDebugDisplay(this.debugDisplay);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the analytics setting is enabled or disabled.
|
||||
*/
|
||||
analyticsEnabledChanged(): void {
|
||||
this.pushNotificationsProvider.enableAnalytics(this.analyticsEnabled).then(() => {
|
||||
this.configProvider.set(CoreConstants.SETTINGS_ANALYTICS_ENABLED, this.analyticsEnabled ? 1 : 0);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue