-
Notifications
You must be signed in to change notification settings - Fork 190
✨ Add initial Salesforce support. #4676
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
Closed
Closed
Changes from 3 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
d32f6ea
Add initial Salesforce support.
BeltranBulbarellaDD c02e9bf
Guard session
BeltranBulbarellaDD 2fcb2ee
Linting
BeltranBulbarellaDD 0d952b5
Add Resources and APM support
BeltranBulbarellaDD d6d525e
Make getGlobalLocationHref mockable, patch plain usage of location
BeltranBulbarellaDD 363201b
use wire
BeltranBulbarellaDD 2655dc5
Merge branch 'main' into beltran.bulbarella/salesforce_0
BeltranBulbarellaDD 6a2eb32
Refactor for comments
BeltranBulbarellaDD 059c321
Merge branch 'main' into beltran.bulbarella/salesforce_0
BeltranBulbarellaDD f7581c2
Fix bundle
BeltranBulbarellaDD 783c96b
Use globalObject in turn of window
BeltranBulbarellaDD a8474b6
Add isCSPEventSupported function
BeltranBulbarellaDD 59232c7
Create isEventSupported and reuse it
BeltranBulbarellaDD 4f0711a
linter
BeltranBulbarellaDD 721c1a2
Remove config parameter from isEventSupported
BeltranBulbarellaDD 41a66d7
Remove views plugin and try catch debug
BeltranBulbarellaDD 045bd3c
linter
BeltranBulbarellaDD 3293b46
Fix compat
BeltranBulbarellaDD 1f4c882
Revert changes to instrumentMethod.ts
BeltranBulbarellaDD a52f0d5
Move view tracking to bundle, rename bundle
BeltranBulbarellaDD a56d75f
Merge branch 'main' into beltran.bulbarella/salesforce_0
BeltranBulbarellaDD ff6a526
Move SF packages, add README
BeltranBulbarellaDD 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
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
187 changes: 187 additions & 0 deletions
187
packages/rum-slim/src/domain/salesforce/viewNameTracker.ts
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,187 @@ | ||
| import { addEventListener, buildUrl, DOM_EVENT, instrumentMethod, noop, setTimeout } from '@datadog/browser-core' | ||
| import type { RumPublicApi, ViewOptions } from '@datadog/browser-rum-core' | ||
|
|
||
| export interface SalesforceLocation { | ||
| pathname?: string | ||
| href?: string | ||
| } | ||
|
|
||
| interface StartSalesforceViewNameTrackingOptions { | ||
| getRumPublicApi: () => Pick<RumPublicApi, 'setViewName' | 'startView'> | undefined | ||
| getLocation?: () => SalesforceLocation | undefined | ||
| } | ||
|
|
||
| interface SalesforceView { | ||
| key: string | ||
| url?: string | ||
| } | ||
|
|
||
| export function startSalesforceViewNameTracking(options: StartSalesforceViewNameTrackingOptions) { | ||
| const getLocation = options.getLocation ?? getNavigationLocation | ||
| const initialView = resolveCurrentView(getLocation()) | ||
| let lastViewKey = initialView?.key | ||
| const eventListenerConfiguration = { allowUntrustedEvents: true } | ||
|
|
||
| if (initialView) { | ||
| setCurrentViewName(initialView) | ||
| } | ||
|
|
||
| const { stop: stopInstrumentingPushState } = instrumentMethod( | ||
| getHistoryInstrumentationTarget('pushState'), | ||
| 'pushState', | ||
| ({ onPostCall }) => { | ||
| onPostCall(scheduleSetCurrentViewName) | ||
| } | ||
| ) | ||
| const { stop: stopInstrumentingReplaceState } = instrumentMethod( | ||
| getHistoryInstrumentationTarget('replaceState'), | ||
| 'replaceState', | ||
| ({ onPostCall }) => { | ||
| onPostCall(scheduleSetCurrentViewName) | ||
| } | ||
| ) | ||
|
|
||
| const { stop: stopListeningPopState } = addEventListener( | ||
| eventListenerConfiguration, | ||
| window, | ||
| DOM_EVENT.POP_STATE, | ||
| scheduleSetCurrentViewName | ||
| ) | ||
| const { stop: stopListeningHashChange } = addEventListener( | ||
| eventListenerConfiguration, | ||
| window, | ||
| DOM_EVENT.HASH_CHANGE, | ||
| scheduleSetCurrentViewName | ||
| ) | ||
| const { stop: stopListeningClick } = addEventListener( | ||
| eventListenerConfiguration, | ||
| window, | ||
| DOM_EVENT.CLICK, | ||
| scheduleLocationCheckAfterClick, | ||
| { capture: true } | ||
| ) | ||
|
|
||
| function scheduleLocationCheckAfterClick() { | ||
| setTimeout(trackCurrentView, 0) | ||
| setTimeout(trackCurrentView, 100) | ||
| setTimeout(trackCurrentView, 500) | ||
| } | ||
|
|
||
| function scheduleSetCurrentViewName() { | ||
| setTimeout(trackCurrentView, 0) | ||
| } | ||
|
|
||
| function trackCurrentView() { | ||
| const currentView = resolveCurrentView(getLocation()) | ||
|
|
||
| if (!currentView) { | ||
| return | ||
| } | ||
|
|
||
| if (!lastViewKey || currentView.key === lastViewKey) { | ||
| setCurrentViewName(currentView) | ||
| lastViewKey = currentView.key | ||
| return | ||
| } | ||
|
|
||
| options.getRumPublicApi()?.startView(toViewOptions(currentView)) | ||
| lastViewKey = currentView.key | ||
| } | ||
|
|
||
| function setCurrentViewName(view: SalesforceView) { | ||
| options.getRumPublicApi()?.setViewName(view.key) | ||
| } | ||
|
|
||
| return { | ||
| stop() { | ||
| stopInstrumentingPushState() | ||
| stopInstrumentingReplaceState() | ||
| stopListeningPopState() | ||
| stopListeningHashChange() | ||
| stopListeningClick() | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| function getNavigationLocation(): SalesforceLocation | undefined { | ||
| try { | ||
| return { | ||
| href: window.location.href, | ||
| pathname: window.location.pathname, | ||
| } | ||
| } catch { | ||
| return undefined | ||
| } | ||
| } | ||
|
|
||
| function resolveCurrentView(location: SalesforceLocation | undefined): SalesforceView | undefined { | ||
| if (!location) { | ||
| return undefined | ||
| } | ||
|
|
||
| const url = normalizeLocationHref(location.href) | ||
| const key = normalizePathname(location.pathname) ?? getPathnameFromHref(url) | ||
|
|
||
| if (!key) { | ||
| return undefined | ||
| } | ||
|
|
||
| return { | ||
| key, | ||
| url, | ||
| } | ||
| } | ||
|
|
||
| function toViewOptions(view: SalesforceView): ViewOptions { | ||
| return view.url ? { name: view.key, url: view.url } : { name: view.key } | ||
| } | ||
|
|
||
| function getPathnameFromHref(href: string | undefined) { | ||
| if (!href) { | ||
| return undefined | ||
| } | ||
|
|
||
| try { | ||
| return normalizePathname(buildUrl(href).pathname) | ||
| } catch { | ||
| return undefined | ||
| } | ||
| } | ||
|
|
||
| function normalizeLocationHref(href: unknown) { | ||
| if (typeof href !== 'string' || !href.trim()) { | ||
| return undefined | ||
| } | ||
|
|
||
| try { | ||
| return buildUrl(href).href | ||
| } catch { | ||
| return undefined | ||
| } | ||
| } | ||
|
|
||
| function normalizePathname(pathname: unknown) { | ||
| if (typeof pathname !== 'string' || !pathname.trim()) { | ||
| return undefined | ||
| } | ||
|
|
||
| let normalizedPathname = pathname.trim() | ||
|
|
||
| if (!normalizedPathname.startsWith('/')) { | ||
| normalizedPathname = `/${normalizedPathname}` | ||
| } | ||
|
|
||
| if (normalizedPathname.length > 1) { | ||
| normalizedPathname = normalizedPathname.replace(/\/+$/, '') | ||
| } | ||
|
|
||
| return normalizedPathname || '/' | ||
| } | ||
|
|
||
| function getHistoryInstrumentationTarget(methodName: 'pushState' | 'replaceState') { | ||
| if (typeof History === 'undefined') { | ||
| return { [methodName]: noop } | ||
| } | ||
|
|
||
| return Object.prototype.hasOwnProperty.call(history, methodName) ? history : History.prototype | ||
| } |
Oops, something went wrong.
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.