[Usage Collection] Remove unused applicationUsageTracker from Public API (#92670) (#93076)

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

Co-authored-by: Alejandro Fernández Haro <alejandro.haro@elastic.co>
This commit is contained in:
Kibana Machine 2021-03-01 14:54:57 -05:00 committed by GitHub
parent d5e8c0f062
commit b506b339ac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 17 additions and 25 deletions

View file

@ -10,7 +10,6 @@ import { Adapters as Adapters_2 } from 'src/plugins/inspector/common';
import { ApiResponse } from '@elastic/elasticsearch';
import { ApiResponse as ApiResponse_2 } from '@elastic/elasticsearch/lib/Transport';
import { ApplicationStart } from 'kibana/public';
import { ApplicationUsageTracker } from '@kbn/analytics';
import { Assign } from '@kbn/utility-types';
import { BehaviorSubject } from 'rxjs';
import { BfetchPublicSetup } from 'src/plugins/bfetch/public';

View file

@ -70,17 +70,6 @@ Application Usage will automatically track the active minutes on screen and clic
The prop `viewId` is used as a unique identifier for your plugin. The Application Id is automatically attached to the tracked usage, based on the ID used when registering your app via `core.application.register`.
#### Advanced Usage
If you have a custom use case not provided by the Application Usage helpers you can use the `usageCollection.applicationUsageTracker` public api directly.
To start tracking a view: `applicationUsageTracker.trackApplicationViewUsage(viewId)`
Calling this method will marks the specified `viewId` as active. applicationUsageTracker will start tracking clicks and screen minutes for the view.
To stop tracking a view: `applicationUsageTracker.flushTrackedView(viewId)`
Calling this method will stop tracking the clicks and screen minutes for that view. Usually once the view is no longer active.
## Application Usage Telemetry Data
This collector reports the number of general clicks and minutes on screen for each registered application in Kibana.

View file

@ -13,11 +13,20 @@ import { ApplicationUsageContext } from './components/track_application_view';
export type Setup = jest.Mocked<UsageCollectionSetup>;
export const createApplicationUsageTrackerMock = (): ApplicationUsageTracker => {
const applicationUsageTrackerMock: jest.Mocked<ApplicationUsageTracker> = {
setCurrentAppId: jest.fn(),
// This is to avoid having to mock every private property of the class
type ApplicationUsageTrackerPublic = Pick<ApplicationUsageTracker, keyof ApplicationUsageTracker>;
export const createApplicationUsageTrackerMock = (): ApplicationUsageTrackerPublic => {
const applicationUsageTrackerMock: jest.Mocked<ApplicationUsageTrackerPublic> = {
trackApplicationViewUsage: jest.fn(),
} as any;
flushTrackedView: jest.fn(),
updateViewClickCounter: jest.fn(),
setCurrentAppId: jest.fn(),
start: jest.fn(),
stop: jest.fn(),
pauseTrackingAll: jest.fn(),
resumeTrackingAll: jest.fn(),
};
return applicationUsageTrackerMock;
};
@ -32,7 +41,6 @@ const createSetupContract = (): Setup => {
</ApplicationUsageContext.Provider>
),
},
applicationUsageTracker: applicationUsageTrackerMock,
reportUiCounter: jest.fn(),
};

View file

@ -35,16 +35,11 @@ export interface UsageCollectionSetup {
components: {
ApplicationUsageTrackingProvider: React.FC;
};
applicationUsageTracker: IApplicationUsageTracker;
reportUiCounter: Reporter['reportUiCounter'];
}
export interface UsageCollectionStart {
reportUiCounter: Reporter['reportUiCounter'];
applicationUsageTracker: Pick<
ApplicationUsageTracker,
'trackApplicationViewUsage' | 'flushTrackedView' | 'updateViewClickCounter'
>;
}
export function isUnauthenticated(http: HttpSetup) {
@ -83,7 +78,6 @@ export class UsageCollectionPlugin implements Plugin<UsageCollectionSetup, Usage
</ApplicationUsageContext.Provider>
),
},
applicationUsageTracker,
reportUiCounter: this.reporter.reportUiCounter,
};
}
@ -105,7 +99,6 @@ export class UsageCollectionPlugin implements Plugin<UsageCollectionSetup, Usage
this.reporter.reportUserAgent('kibana');
return {
applicationUsageTracker: this.getPublicApplicationUsageTracker(),
reportUiCounter: this.reporter.reportUiCounter,
};
}

View file

@ -18,7 +18,10 @@ const DO_NOT_REPORT = ['kibana'];
export function trackApplicationUsageChange(
currentAppId$: Observable<string | undefined>,
applicationUsageTracker: ApplicationUsageTracker
applicationUsageTracker: Pick<
ApplicationUsageTracker,
'updateViewClickCounter' | 'setCurrentAppId' | 'trackApplicationViewUsage'
>
) {
const windowClickSubscrition = fromEvent(window, 'click').subscribe(() => {
applicationUsageTracker.updateViewClickCounter(MAIN_APP_DEFAULT_VIEW_ID);