-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Lens] Track actions in the UI by time
- Loading branch information
1 parent
0a85478
commit a832b1e
Showing
16 changed files
with
516 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
export interface LensClickEvent { | ||
name: string; | ||
date: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ | |
|
||
export * from './api'; | ||
export * from './constants'; | ||
export * from './clickdata'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
x-pack/legacy/plugins/lens/public/lens_ui_telemetry/__mocks__/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { createContext, useContext } from 'react'; | ||
|
||
export const LensTelemetryContext = createContext<{ | ||
trackClick: (name: string) => void; | ||
trackSuggestionClick: (name: string, suggestionData: unknown) => void; | ||
}>({ | ||
trackClick: jest.fn(), | ||
trackSuggestionClick: jest.fn(), | ||
}); | ||
|
||
export const useLensTelemetry = () => useContext(LensTelemetryContext); |
89 changes: 89 additions & 0 deletions
89
x-pack/legacy/plugins/lens/public/lens_ui_telemetry/factory.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { HttpServiceBase } from 'src/core/public'; | ||
|
||
import { Storage } from 'src/legacy/core_plugins/data/public/types'; | ||
import { LensClickEvent, BASE_API_URL } from '../../common'; | ||
|
||
const STORAGE_KEY = 'lens-ui-telemetry'; | ||
|
||
export class LensReportManager { | ||
private clicks: LensClickEvent[]; | ||
private suggestionClicks: LensClickEvent[]; | ||
|
||
private storage: Storage; | ||
private http: HttpServiceBase; | ||
private basePath: string; | ||
private timer: ReturnType<typeof setInterval>; | ||
|
||
constructor({ | ||
storage, | ||
http, | ||
basePath, | ||
}: { | ||
storage: Storage; | ||
http: HttpServiceBase; | ||
basePath: string; | ||
}) { | ||
this.storage = storage; | ||
this.http = http; | ||
this.basePath = basePath; | ||
|
||
const unsent = this.storage.get(STORAGE_KEY); | ||
this.clicks = unsent && unsent.clicks ? unsent.clicks : []; | ||
this.suggestionClicks = unsent && unsent.suggestionClicks ? unsent.suggestionClicks : []; | ||
|
||
this.timer = setInterval(() => { | ||
if (this.clicks.length || this.suggestionClicks.length) { | ||
this.postToServer(); | ||
} | ||
}, 10000); | ||
} | ||
|
||
public trackClick(name: string) { | ||
this.clicks.push({ | ||
name, | ||
date: new Date().toISOString(), | ||
}); | ||
this.write(); | ||
} | ||
|
||
public trackSuggestionClick(name: string) { | ||
this.suggestionClicks.push({ | ||
name, | ||
date: new Date().toISOString(), | ||
}); | ||
this.write(); | ||
} | ||
|
||
private write() { | ||
this.storage.set(STORAGE_KEY, { clicks: this.clicks, suggestionClicks: this.suggestionClicks }); | ||
} | ||
|
||
public stop() { | ||
if (this.timer) { | ||
clearInterval(this.timer); | ||
} | ||
} | ||
|
||
private async postToServer() { | ||
try { | ||
await this.http.post(`${this.basePath}${BASE_API_URL}/telemetry`, { | ||
body: JSON.stringify({ | ||
clicks: this.clicks, | ||
suggestionClicks: this.clicks, | ||
}), | ||
}); | ||
this.clicks = []; | ||
this.suggestionClicks = []; | ||
this.write(); | ||
} catch (e) { | ||
// Maybe show an error | ||
console.log(e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
export * from './factory'; | ||
export * from './provider'; |
17 changes: 17 additions & 0 deletions
17
x-pack/legacy/plugins/lens/public/lens_ui_telemetry/provider.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { createContext, useContext } from 'react'; | ||
|
||
export const LensTelemetryContext = createContext<{ | ||
trackClick: (name: string) => void; | ||
trackSuggestionClick: (name: string, suggestionData: unknown) => void; | ||
}>({ | ||
trackClick: () => {}, | ||
trackSuggestionClick: () => {}, | ||
}); | ||
|
||
export const useLensTelemetry = () => useContext(LensTelemetryContext); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.