-
Notifications
You must be signed in to change notification settings - Fork 222
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option to disable
performanceNavigationTiming
plugin (#1375)
- Loading branch information
Showing
4 changed files
with
75 additions
and
8 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
...s/@snowplow/javascript-tracker/performance-navigation-timing-config_2024-11-11-14-14.json
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 @@ | ||
{ | ||
"changes": [ | ||
{ | ||
"packageName": "@snowplow/javascript-tracker", | ||
"comment": "Add `performanceNavigationTiming` option to JS contexts config", | ||
"type": "none" | ||
} | ||
], | ||
"packageName": "@snowplow/javascript-tracker" | ||
} |
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
61 changes: 61 additions & 0 deletions
61
trackers/javascript-tracker/test/unit/plugin_features.test.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,61 @@ | ||
import { SelfDescribingJson } from '@snowplow/tracker-core'; | ||
import { Plugins } from '../../src/features'; | ||
|
||
describe('Performance Navigation Timing', () => { | ||
let windowSpy: any; | ||
|
||
const otherContexts = { | ||
webPage: false, | ||
session: false, | ||
performanceTiming: false, | ||
gaCookies: false, | ||
geolocation: false, | ||
clientHints: false, | ||
webVitals: false, | ||
}; | ||
|
||
const hasPerformanceNavigationTimingContext = (plugins: ReturnType<typeof Plugins>): boolean => { | ||
const pluginContexts = plugins.map((plugin) => plugin[0]?.contexts?.()); | ||
const hasPerformanceContext = pluginContexts.some((contexts?: SelfDescribingJson[]) => | ||
contexts?.some( | ||
(context: { schema?: string }) => context.schema === 'iglu:org.w3/PerformanceNavigationTiming/jsonschema/1-0-0' | ||
) | ||
); | ||
return hasPerformanceContext; | ||
}; | ||
|
||
beforeEach(() => { | ||
windowSpy = jest.spyOn(global, 'window', 'get'); | ||
|
||
// The PerformanceNavigationTiming context will only be added if the plugin can: | ||
// - Access the `performance` object on the window | ||
// - See that a value is returned from `getEntriesByType` | ||
windowSpy.mockImplementation(() => ({ | ||
performance: { | ||
getEntriesByType: () => [{}], | ||
}, | ||
})); | ||
}); | ||
|
||
it('Is enabled if contexts.performanceNavigationTiming is true', () => { | ||
const plugins = Plugins({ | ||
contexts: { | ||
performanceNavigationTiming: true, | ||
...otherContexts, | ||
}, | ||
}); | ||
|
||
expect(hasPerformanceNavigationTimingContext(plugins)).toBe(true); | ||
}); | ||
|
||
it('Is disabled if contexts.performanceNavigationTiming is false', () => { | ||
const plugins = Plugins({ | ||
contexts: { | ||
performanceNavigationTiming: false, | ||
...otherContexts, | ||
}, | ||
}); | ||
|
||
expect(hasPerformanceNavigationTimingContext(plugins)).toBe(false); | ||
}); | ||
}); |