Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 => {
Copy link
Contributor

@TinaHeiligers TinaHeiligers Mar 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're still using applicationUsageTracker internally so we're not strictly removing it from the code base.

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