-
Notifications
You must be signed in to change notification settings - Fork 39
Rework Analytics initialization #357
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
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
5e3ca04
feat: add initialization to core package
sc-nikolaoslazaridis f125600
feat: add initialization to analytics-core
sc-nikolaoslazaridis a1433ba
feat: add initialization to events package
sc-nikolaoslazaridis 413278c
feat: add initialization to personalize package
sc-nikolaoslazaridis 8fe8cb0
feat: use content sdk event package in content forms
sc-nikolaoslazaridis a57bde4
chore: use content package in react package
sc-nikolaoslazaridis 11d8acc
chore: content package use content events package
sc-nikolaoslazaridis d82614c
chore: nextjs use content analytics packages
sc-nikolaoslazaridis 0174fde
feat: use content analytics packages, add proxy envs
sc-nikolaoslazaridis aba751a
chore: add normal dep to content package
sc-nikolaoslazaridis 3b1bff1
chore: fixes and sample update
sc-nikolaoslazaridis 37d4a25
Merge branch 'dev' into feature/JSS-8782
sc-nikolaoslazaridis 6411b83
chore: version updates
sc-nikolaoslazaridis 06a5b31
chore: yarn lock
sc-nikolaoslazaridis 5a349f7
docs: add short temporary changelog entry
sc-nikolaoslazaridis fd0d251
chore: make edge url optional in the settings param
sc-nikolaoslazaridis 523c33a
chore: clean template package json
sc-nikolaoslazaridis 155252f
Update packages/events/src/debug.ts
sc-nikolaoslazaridis 6949ca8
Update packages/core/src/initialization/consts.ts
sc-nikolaoslazaridis a84ba7c
chore: add index file under initialization folder in core package
sc-nikolaoslazaridis 5175796
chore: add api extractor tags to types
sc-nikolaoslazaridis 7aee1f9
chore: make interface public
sc-nikolaoslazaridis da2f47f
Update packages/personalize/src/debug.ts
sc-nikolaoslazaridis bc2ebc5
chore: add isNamespaceEnabled function to debug module
sc-nikolaoslazaridis ff9406c
chore: changelog update
sc-nikolaoslazaridis a01b21e
chore: update changelog
sc-nikolaoslazaridis 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 was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
packages/analytics-core/src/browser-id/construct-get-browser-id-url.spec.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
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
57 changes: 26 additions & 31 deletions
57
packages/analytics-core/src/browser-id/get-browser-id.spec.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 |
|---|---|---|
| @@ -1,54 +1,49 @@ | ||
| import * as coreBrowserModule from '../initializer/browser/initializer'; | ||
| import * as pluginsModule from '../initialization/plugin'; | ||
| import { getBrowserId } from './get-browser-id'; | ||
| import { jest, expect } from '@jest/globals'; | ||
|
|
||
| jest.mock('../initializer/browser/initializer'); | ||
| jest.mock('../initialization/plugin'); | ||
|
|
||
| describe('getBrowserId', () => { | ||
| const getCloudSDKSettingsSpy = jest | ||
| .spyOn(coreBrowserModule, 'getCloudSDKSettings') | ||
| .mockReturnValue({ | ||
| cookieSettings: { | ||
| domain: 'cDomain', | ||
| expiryDays: 730, | ||
| name: { browserId: 'bid_name' }, | ||
| path: '/', | ||
| }, | ||
| siteName: '456', | ||
| sitecoreEdgeContextId: '123', | ||
| sitecoreEdgeUrl: '', | ||
| }); | ||
| const mockEnvironment = { | ||
| getBrowserId: jest.fn(), | ||
| }; | ||
|
|
||
| const getAnalyticsPluginSpy = jest.spyOn(pluginsModule, 'getAnalyticsPlugin').mockReturnValue({ | ||
| environment: mockEnvironment, | ||
| } as unknown as ReturnType<typeof pluginsModule.getAnalyticsPlugin>); | ||
|
|
||
| afterEach(() => { | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| it('should return the cookie value when cookie exists on the page', async () => { | ||
| jest.spyOn(document, 'cookie', 'get').mockReturnValueOnce(`bid_name=bid_value`); | ||
|
|
||
| const mockCoreBrowserModule = coreBrowserModule as { initCoreState: Promise<void> }; | ||
| mockCoreBrowserModule.initCoreState = Promise.resolve(); | ||
| it('should return the browser ID when environment returns a value', () => { | ||
| mockEnvironment.getBrowserId.mockReturnValueOnce('bid_value'); | ||
|
|
||
| const browserId = getBrowserId(); | ||
|
|
||
| expect(browserId).toEqual('bid_value'); | ||
| expect(getCloudSDKSettingsSpy).toHaveBeenCalledTimes(1); | ||
| expect(getAnalyticsPluginSpy).toHaveBeenCalledTimes(1); | ||
| expect(mockEnvironment.getBrowserId).toHaveBeenCalledTimes(1); | ||
| }); | ||
|
|
||
| it('should return empty string if there is a cookie but not the correct one', async () => { | ||
| jest.spyOn(document, 'cookie', 'get').mockReturnValueOnce('WrongCookieName=cookieValue'); | ||
|
|
||
| const mockCoreBrowserModule = coreBrowserModule as { initCoreState: Promise<void> }; | ||
| mockCoreBrowserModule.initCoreState = Promise.resolve(); | ||
| it('should return empty string when environment returns null', () => { | ||
| mockEnvironment.getBrowserId.mockReturnValueOnce(null); | ||
|
|
||
| const browserId = getBrowserId(); | ||
|
|
||
| expect(browserId).toEqual(''); | ||
| expect(getCloudSDKSettingsSpy).toHaveBeenCalledTimes(1); | ||
| expect(getAnalyticsPluginSpy).toHaveBeenCalledTimes(1); | ||
| expect(mockEnvironment.getBrowserId).toHaveBeenCalledTimes(1); | ||
| }); | ||
| it('should return empty string if no cookie exists on the page', async () => { | ||
| const mockCoreBrowserModule = coreBrowserModule as { initCoreState: Promise<void> }; | ||
| mockCoreBrowserModule.initCoreState = Promise.resolve(); | ||
|
|
||
| it('should return empty string when environment returns undefined', () => { | ||
| mockEnvironment.getBrowserId.mockReturnValueOnce(undefined); | ||
|
|
||
| const browserId = getBrowserId(); | ||
|
|
||
| expect(browserId).toBe(''); | ||
| expect(getCloudSDKSettingsSpy).toHaveBeenCalledTimes(1); | ||
| expect(getAnalyticsPluginSpy).toHaveBeenCalledTimes(1); | ||
| expect(mockEnvironment.getBrowserId).toHaveBeenCalledTimes(1); | ||
| }); | ||
| }); |
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 |
|---|---|---|
| @@ -1,12 +1,9 @@ | ||
| import { getCookieValueClientSide } from '../utils'; | ||
| import { getCloudSDKSettings } from '../initializer/browser/initializer'; | ||
| import { getAnalyticsPlugin } from '../internal'; | ||
|
|
||
| /** | ||
| * Gets the browser ID from the cookie. | ||
| * @returns {string} The browser ID if the cookie exists. | ||
| */ | ||
| export function getBrowserId(): string { | ||
| const cloudSDKSettings = getCloudSDKSettings(); | ||
|
|
||
| return getCookieValueClientSide(cloudSDKSettings.cookieSettings.name.browserId); | ||
| return getAnalyticsPlugin().environment.getBrowserId() || ''; | ||
| } |
This file was deleted.
Oops, something went wrong.
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
45 changes: 0 additions & 45 deletions
45
packages/analytics-core/src/cookie/get-cookie-value-from-middleware-request.spec.ts
This file was deleted.
Oops, something went wrong.
22 changes: 0 additions & 22 deletions
22
packages/analytics-core/src/cookie/get-cookie-value-from-middleware-request.ts
This file was deleted.
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.