MOBILE-4368 analytics: Support open link events
parent
791da4500b
commit
333c2b9c6d
|
@ -1892,12 +1892,12 @@ export class CoreSite {
|
||||||
options.showBrowserWarning = false; // A warning already shown, no need to show another.
|
options.showBrowserWarning = false; // A warning already shown, no need to show another.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
options.originalUrl = url;
|
||||||
|
|
||||||
// Open the URL.
|
// Open the URL.
|
||||||
if (inApp) {
|
if (inApp) {
|
||||||
return CoreUtils.openInApp(autoLoginUrl, options);
|
return CoreUtils.openInApp(autoLoginUrl, options);
|
||||||
} else {
|
} else {
|
||||||
options.browserWarningUrl = url;
|
|
||||||
|
|
||||||
return CoreUtils.openInBrowser(autoLoginUrl, options);
|
return CoreUtils.openInBrowser(autoLoginUrl, options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -127,12 +127,14 @@ export enum CoreAnalyticsEventType {
|
||||||
VIEW_ITEM_LIST = 'view_item_list', // View some page or data that mainly contains a list of items.
|
VIEW_ITEM_LIST = 'view_item_list', // View some page or data that mainly contains a list of items.
|
||||||
PUSH_NOTIFICATION = 'push_notification', // Event related to push notifications.
|
PUSH_NOTIFICATION = 'push_notification', // Event related to push notifications.
|
||||||
DOWNLOAD_FILE = 'download_file', // A file was downloaded.
|
DOWNLOAD_FILE = 'download_file', // A file was downloaded.
|
||||||
|
OPEN_LINK = 'open_link', // A link was opened in browser or InAppBrowser.
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Any type of event data.
|
* Any type of event data.
|
||||||
*/
|
*/
|
||||||
export type CoreAnalyticsAnyEvent = CoreAnalyticsViewEvent | CoreAnalyticsPushEvent | CoreAnalyticsDownloadFileEvent;
|
export type CoreAnalyticsAnyEvent = CoreAnalyticsViewEvent | CoreAnalyticsPushEvent | CoreAnalyticsDownloadFileEvent |
|
||||||
|
CoreAnalyticsOpenLinkEvent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Event data, including calculated data.
|
* Event data, including calculated data.
|
||||||
|
@ -172,3 +174,11 @@ export type CoreAnalyticsDownloadFileEvent = {
|
||||||
type: CoreAnalyticsEventType.DOWNLOAD_FILE;
|
type: CoreAnalyticsEventType.DOWNLOAD_FILE;
|
||||||
fileUrl: string;
|
fileUrl: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data specific for the OPEN_LINK events.
|
||||||
|
*/
|
||||||
|
export type CoreAnalyticsOpenLinkEvent = {
|
||||||
|
type: CoreAnalyticsEventType.OPEN_LINK;
|
||||||
|
link: string;
|
||||||
|
};
|
||||||
|
|
|
@ -39,6 +39,8 @@ import { CoreErrorWithOptions } from '@classes/errors/errorwithoptions';
|
||||||
import { CoreFilepool } from '@services/filepool';
|
import { CoreFilepool } from '@services/filepool';
|
||||||
import { CoreSites } from '@services/sites';
|
import { CoreSites } from '@services/sites';
|
||||||
import { CoreCancellablePromise } from '@classes/cancellable-promise';
|
import { CoreCancellablePromise } from '@classes/cancellable-promise';
|
||||||
|
import { CoreAnalytics, CoreAnalyticsEventType } from '@services/analytics';
|
||||||
|
import { CoreUrlUtils } from './url';
|
||||||
|
|
||||||
export type TreeNode<T> = T & { children: TreeNode<T>[] };
|
export type TreeNode<T> = T & { children: TreeNode<T>[] };
|
||||||
|
|
||||||
|
@ -1058,7 +1060,7 @@ export class CoreUtilsProvider {
|
||||||
* @param options Override default options passed to InAppBrowser.
|
* @param options Override default options passed to InAppBrowser.
|
||||||
* @returns The opened window.
|
* @returns The opened window.
|
||||||
*/
|
*/
|
||||||
openInApp(url: string, options?: InAppBrowserOptions): InAppBrowserObject {
|
openInApp(url: string, options?: CoreUtilsOpenInAppOptions): InAppBrowserObject {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
options.usewkwebview = 'yes'; // Force WKWebView in iOS.
|
options.usewkwebview = 'yes'; // Force WKWebView in iOS.
|
||||||
options.enableViewPortScale = options.enableViewPortScale ?? 'yes'; // Enable zoom on iOS by default.
|
options.enableViewPortScale = options.enableViewPortScale ?? 'yes'; // Enable zoom on iOS by default.
|
||||||
|
@ -1116,6 +1118,11 @@ export class CoreUtilsProvider {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CoreAnalytics.logEvent({
|
||||||
|
type: CoreAnalyticsEventType.OPEN_LINK,
|
||||||
|
link: CoreUrlUtils.unfixPluginfileURL(options.originalUrl ?? url),
|
||||||
|
});
|
||||||
|
|
||||||
return this.iabInstance;
|
return this.iabInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1170,14 +1177,20 @@ export class CoreUtilsProvider {
|
||||||
* @param options Options.
|
* @param options Options.
|
||||||
*/
|
*/
|
||||||
async openInBrowser(url: string, options: CoreUtilsOpenInBrowserOptions = {}): Promise<void> {
|
async openInBrowser(url: string, options: CoreUtilsOpenInBrowserOptions = {}): Promise<void> {
|
||||||
|
const originaUrl = CoreUrlUtils.unfixPluginfileURL(options.originalUrl ?? options.browserWarningUrl ?? url);
|
||||||
if (options.showBrowserWarning || options.showBrowserWarning === undefined) {
|
if (options.showBrowserWarning || options.showBrowserWarning === undefined) {
|
||||||
try {
|
try {
|
||||||
await CoreWindow.confirmOpenBrowserIfNeeded(options.browserWarningUrl ?? url);
|
await CoreWindow.confirmOpenBrowserIfNeeded(originaUrl);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return; // Cancelled, stop.
|
return; // Cancelled, stop.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CoreAnalytics.logEvent({
|
||||||
|
type: CoreAnalyticsEventType.OPEN_LINK,
|
||||||
|
link: originaUrl,
|
||||||
|
});
|
||||||
|
|
||||||
window.open(url, '_system');
|
window.open(url, '_system');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1204,12 +1217,19 @@ export class CoreUtilsProvider {
|
||||||
type: mimetype,
|
type: mimetype,
|
||||||
};
|
};
|
||||||
|
|
||||||
return WebIntent.startActivity(options).catch((error) => {
|
try {
|
||||||
|
await WebIntent.startActivity(options);
|
||||||
|
|
||||||
|
CoreAnalytics.logEvent({
|
||||||
|
type: CoreAnalyticsEventType.OPEN_LINK,
|
||||||
|
link: CoreUrlUtils.unfixPluginfileURL(url),
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
this.logger.error('Error opening online file ' + url + ' with mimetype ' + mimetype);
|
this.logger.error('Error opening online file ' + url + ' with mimetype ' + mimetype);
|
||||||
this.logger.error('Error: ', JSON.stringify(error));
|
this.logger.error('Error: ', JSON.stringify(error));
|
||||||
|
|
||||||
throw new Error(Translate.instant('core.erroropenfilenoapp'));
|
throw new Error(Translate.instant('core.erroropenfilenoapp'));
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// In the rest of platforms we need to open them in InAppBrowser.
|
// In the rest of platforms we need to open them in InAppBrowser.
|
||||||
|
@ -1897,7 +1917,18 @@ export type CoreUtilsOpenFileOptions = {
|
||||||
*/
|
*/
|
||||||
export type CoreUtilsOpenInBrowserOptions = {
|
export type CoreUtilsOpenInBrowserOptions = {
|
||||||
showBrowserWarning?: boolean; // Whether to display a warning before opening in browser. Defaults to true.
|
showBrowserWarning?: boolean; // Whether to display a warning before opening in browser. Defaults to true.
|
||||||
browserWarningUrl?: string; // The URL to display in the warning message. Use it to hide sensitive information.
|
originalUrl?: string; // Original URL to open (in case the URL was treated, e.g. to add a token or an auto-login).
|
||||||
|
/**
|
||||||
|
* @deprecated since 4.3, use originalUrl instead.
|
||||||
|
*/
|
||||||
|
browserWarningUrl?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Options for opening in InAppBrowser.
|
||||||
|
*/
|
||||||
|
export type CoreUtilsOpenInAppOptions = InAppBrowserOptions & {
|
||||||
|
originalUrl?: string; // Original URL to open (in case the URL was treated, e.g. to add a token or an auto-login).
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue