-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[FullStory] Limit number of pageVars #159725
Merged
afharo
merged 2 commits into
elastic:main
from
afharo:fullstory/limit-number-of-page-vars
Jun 15, 2023
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,12 +12,39 @@ import type { | |
Event, | ||
IShipper, | ||
} from '@kbn/analytics-client'; | ||
import { get, has } from 'lodash'; | ||
import { set } from '@kbn/safer-lodash-set'; | ||
import type { FullStoryApi } from './types'; | ||
import type { FullStorySnippetConfig } from './load_snippet'; | ||
import { formatPayload } from './format_payload'; | ||
import { loadSnippet } from './load_snippet'; | ||
import { getParsedVersion } from './get_parsed_version'; | ||
|
||
const PAGE_VARS_KEYS = [ | ||
// Page-specific keys | ||
'pageName', | ||
'page', | ||
'entityId', | ||
'applicationId', | ||
|
||
// Deployment-specific keys | ||
'version', // x4, split to version_major, version_minor, version_patch for easier filtering | ||
'buildNum', // May be useful for Serverless | ||
'cloudId', | ||
'deploymentId', | ||
'cluster_name', | ||
'cluster_uuid', | ||
'cluster_version', | ||
'labels.serverless', | ||
'license_id', | ||
'license_status', | ||
'license_type', | ||
|
||
// Session-specific | ||
'session_id', | ||
'preferred_languages', | ||
] as const; | ||
|
||
/** | ||
* FullStory shipper configuration. | ||
*/ | ||
|
@@ -62,7 +89,13 @@ export class FullStoryShipper implements IShipper { | |
this.initContext.logger.debug(`Received context ${JSON.stringify(newContext)}`); | ||
|
||
// FullStory requires different APIs for different type of contexts. | ||
const { userId, isElasticCloudUser, ...nonUserContext } = newContext; | ||
const { | ||
userId, | ||
isElasticCloudUser, | ||
cloudIsElasticStaffOwned, | ||
cloudTrialEndDate, | ||
...nonUserContext | ||
} = newContext; | ||
|
||
// Call it only when the userId changes | ||
if (userId && userId !== this.lastUserId) { | ||
|
@@ -73,30 +106,37 @@ export class FullStoryShipper implements IShipper { | |
} | ||
|
||
// User-level context | ||
if (typeof isElasticCloudUser === 'boolean') { | ||
this.initContext.logger.debug( | ||
`Calling FS.setUserVars with isElasticCloudUser ${isElasticCloudUser}` | ||
); | ||
this.fullStoryApi.setUserVars( | ||
formatPayload({ | ||
isElasticCloudUser, | ||
}) | ||
); | ||
if ( | ||
typeof isElasticCloudUser === 'boolean' || | ||
typeof cloudIsElasticStaffOwned === 'boolean' || | ||
cloudTrialEndDate | ||
) { | ||
const userVars = { | ||
isElasticCloudUser, | ||
cloudIsElasticStaffOwned, | ||
cloudTrialEndDate, | ||
}; | ||
this.initContext.logger.debug(`Calling FS.setUserVars with ${JSON.stringify(userVars)}`); | ||
this.fullStoryApi.setUserVars(formatPayload(userVars)); | ||
} | ||
|
||
// Cherry-picking fields because FS limits the number of fields that can be sent. | ||
// > Note: You can capture up to 20 unique page properties (exclusive of pageName) for any given page | ||
// > and up to 500 unique page properties across all pages. | ||
// https://help.fullstory.com/hc/en-us/articles/1500004101581-FS-setVars-API-Sending-custom-page-data-to-FullStory | ||
const pageVars = PAGE_VARS_KEYS.reduce((acc, key) => { | ||
if (has(nonUserContext, key)) { | ||
set(acc, key, get(nonUserContext, key)); | ||
} | ||
return acc; | ||
}, {} as Partial<Pick<EventContext, typeof PAGE_VARS_KEYS[number]>> & Record<string, unknown>); | ||
|
||
// Event-level context. At the moment, only the scope `page` is supported by FullStory for webapps. | ||
if (Object.keys(nonUserContext).length) { | ||
// Keeping these fields for backwards compatibility. | ||
if (nonUserContext.applicationId) nonUserContext.app_id = nonUserContext.applicationId; | ||
if (nonUserContext.entityId) nonUserContext.ent_id = nonUserContext.entityId; | ||
if (nonUserContext.cloudId) nonUserContext.org_id = nonUserContext.cloudId; | ||
Comment on lines
-89
to
-92
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we are mostly interested in trial users, most reports don't care about BWC. |
||
|
||
this.initContext.logger.debug( | ||
`Calling FS.setVars with context ${JSON.stringify(nonUserContext)}` | ||
); | ||
if (Object.keys(pageVars).length) { | ||
this.initContext.logger.debug(`Calling FS.setVars with context ${JSON.stringify(pageVars)}`); | ||
this.fullStoryApi.setVars('page', { | ||
...formatPayload(nonUserContext), | ||
...(nonUserContext.version ? getParsedVersion(nonUserContext.version) : {}), | ||
...formatPayload(pageVars), | ||
...(pageVars.version ? getParsedVersion(pageVars.version) : {}), | ||
}); | ||
} | ||
} | ||
|
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we promoted
cloudIsElasticStaffOwned
andcloudTrialEndDate
to the user level because they are account-related.