Skip to content

Commit

Permalink
[Usage Collection] Remove unused applicationUsageTracker from Publi…
Browse files Browse the repository at this point in the history
…c API (#92670) (#93076)

Co-authored-by: Kibana Machine <[email protected]>

Co-authored-by: Alejandro Fernández Haro <[email protected]>
  • Loading branch information
kibanamachine and afharo authored Mar 1, 2021
1 parent d5e8c0f commit b506b33
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 25 deletions.
1 change: 0 additions & 1 deletion src/plugins/data/public/public.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
18 changes: 13 additions & 5 deletions src/plugins/usage_collection/public/mocks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand All @@ -32,7 +41,6 @@ const createSetupContract = (): Setup => {
</ApplicationUsageContext.Provider>
),
},
applicationUsageTracker: applicationUsageTrackerMock,
reportUiCounter: jest.fn(),
};

Expand Down
7 changes: 0 additions & 7 deletions src/plugins/usage_collection/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -83,7 +78,6 @@ export class UsageCollectionPlugin implements Plugin<UsageCollectionSetup, Usage
</ApplicationUsageContext.Provider>
),
},
applicationUsageTracker,
reportUiCounter: this.reporter.reportUiCounter,
};
}
Expand All @@ -105,7 +99,6 @@ export class UsageCollectionPlugin implements Plugin<UsageCollectionSetup, Usage
this.reporter.reportUserAgent('kibana');

return {
applicationUsageTracker: this.getPublicApplicationUsageTracker(),
reportUiCounter: this.reporter.reportUiCounter,
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit b506b33

Please sign in to comment.