Skip to content
Merged
Show file tree
Hide file tree
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 Jan 28, 2026
f125600
feat: add initialization to analytics-core
sc-nikolaoslazaridis Jan 28, 2026
a1433ba
feat: add initialization to events package
sc-nikolaoslazaridis Jan 28, 2026
413278c
feat: add initialization to personalize package
sc-nikolaoslazaridis Jan 28, 2026
8fe8cb0
feat: use content sdk event package in content forms
sc-nikolaoslazaridis Jan 28, 2026
a57bde4
chore: use content package in react package
sc-nikolaoslazaridis Jan 29, 2026
11d8acc
chore: content package use content events package
sc-nikolaoslazaridis Jan 29, 2026
d82614c
chore: nextjs use content analytics packages
sc-nikolaoslazaridis Jan 29, 2026
0174fde
feat: use content analytics packages, add proxy envs
sc-nikolaoslazaridis Jan 29, 2026
aba751a
chore: add normal dep to content package
sc-nikolaoslazaridis Jan 29, 2026
3b1bff1
chore: fixes and sample update
sc-nikolaoslazaridis Jan 29, 2026
37d4a25
Merge branch 'dev' into feature/JSS-8782
sc-nikolaoslazaridis Jan 29, 2026
6411b83
chore: version updates
sc-nikolaoslazaridis Jan 29, 2026
06a5b31
chore: yarn lock
sc-nikolaoslazaridis Jan 29, 2026
5a349f7
docs: add short temporary changelog entry
sc-nikolaoslazaridis Jan 29, 2026
fd0d251
chore: make edge url optional in the settings param
sc-nikolaoslazaridis Jan 30, 2026
523c33a
chore: clean template package json
sc-nikolaoslazaridis Jan 30, 2026
155252f
Update packages/events/src/debug.ts
sc-nikolaoslazaridis Feb 2, 2026
6949ca8
Update packages/core/src/initialization/consts.ts
sc-nikolaoslazaridis Feb 2, 2026
a84ba7c
chore: add index file under initialization folder in core package
sc-nikolaoslazaridis Feb 2, 2026
5175796
chore: add api extractor tags to types
sc-nikolaoslazaridis Feb 2, 2026
7aee1f9
chore: make interface public
sc-nikolaoslazaridis Feb 2, 2026
da2f47f
Update packages/personalize/src/debug.ts
sc-nikolaoslazaridis Feb 2, 2026
bc2ebc5
chore: add isNamespaceEnabled function to debug module
sc-nikolaoslazaridis Feb 2, 2026
ff9406c
chore: changelog update
sc-nikolaoslazaridis Feb 2, 2026
a01b21e
chore: update changelog
sc-nikolaoslazaridis Feb 3, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@ Our versioning strategy is as follows:
* `[react]` Added React hooks for search functionality
- `useSearch` hook for paginated search queries with automatic state management, request cancellation, request status tracking.
- `useInfiniteSearch` hook for infinite scroll/search patterns with `loadMore` functionality, request cancellation, request status tracking.
* `[analytics]` `[core]` `[create-content-sdk-app]` `[nextjs]` `[react]` Reorganize Analytics packages ([#340](https://github.com/Sitecore/content-sdk/pull/340))([#341](https://github.com/Sitecore/content-sdk/pull/341))

* `[nextjs]` `[Pages Router]` Adjust static path generation when multisite is disabled ([#345](https://github.com/Sitecore/content-sdk/pull/345))

* Introduce Analytics packages:
* `[analytics]` `[core]` `[create-content-sdk-app]` `[nextjs]` `[react]` Reorganize Analytics packages ([#340](https://github.com/Sitecore/content-sdk/pull/340))([#341](https://github.com/Sitecore/content-sdk/pull/341))
* `[sdk]` Rework Analytics initialization ([#357](https://github.com/Sitecore/content-sdk/pull/357))

### 🛠 Breaking Changes

* Decouple `@sitecore-content-sdk/content` from `@sitecore-content-sdk/core` ([#351](https://github.com/Sitecore/content-sdk/pull/351)):
Expand Down
2 changes: 0 additions & 2 deletions packages/analytics-core/browser.d.ts

This file was deleted.

21 changes: 10 additions & 11 deletions packages/analytics-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"url": "https://github.com/sitecore/content-sdk/issues"
},
"dependencies": {
"@sitecore-content-sdk/core": "1.5.0-canary.6",
"debug": "^4.4.3"
},
"description": "> TODO: description",
Expand All @@ -29,26 +30,24 @@
"ts-jest": "^29.1.0",
"ts-node": "^10.9.2"
},
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"types": "types/src/index.d.ts",
"exports": {
Comment thread
sc-nikolaoslazaridis marked this conversation as resolved.
"./browser": {
"import": "./dist/esm/src/browser.js",
"require": "./dist/cjs/src/browser.js",
"types": "./types/src/browser/index.d.ts"
".": {
"import": "./dist/esm/src/index.js",
"require": "./dist/cjs/src/index.js",
"types": "./types/src/index.d.ts"
},
"./internal": {
"import": "./dist/esm/src/internal.js",
"require": "./dist/cjs/src/internal.js",
"types": "./types/src/internal/index.d.ts"
},
"./server": {
"import": "./dist/esm/src/server.js",
"require": "./dist/cjs/src/server.js",
"types": "./types/src/server/index.d.ts"
"types": "./types/src/internal.d.ts"
},
"./utils": {
"import": "./dist/esm/src/utils.js",
"require": "./dist/cjs/src/utils.js",
"types": "./types/src/utils/index.d.ts"
"types": "./types/src/utils.d.ts"
}
},
"files": [
Expand Down
2 changes: 0 additions & 2 deletions packages/analytics-core/server.d.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { SITECORE_EDGE_URL } from '../consts';
import { constructGetBrowserIdUrl } from './construct-get-browser-id-url';
import { expect } from '@jest/globals';

describe('constructGetBrowserIdUrl', () => {
it('should correctly create the URL for retrieving the browser Id from EDGE events proxy', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import * as utils from '../utils';
import { ErrorMessages, LIBRARY_VERSION, SITECORE_EDGE_URL } from '../consts';
import { ERROR_MESSAGES, LIBRARY_VERSION, SITECORE_EDGE_URL } from '../consts';
import type { EPResponse } from '../interfaces';
import * as constructGetBrowserIdUrl from './construct-get-browser-id-url';
import { fetchBrowserIdFromEdgeProxy } from './fetch-browser-id-from-edge-proxy';
import { jest, expect } from '@jest/globals';

describe('fetchBrowserIdFromEdgeProxy', () => {
const constructBrowserIdUrlSpy = jest.spyOn(constructGetBrowserIdUrl, 'constructGetBrowserIdUrl');
Expand Down Expand Up @@ -87,7 +88,7 @@ describe('fetchBrowserIdFromEdgeProxy', () => {

global.fetch = jest.fn(() => Promise.reject(abortError));

const expectedError = ErrorMessages.IE_0003;
const expectedError = ERROR_MESSAGES.IE_0003;

expect(async () => {
await fetchBrowserIdFromEdgeProxy(SITECORE_EDGE_URL, sitecoreEdgeContextId);
Expand All @@ -97,7 +98,7 @@ describe('fetchBrowserIdFromEdgeProxy', () => {
it('should throw IE-0003 error if fetch returns null - fetchWithTimeout', async () => {
const fetchWithTimeoutSpy = jest.spyOn(utils, 'fetchWithTimeout').mockResolvedValue(null);

const expectedError = ErrorMessages.IE_0003;
const expectedError = ERROR_MESSAGES.IE_0003;

expect(async () => {
await fetchBrowserIdFromEdgeProxy(SITECORE_EDGE_URL, sitecoreEdgeContextId, 100);
Expand All @@ -110,7 +111,7 @@ describe('fetchBrowserIdFromEdgeProxy', () => {
.spyOn(utils, 'fetchWithTimeout')
.mockRejectedValueOnce({ message: 'random error' });

const expectedError = ErrorMessages.IE_0003;
const expectedError = ERROR_MESSAGES.IE_0003;

expect(async () => {
await fetchBrowserIdFromEdgeProxy(SITECORE_EDGE_URL, sitecoreEdgeContextId, 100);
Expand All @@ -120,23 +121,23 @@ describe('fetchBrowserIdFromEdgeProxy', () => {

it('should throw [IV-0006] when we pass negative timeout value', async () => {
const fetchWithTimeoutSpy = jest.spyOn(utils, 'fetchWithTimeout').mockRejectedValueOnce({
message: utils.ErrorMessages.IV_0006,
message: utils.ERROR_MESSAGES.IV_0006,
});

expect(async () => {
await fetchBrowserIdFromEdgeProxy(SITECORE_EDGE_URL, sitecoreEdgeContextId, -100);
}).rejects.toThrow(utils.ErrorMessages.IV_0006);
}).rejects.toThrow(utils.ERROR_MESSAGES.IV_0006);
expect(fetchWithTimeoutSpy).toHaveBeenCalledTimes(1);
});

it('should throw [IE-0002] when we get an AbortError', async () => {
const fetchWithTimeoutSpy = jest.spyOn(utils, 'fetchWithTimeout').mockRejectedValueOnce({
message: utils.ErrorMessages.IE_0002,
message: utils.ERROR_MESSAGES.IE_0002,
});

await expect(async () => {
await fetchBrowserIdFromEdgeProxy(SITECORE_EDGE_URL, sitecoreEdgeContextId, 100);
}).rejects.toThrow(utils.ErrorMessages.IE_0002);
}).rejects.toThrow(utils.ERROR_MESSAGES.IE_0002);
expect(fetchWithTimeoutSpy).toHaveBeenCalledTimes(1);
});
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { EPResponse, ProxySettings } from '../interfaces';
import { ErrorMessages, LIBRARY_VERSION } from '../consts';
import { ErrorMessages as UtilsErrorMessages, fetchWithTimeout } from '../utils';
import { ERROR_MESSAGES, LIBRARY_VERSION } from '../consts';
import { ERROR_MESSAGES as UTILS_ERROR_MESSAGES, fetchWithTimeout } from '../utils';
import { constructGetBrowserIdUrl } from './construct-get-browser-id-url';

/**
Expand Down Expand Up @@ -33,8 +33,8 @@ export async function fetchBrowserIdFromEdgeProxy(
})
.catch((err) => {
if (
err.message === UtilsErrorMessages.IV_0006 ||
err.message === UtilsErrorMessages.IE_0002
err.message === UTILS_ERROR_MESSAGES.IV_0006 ||
err.message === UTILS_ERROR_MESSAGES.IE_0002
)
throw new Error(err.message);

Expand All @@ -45,7 +45,7 @@ export async function fetchBrowserIdFromEdgeProxy(
.then((res) => res.json())
.catch(() => undefined);

if (!payload?.ref) throw new Error(ErrorMessages.IE_0003);
if (!payload?.ref) throw new Error(ERROR_MESSAGES.IE_0003);

const { ref: browserId, customer_ref: guestId }: EPResponse = payload;
return { browserId, guestId };
Expand Down
57 changes: 26 additions & 31 deletions packages/analytics-core/src/browser-id/get-browser-id.spec.ts
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);
});
});
7 changes: 2 additions & 5 deletions packages/analytics-core/src/browser-id/get-browser-id.ts
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() || '';
}
5 changes: 0 additions & 5 deletions packages/analytics-core/src/browser.ts

This file was deleted.

17 changes: 5 additions & 12 deletions packages/analytics-core/src/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,8 @@ export const API_VERSION = 'v1.2';
export const SITECORE_EDGE_URL = 'https://edge-platform.sitecorecloud.io';

export const CORRELATION_ID_HEADER = 'x-sc-correlation-id';
/* eslint-disable max-len */
export enum ErrorMessages {
IE_0001 = `[IE-0001] You are trying to run a browser-side function on the server side. On the server side, run the server-side equivalent of the function, available in "server" modules.`,
IE_0003 = '[IE-0003] Unable to set the "sc_{SitecoreEdgeContextId}" cookie because the browser ID could not be retrieved from the server. Make sure to set the correct values for "sitecoreEdgeContextId" and "siteName". If the issue persists, try again later or use try-catch blocks to handle this error.',
IE_0011 = '[IE-0011] Unable to set the "sc_{SitecoreEdgeContextId}_personalize" cookie because the guest ID could not be retrieved from the server. Make sure to set the correct values for "sitecoreEdgeContextId" and "siteName". If the issue persists, try again later or use try-catch blocks to handle this error.',
IE_0012 = '[IE-0012] You must first initialize the Cloud SDK. Import "CloudSDK" from "@sitecore-content-sdk/analytics-core/browser", then run "CloudSDK().initialize()".',
IE_0013 = '[IE-0013] You must first initialize the Cloud SDK. Import "CloudSDK" from "@sitecore-content-sdk/analytics-core/server", then run "await CloudSDK().initialize()".',
IV_0001 = '[IV-0001] Incorrect value for "sitecoreEdgeUrl". Set the value to a valid URL string.',
MV_0001 = '[MV-0001] "sitecoreEdgeContextId" is required.',
MV_0002 = '[MV-0002] "siteName" is required.',
}
/* eslint-enable max-len */

export const ERROR_MESSAGES = {
IE_0003:
'[IE-0003] Unable to set the "sc_cid" cookie because the browser ID could not be retrieved from the server. Make sure to set the correct values for "contextId" and "siteName". If the issue persists, try again later or use try-catch blocks to handle this error.',
} as const;

This file was deleted.

This file was deleted.

Loading