Skip to content

Commit

Permalink
Use setUserVars for esorgid
Browse files Browse the repository at this point in the history
  • Loading branch information
lizozom committed Mar 6, 2022
1 parent beac727 commit 86f8820
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
6 changes: 2 additions & 4 deletions x-pack/plugins/cloud/public/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ describe('Cloud Plugin', () => {
version_patch_int: -1,
}
);

expect(fullStoryApiMock.setUserVars).toHaveBeenCalledWith({ org_id_str: 'cloudId' });
});

it('user hash includes org id', async () => {
Expand Down Expand Up @@ -147,15 +149,13 @@ describe('Cloud Plugin', () => {
expect(fullStoryApiMock.setVars).toHaveBeenCalledWith('page', {
pageName: 'App1',
app_id_str: 'App1',
org_id_str: 'cloudId',
});

// context clear
currentContext$.next({});
expect(fullStoryApiMock.setVars).toHaveBeenCalledWith('page', {
pageName: 'App1',
app_id_str: 'App1',
org_id_str: 'cloudId',
});

// different app
Expand All @@ -169,7 +169,6 @@ describe('Cloud Plugin', () => {
app_id_str: 'App2',
page_str: 'page2',
ent_id_str: '123',
org_id_str: 'cloudId',
});

// Back to first app
Expand All @@ -184,7 +183,6 @@ describe('Cloud Plugin', () => {
app_id_str: 'App1',
page_str: 'page3',
ent_id_str: '123',
org_id_str: 'cloudId',
});

expect(currentContext$.observers.length).toBe(1);
Expand Down
5 changes: 4 additions & 1 deletion x-pack/plugins/cloud/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@ export class CloudPlugin implements Plugin<CloudSetup> {
packageInfo: this.initializerContext.env.packageInfo,
});

fullStory.setUserVars({
org_id_str: esOrgId,
});

// Very defensive try/catch to avoid any UnhandledPromiseRejections
try {
// This needs to be called syncronously to be sure that we populate the user ID soon enough to make sessions merging
Expand All @@ -283,7 +287,6 @@ export class CloudPlugin implements Plugin<CloudSetup> {
app_id_str: name ?? 'unknown',
page_str: page,
ent_id_str: id,
org_id_str: esOrgId,
},
isUndefined
)
Expand Down

0 comments on commit 86f8820

Please sign in to comment.