-
Notifications
You must be signed in to change notification settings - Fork 8.6k
Add telemetry for Elastic Cloud #102390
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
Merged
Merged
Add telemetry for Elastic Cloud #102390
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
85d5fa8
Add initial FullStory implementation
joshdover 6fc5772
Fix type from rename
joshdover cf1afb8
Fix license notice
joshdover 66ad855
Remove unused log
joshdover 69c60df
Merge remote-tracking branch 'upstream/master' into fs/script
joshdover cf1576d
Merge remote-tracking branch 'upstream/master' into fs/script
joshdover 4449cf8
Use the username field directly
joshdover File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,100 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| import { sha256 } from 'js-sha256'; | ||
| import type { IBasePath, PackageInfo } from '../../../../src/core/public'; | ||
|
|
||
| export interface FullStoryDeps { | ||
| basePath: IBasePath; | ||
| orgId: string; | ||
| packageInfo: PackageInfo; | ||
| userIdPromise: Promise<string | undefined>; | ||
| } | ||
|
|
||
| interface FullStoryApi { | ||
| identify(userId: string, userVars?: Record<string, any>): void; | ||
| event(eventName: string, eventProperties: Record<string, any>): void; | ||
| } | ||
|
|
||
| export const initializeFullStory = async ({ | ||
| basePath, | ||
| orgId, | ||
| packageInfo, | ||
| userIdPromise, | ||
| }: FullStoryDeps) => { | ||
| // @ts-expect-error | ||
| window._fs_debug = false; | ||
| // @ts-expect-error | ||
| window._fs_host = 'fullstory.com'; | ||
| // @ts-expect-error | ||
| window._fs_script = basePath.prepend(`/internal/cloud/${packageInfo.buildNum}/fullstory.js`); | ||
| // @ts-expect-error | ||
| window._fs_org = orgId; | ||
| // @ts-expect-error | ||
| window._fs_namespace = 'FSKibana'; | ||
|
|
||
| /* eslint-disable */ | ||
| (function(m,n,e,t,l,o,g,y){ | ||
| if (e in m) {if(m.console && m.console.log) { m.console.log('FullStory namespace conflict. Please set window["_fs_namespace"].');} return;} | ||
| // @ts-expect-error | ||
| g=m[e]=function(a,b,s){g.q?g.q.push([a,b,s]):g._api(a,b,s);};g.q=[]; | ||
| // @ts-expect-error | ||
| o=n.createElement(t);o.async=1;o.crossOrigin='anonymous';o.src=_fs_script; | ||
| // @ts-expect-error | ||
| y=n.getElementsByTagName(t)[0];y.parentNode.insertBefore(o,y); | ||
| // @ts-expect-error | ||
| g.identify=function(i,v,s){g(l,{uid:i},s);if(v)g(l,v,s)};g.setUserVars=function(v,s){g(l,v,s)};g.event=function(i,v,s){g('event',{n:i,p:v},s)}; | ||
| // @ts-expect-error | ||
| g.anonymize=function(){g.identify(!!0)}; | ||
| // @ts-expect-error | ||
| g.shutdown=function(){g("rec",!1)};g.restart=function(){g("rec",!0)}; | ||
| // @ts-expect-error | ||
| g.log = function(a,b){g("log",[a,b])}; | ||
| // @ts-expect-error | ||
| g.consent=function(a){g("consent",!arguments.length||a)}; | ||
| // @ts-expect-error | ||
| g.identifyAccount=function(i,v){o='account';v=v||{};v.acctId=i;g(o,v)}; | ||
| // @ts-expect-error | ||
| g.clearUserCookie=function(){}; | ||
| // @ts-expect-error | ||
| g.setVars=function(n, p){g('setVars',[n,p]);}; | ||
| // @ts-expect-error | ||
| g._w={};y='XMLHttpRequest';g._w[y]=m[y];y='fetch';g._w[y]=m[y]; | ||
| // @ts-expect-error | ||
| if(m[y])m[y]=function(){return g._w[y].apply(this,arguments)}; | ||
| // @ts-expect-error | ||
| g._v="1.3.0"; | ||
| // @ts-expect-error | ||
| })(window,document,window['_fs_namespace'],'script','user'); | ||
| /* eslint-enable */ | ||
|
|
||
| // @ts-expect-error | ||
| const fullstory: FullStoryApi = window.FSKibana; | ||
|
|
||
| // Record an event that Kibana was opened so we can easily search for sessions that use Kibana | ||
| // @ts-expect-error | ||
| window.FSKibana.event('Loaded Kibana', { | ||
| kibana_version_str: packageInfo.version, | ||
| }); | ||
|
|
||
| // Use a promise here so we don't have to wait to retrieve the user to start recording the session | ||
| userIdPromise | ||
| .then((userId) => { | ||
| if (!userId) return; | ||
| // Do the hashing here to keep it at clear as possible in our source code that we do not send literal user IDs | ||
| const hashedId = sha256(userId.toString()); | ||
| // @ts-expect-error | ||
| window.FSKibana.identify(hashedId); | ||
| }) | ||
| .catch((e) => { | ||
| // eslint-disable-next-line no-console | ||
| console.error( | ||
| `[cloud.full_story] Could not call FS.identify due to error: ${e.toString()}`, | ||
| e | ||
| ); | ||
| }); | ||
| }; |
This file contains hidden or 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,13 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| import type { FullStoryDeps } from './fullstory'; | ||
|
|
||
| export const initializeFullStoryMock = jest.fn<void, [FullStoryDeps]>(); | ||
| jest.doMock('./fullstory', () => { | ||
| return { initializeFullStory: initializeFullStoryMock }; | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.