@sitecore-cloudsdk/events 0.3.0 → 0.3.1-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/package.json +3 -3
- package/dist/cjs/src/lib/consts.d.ts +4 -0
- package/dist/cjs/src/lib/consts.js +8 -2
- package/dist/cjs/src/lib/eventStorage/addToEventQueue.d.ts +1 -1
- package/dist/cjs/src/lib/eventStorage/addToEventQueue.js +3 -3
- package/dist/cjs/src/lib/eventStorage/eventStorage.d.ts +1 -1
- package/dist/cjs/src/lib/eventStorage/eventStorage.js +3 -4
- package/dist/cjs/src/lib/events/base-event.d.ts +2 -1
- package/dist/cjs/src/lib/events/base-event.js +3 -2
- package/dist/cjs/src/lib/events/common-interfaces.d.ts +1 -1
- package/dist/cjs/src/lib/events/custom-event/custom-event.d.ts +11 -4
- package/dist/cjs/src/lib/events/custom-event/custom-event.js +14 -7
- package/dist/cjs/src/lib/events/custom-event/event.d.ts +2 -2
- package/dist/cjs/src/lib/events/custom-event/event.js +2 -2
- package/dist/cjs/src/lib/events/custom-event/eventServer.d.ts +3 -3
- package/dist/cjs/src/lib/events/custom-event/eventServer.js +3 -3
- package/dist/cjs/src/lib/events/custom-event/form.d.ts +1 -1
- package/dist/cjs/src/lib/events/custom-event/form.js +5 -5
- package/dist/cjs/src/lib/events/identity/identity-event.d.ts +4 -4
- package/dist/cjs/src/lib/events/identity/identity-event.js +11 -12
- package/dist/cjs/src/lib/events/identity/identity.d.ts +2 -2
- package/dist/cjs/src/lib/events/identity/identity.js +2 -2
- package/dist/cjs/src/lib/events/identity/identityServer.d.ts +3 -3
- package/dist/cjs/src/lib/events/identity/identityServer.js +3 -3
- package/dist/cjs/src/lib/events/page-view/page-view-event.d.ts +13 -6
- package/dist/cjs/src/lib/events/page-view/page-view-event.js +24 -17
- package/dist/cjs/src/lib/events/page-view/page-view-server.d.ts +4 -4
- package/dist/cjs/src/lib/events/page-view/page-view-server.js +3 -3
- package/dist/cjs/src/lib/events/page-view/page-view.d.ts +4 -4
- package/dist/cjs/src/lib/events/page-view/page-view.js +3 -3
- package/dist/cjs/src/lib/events/send-event/sendEvent.d.ts +2 -2
- package/dist/cjs/src/lib/events/send-event/sendEvent.js +12 -7
- package/dist/cjs/src/lib/getGuestId/getGuestId.js +1 -1
- package/dist/cjs/src/lib/initializer/browser/initializer.d.ts +13 -1
- package/dist/cjs/src/lib/initializer/browser/initializer.js +3 -3
- package/dist/cjs/src/lib/initializer/server/initializer.d.ts +3 -3
- package/dist/cjs/src/lib/initializer/server/initializer.js +0 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/package.json +3 -3
- package/dist/esm/src/lib/consts.d.ts +4 -0
- package/dist/esm/src/lib/consts.js +7 -1
- package/dist/esm/src/lib/eventStorage/addToEventQueue.d.ts +1 -1
- package/dist/esm/src/lib/eventStorage/addToEventQueue.js +3 -3
- package/dist/esm/src/lib/eventStorage/eventStorage.d.ts +1 -1
- package/dist/esm/src/lib/eventStorage/eventStorage.js +4 -5
- package/dist/esm/src/lib/events/base-event.d.ts +2 -1
- package/dist/esm/src/lib/events/base-event.js +3 -2
- package/dist/esm/src/lib/events/common-interfaces.d.ts +1 -1
- package/dist/esm/src/lib/events/custom-event/custom-event.d.ts +11 -4
- package/dist/esm/src/lib/events/custom-event/custom-event.js +12 -5
- package/dist/esm/src/lib/events/custom-event/event.d.ts +2 -2
- package/dist/esm/src/lib/events/custom-event/event.js +2 -2
- package/dist/esm/src/lib/events/custom-event/eventServer.d.ts +3 -3
- package/dist/esm/src/lib/events/custom-event/eventServer.js +4 -4
- package/dist/esm/src/lib/events/custom-event/form.d.ts +1 -1
- package/dist/esm/src/lib/events/custom-event/form.js +5 -5
- package/dist/esm/src/lib/events/identity/identity-event.d.ts +4 -4
- package/dist/esm/src/lib/events/identity/identity-event.js +4 -5
- package/dist/esm/src/lib/events/identity/identity.d.ts +2 -2
- package/dist/esm/src/lib/events/identity/identity.js +2 -2
- package/dist/esm/src/lib/events/identity/identityServer.d.ts +3 -3
- package/dist/esm/src/lib/events/identity/identityServer.js +4 -4
- package/dist/esm/src/lib/events/page-view/page-view-event.d.ts +13 -6
- package/dist/esm/src/lib/events/page-view/page-view-event.js +24 -17
- package/dist/esm/src/lib/events/page-view/page-view-server.d.ts +4 -4
- package/dist/esm/src/lib/events/page-view/page-view-server.js +4 -4
- package/dist/esm/src/lib/events/page-view/page-view.d.ts +4 -4
- package/dist/esm/src/lib/events/page-view/page-view.js +3 -3
- package/dist/esm/src/lib/events/send-event/sendEvent.d.ts +2 -2
- package/dist/esm/src/lib/events/send-event/sendEvent.js +13 -8
- package/dist/esm/src/lib/getGuestId/getGuestId.js +1 -1
- package/dist/esm/src/lib/initializer/browser/initializer.d.ts +13 -1
- package/dist/esm/src/lib/initializer/browser/initializer.js +4 -4
- package/dist/esm/src/lib/initializer/server/initializer.d.ts +3 -3
- package/dist/esm/src/lib/initializer/server/initializer.js +1 -2
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import type { BasicTypes, NestedObject } from '@sitecore-cloudsdk/utils';
|
|
2
|
+
import type { EPResponse, Settings } from '@sitecore-cloudsdk/core';
|
|
3
|
+
import type { EventAttributesInput, ExtensionData } from '../common-interfaces';
|
|
1
4
|
import { BaseEvent } from '../base-event';
|
|
2
|
-
import {
|
|
3
|
-
import { SendEvent } from '../send-event/sendEvent';
|
|
4
|
-
import { EPResponse, Settings } from '@sitecore-cloudsdk/core';
|
|
5
|
-
import { BasicTypes, NestedObject } from '@sitecore-cloudsdk/utils';
|
|
5
|
+
import type { SendEvent } from '../send-event/sendEvent';
|
|
6
6
|
export declare class CustomEvent extends BaseEvent {
|
|
7
7
|
customEventPayload: CustomEventPayload;
|
|
8
8
|
private sendEvent;
|
|
@@ -32,6 +32,12 @@ export interface CustomEventArguments {
|
|
|
32
32
|
* Interface with the required/optional attributes in order to send a custom event to SitecoreCloud API
|
|
33
33
|
*/
|
|
34
34
|
export interface CustomEventPayload extends NestedObject {
|
|
35
|
+
sc_search?: {
|
|
36
|
+
data: NestedObject;
|
|
37
|
+
metadata: {
|
|
38
|
+
ut_api_version: string;
|
|
39
|
+
};
|
|
40
|
+
};
|
|
35
41
|
ext?: {
|
|
36
42
|
[key: string]: BasicTypes;
|
|
37
43
|
};
|
|
@@ -41,5 +47,6 @@ export interface CustomEventPayload extends NestedObject {
|
|
|
41
47
|
*/
|
|
42
48
|
export interface EventData extends EventAttributesInput, NestedObject {
|
|
43
49
|
type: string;
|
|
50
|
+
searchData?: NestedObject;
|
|
44
51
|
extensionData?: ExtensionData;
|
|
45
52
|
}
|
|
@@ -1,22 +1,21 @@
|
|
|
1
|
-
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
|
|
2
1
|
import { BaseEvent } from '../base-event';
|
|
3
|
-
import { flattenObject } from '@sitecore-cloudsdk/utils';
|
|
4
|
-
import { MAX_EXT_ATTRIBUTES } from '../consts';
|
|
5
2
|
import { ErrorMessages } from '../../consts';
|
|
3
|
+
import { MAX_EXT_ATTRIBUTES } from '../consts';
|
|
4
|
+
import { flattenObject } from '@sitecore-cloudsdk/utils';
|
|
6
5
|
export class CustomEvent extends BaseEvent {
|
|
7
6
|
/**
|
|
8
7
|
* A class that extends from {@link BaseEvent} and has all the required functionality to send a VIEW event
|
|
9
8
|
* @param args - Unified object containing the required properties
|
|
10
9
|
*/
|
|
11
10
|
constructor(args) {
|
|
12
|
-
const { channel, currency, language, page, type, extensionData, ...rest } = args.eventData;
|
|
11
|
+
const { channel, currency, language, page, type, extensionData, searchData, ...rest } = args.eventData;
|
|
13
12
|
super({ channel, currency, language, page }, args.id);
|
|
14
13
|
this.extensionData = {};
|
|
15
14
|
this.sendEvent = args.sendEvent;
|
|
16
15
|
this.settings = args.settings;
|
|
17
16
|
this.customEventPayload = {
|
|
18
17
|
type,
|
|
19
|
-
...rest
|
|
18
|
+
...rest
|
|
20
19
|
};
|
|
21
20
|
if (extensionData)
|
|
22
21
|
this.extensionData = flattenObject({ object: extensionData });
|
|
@@ -25,6 +24,14 @@ export class CustomEvent extends BaseEvent {
|
|
|
25
24
|
throw new Error(ErrorMessages.IV_0005);
|
|
26
25
|
if (numberOfExtensionDataProperties > 0)
|
|
27
26
|
this.customEventPayload.ext = this.extensionData;
|
|
27
|
+
if (searchData)
|
|
28
|
+
this.customEventPayload.sc_search = {
|
|
29
|
+
data: searchData,
|
|
30
|
+
metadata: {
|
|
31
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
32
|
+
ut_api_version: '1.0'
|
|
33
|
+
}
|
|
34
|
+
};
|
|
28
35
|
}
|
|
29
36
|
/**
|
|
30
37
|
* Sends the event to Sitecore EP
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { EPResponse } from '@sitecore-cloudsdk/core';
|
|
2
|
-
import { EventData } from './custom-event';
|
|
1
|
+
import type { EPResponse } from '@sitecore-cloudsdk/core';
|
|
2
|
+
import type { EventData } from './custom-event';
|
|
3
3
|
/**
|
|
4
4
|
* A function that sends an event to SitecoreCloud API with the specified type
|
|
5
5
|
*
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
|
|
2
2
|
import { getBrowserId, getSettings, handleGetSettingsError } from '@sitecore-cloudsdk/core';
|
|
3
3
|
import { CustomEvent } from './custom-event';
|
|
4
|
+
import { ErrorMessages } from '../../consts';
|
|
4
5
|
import { awaitInit } from '../../initializer/browser/initializer';
|
|
5
6
|
import { sendEvent } from '../send-event/sendEvent';
|
|
6
|
-
import { ErrorMessages } from '../../consts';
|
|
7
7
|
/**
|
|
8
8
|
* A function that sends an event to SitecoreCloud API with the specified type
|
|
9
9
|
*
|
|
@@ -18,6 +18,6 @@ export async function event(eventData) {
|
|
|
18
18
|
eventData,
|
|
19
19
|
id,
|
|
20
20
|
sendEvent,
|
|
21
|
-
settings
|
|
21
|
+
settings
|
|
22
22
|
}).send();
|
|
23
23
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { EPResponse } from '@sitecore-cloudsdk/core';
|
|
2
|
-
import { EventData } from './custom-event';
|
|
3
|
-
import { Request } from '@sitecore-cloudsdk/utils';
|
|
1
|
+
import type { EPResponse } from '@sitecore-cloudsdk/core';
|
|
2
|
+
import type { EventData } from './custom-event';
|
|
3
|
+
import type { Request } from '@sitecore-cloudsdk/utils';
|
|
4
4
|
/**
|
|
5
5
|
* A function that sends an event to SitecoreCloud API with the specified type
|
|
6
6
|
*
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
|
|
2
|
-
import {
|
|
2
|
+
import { getCookieValueFromRequest, getSettingsServer, handleGetSettingsError } from '@sitecore-cloudsdk/core';
|
|
3
3
|
import { CustomEvent } from './custom-event';
|
|
4
|
-
import { sendEvent } from '../send-event/sendEvent';
|
|
5
4
|
import { ErrorMessages } from '../../consts';
|
|
5
|
+
import { sendEvent } from '../send-event/sendEvent';
|
|
6
6
|
/**
|
|
7
7
|
* A function that sends an event to SitecoreCloud API with the specified type
|
|
8
8
|
*
|
|
@@ -12,11 +12,11 @@ import { ErrorMessages } from '../../consts';
|
|
|
12
12
|
*/
|
|
13
13
|
export function eventServer(request, eventData) {
|
|
14
14
|
const settings = handleGetSettingsError(getSettingsServer, ErrorMessages.IE_0005);
|
|
15
|
-
const id =
|
|
15
|
+
const id = getCookieValueFromRequest(request, settings.cookieSettings.cookieNames.browserId);
|
|
16
16
|
return new CustomEvent({
|
|
17
17
|
eventData,
|
|
18
18
|
id,
|
|
19
19
|
sendEvent,
|
|
20
|
-
settings
|
|
20
|
+
settings
|
|
21
21
|
}).send();
|
|
22
22
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
|
|
2
2
|
import { getBrowserId, getSettings, handleGetSettingsError } from '@sitecore-cloudsdk/core';
|
|
3
3
|
import { CustomEvent } from './custom-event';
|
|
4
|
-
import { sendEvent } from '../send-event/sendEvent';
|
|
5
|
-
import { awaitInit } from '../../initializer/browser/initializer';
|
|
6
4
|
import { ErrorMessages } from '../../consts';
|
|
5
|
+
import { awaitInit } from '../../initializer/browser/initializer';
|
|
6
|
+
import { sendEvent } from '../send-event/sendEvent';
|
|
7
7
|
/**
|
|
8
8
|
* A function that sends a form event to SitecoreCloud API
|
|
9
9
|
*
|
|
@@ -20,13 +20,13 @@ export async function form(formId, interactionType) {
|
|
|
20
20
|
eventData: {
|
|
21
21
|
extensionData: {
|
|
22
22
|
formId,
|
|
23
|
-
interactionType: interactionType.toUpperCase()
|
|
23
|
+
interactionType: interactionType.toUpperCase()
|
|
24
24
|
},
|
|
25
|
-
type: 'FORM'
|
|
25
|
+
type: 'FORM'
|
|
26
26
|
},
|
|
27
27
|
id,
|
|
28
28
|
sendEvent,
|
|
29
|
-
settings
|
|
29
|
+
settings
|
|
30
30
|
});
|
|
31
31
|
formEvent.page = undefined;
|
|
32
32
|
return formEvent.send();
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import type { EPResponse, Infer, Settings } from '@sitecore-cloudsdk/core';
|
|
2
|
+
import type { EventAttributesInput, ExtensionData } from '../common-interfaces';
|
|
1
3
|
import { BaseEvent } from '../base-event';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { EPResponse, Infer, Settings } from '@sitecore-cloudsdk/core';
|
|
5
|
-
import { SendEvent } from '../send-event/sendEvent';
|
|
4
|
+
import type { FlattenedObject } from '@sitecore-cloudsdk/utils';
|
|
5
|
+
import type { SendEvent } from '../send-event/sendEvent';
|
|
6
6
|
export declare class IdentityEvent extends BaseEvent {
|
|
7
7
|
private identityData;
|
|
8
8
|
private sendEvent;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import { flattenObject, isShortISODateString, isValidEmail } from '@sitecore-cloudsdk/utils';
|
|
2
2
|
import { BaseEvent } from '../base-event';
|
|
3
|
-
import { MAX_EXT_ATTRIBUTES } from '../consts';
|
|
4
|
-
import { isShortISODateString, isValidEmail, flattenObject } from '@sitecore-cloudsdk/utils';
|
|
5
3
|
import { ErrorMessages } from '../../consts';
|
|
4
|
+
import { MAX_EXT_ATTRIBUTES } from '../consts';
|
|
6
5
|
export class IdentityEvent extends BaseEvent {
|
|
7
6
|
/**
|
|
8
7
|
* A class that extends from {@link BaseEvent} and has all the required functionality to send a VIEW event
|
|
@@ -57,7 +56,7 @@ export class IdentityEvent extends BaseEvent {
|
|
|
57
56
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
58
57
|
expiry_date: value.expiryDate,
|
|
59
58
|
id: value.id,
|
|
60
|
-
provider: value.provider
|
|
59
|
+
provider: value.provider
|
|
61
60
|
};
|
|
62
61
|
}),
|
|
63
62
|
lastname: this.identityData.lastName,
|
|
@@ -68,7 +67,7 @@ export class IdentityEvent extends BaseEvent {
|
|
|
68
67
|
state: this.identityData.state,
|
|
69
68
|
street: this.identityData.street,
|
|
70
69
|
title: this.identityData.title,
|
|
71
|
-
type: 'IDENTITY'
|
|
70
|
+
type: 'IDENTITY'
|
|
72
71
|
};
|
|
73
72
|
if (this.numberOfExtensionDataProperties > 0)
|
|
74
73
|
identityPayload.ext = this.extensionData;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { EPResponse } from '@sitecore-cloudsdk/core';
|
|
2
|
-
import { IdentityData } from './identity-event';
|
|
1
|
+
import type { EPResponse } from '@sitecore-cloudsdk/core';
|
|
2
|
+
import type { IdentityData } from './identity-event';
|
|
3
3
|
/**
|
|
4
4
|
* A function that sends an IDENTITY event to SitecoreCloud API
|
|
5
5
|
*
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
|
|
2
2
|
import { getBrowserId, getSettings, handleGetSettingsError } from '@sitecore-cloudsdk/core';
|
|
3
|
+
import { ErrorMessages } from '../../consts';
|
|
3
4
|
import { IdentityEvent } from './identity-event';
|
|
4
5
|
import { awaitInit } from '../../initializer/browser/initializer';
|
|
5
6
|
import { sendEvent } from '../send-event/sendEvent';
|
|
6
|
-
import { ErrorMessages } from '../../consts';
|
|
7
7
|
/**
|
|
8
8
|
* A function that sends an IDENTITY event to SitecoreCloud API
|
|
9
9
|
*
|
|
@@ -18,6 +18,6 @@ export async function identity(identityData) {
|
|
|
18
18
|
id,
|
|
19
19
|
identityData,
|
|
20
20
|
sendEvent,
|
|
21
|
-
settings
|
|
21
|
+
settings
|
|
22
22
|
}).send();
|
|
23
23
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import type { EPResponse } from '@sitecore-cloudsdk/core';
|
|
2
|
+
import type { IdentityData } from './identity-event';
|
|
3
|
+
import type { Request } from '@sitecore-cloudsdk/utils';
|
|
4
4
|
/**
|
|
5
5
|
* A function that sends an IDENTITY event to SitecoreCloud API
|
|
6
6
|
*
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
|
|
2
|
-
import {
|
|
2
|
+
import { getCookieValueFromRequest, getSettingsServer, handleGetSettingsError } from '@sitecore-cloudsdk/core';
|
|
3
|
+
import { ErrorMessages } from '../../consts';
|
|
3
4
|
import { IdentityEvent } from './identity-event';
|
|
4
5
|
import { sendEvent } from '../send-event/sendEvent';
|
|
5
|
-
import { ErrorMessages } from '../../consts';
|
|
6
6
|
/**
|
|
7
7
|
* A function that sends an IDENTITY event to SitecoreCloud API
|
|
8
8
|
*
|
|
@@ -12,11 +12,11 @@ import { ErrorMessages } from '../../consts';
|
|
|
12
12
|
*/
|
|
13
13
|
export function identityServer(request, identityData) {
|
|
14
14
|
const settings = handleGetSettingsError(getSettingsServer, ErrorMessages.IE_0005);
|
|
15
|
-
const id =
|
|
15
|
+
const id = getCookieValueFromRequest(request, settings.cookieSettings.cookieNames.browserId);
|
|
16
16
|
return new IdentityEvent({
|
|
17
17
|
id,
|
|
18
18
|
identityData,
|
|
19
19
|
sendEvent,
|
|
20
|
-
settings: settings
|
|
20
|
+
settings: settings
|
|
21
21
|
}).send();
|
|
22
22
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { EPResponse, Infer, Settings } from '@sitecore-cloudsdk/core';
|
|
2
|
-
import {
|
|
1
|
+
import type { EPResponse, Infer, Settings } from '@sitecore-cloudsdk/core';
|
|
2
|
+
import type { EventAttributesInput, ExtensionData } from '../common-interfaces';
|
|
3
|
+
import type { FlattenedObject, NestedObject } from '@sitecore-cloudsdk/utils';
|
|
3
4
|
import { BaseEvent } from '../base-event';
|
|
4
|
-
import {
|
|
5
|
-
import { SendEvent } from '../send-event/sendEvent';
|
|
5
|
+
import type { SendEvent } from '../send-event/sendEvent';
|
|
6
6
|
export declare class PageViewEvent extends BaseEvent {
|
|
7
7
|
static isFirstPageView: boolean;
|
|
8
8
|
private sendEvent;
|
|
9
|
-
private pageViewData
|
|
9
|
+
private pageViewData?;
|
|
10
10
|
private extensionData;
|
|
11
11
|
private urlSearchParams;
|
|
12
12
|
private includeUTMParameters;
|
|
@@ -49,7 +49,7 @@ export declare class PageViewEvent extends BaseEvent {
|
|
|
49
49
|
*/
|
|
50
50
|
export interface PageViewEventArguments {
|
|
51
51
|
sendEvent: SendEvent;
|
|
52
|
-
pageViewData
|
|
52
|
+
pageViewData?: PageViewData;
|
|
53
53
|
id: string;
|
|
54
54
|
settings: Settings;
|
|
55
55
|
infer?: Infer;
|
|
@@ -64,6 +64,7 @@ export interface PageViewData extends EventAttributesInput {
|
|
|
64
64
|
referrer?: string;
|
|
65
65
|
includeUTMParameters?: boolean;
|
|
66
66
|
extensionData?: ExtensionData;
|
|
67
|
+
searchData?: NestedObject;
|
|
67
68
|
}
|
|
68
69
|
/**
|
|
69
70
|
* Interface with the utm_ parameters
|
|
@@ -80,5 +81,11 @@ export interface PageViewEventPayload extends UtmParameters {
|
|
|
80
81
|
ext?: {
|
|
81
82
|
pageVariantId?: string;
|
|
82
83
|
} & FlattenedObject;
|
|
84
|
+
sc_search?: {
|
|
85
|
+
data: NestedObject;
|
|
86
|
+
metadata: {
|
|
87
|
+
ut_api_version: string;
|
|
88
|
+
};
|
|
89
|
+
};
|
|
83
90
|
}
|
|
84
91
|
export {};
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { flattenObject } from '@sitecore-cloudsdk/utils';
|
|
2
|
-
import { BaseEvent } from '../base-event';
|
|
3
1
|
import { MAX_EXT_ATTRIBUTES, UTM_PREFIX } from '../consts';
|
|
2
|
+
import { BaseEvent } from '../base-event';
|
|
4
3
|
import { ErrorMessages } from '../../consts';
|
|
4
|
+
import { flattenObject } from '@sitecore-cloudsdk/utils';
|
|
5
5
|
export class PageViewEvent extends BaseEvent {
|
|
6
6
|
/**
|
|
7
7
|
* A class that extends from {@link BaseEvent} and has all the required functionality to send a VIEW event
|
|
8
8
|
* @param args - Unified object containing the required properties
|
|
9
9
|
*/
|
|
10
10
|
constructor(args) {
|
|
11
|
-
const { channel, currency, language, page, extensionData } = args.pageViewData;
|
|
11
|
+
const { channel, currency, language, page, extensionData } = { ...args.pageViewData };
|
|
12
12
|
super({
|
|
13
13
|
channel,
|
|
14
14
|
currency,
|
|
15
15
|
language,
|
|
16
|
-
page
|
|
16
|
+
page
|
|
17
17
|
}, args.id);
|
|
18
18
|
this.extensionData = {};
|
|
19
19
|
this.pageViewData = args.pageViewData;
|
|
@@ -25,8 +25,7 @@ export class PageViewEvent extends BaseEvent {
|
|
|
25
25
|
const numberOfExtensionDataProperties = Object.entries(this.extensionData).length;
|
|
26
26
|
if (numberOfExtensionDataProperties > MAX_EXT_ATTRIBUTES)
|
|
27
27
|
throw new Error(ErrorMessages.IV_0005);
|
|
28
|
-
this.includeUTMParameters =
|
|
29
|
-
args.pageViewData.includeUTMParameters === undefined ? true : args.pageViewData.includeUTMParameters;
|
|
28
|
+
this.includeUTMParameters = (args.pageViewData && args.pageViewData.includeUTMParameters) ?? true;
|
|
30
29
|
}
|
|
31
30
|
/**
|
|
32
31
|
* Gets the variant ID from the url if not passed by the developer
|
|
@@ -49,7 +48,7 @@ export class PageViewEvent extends BaseEvent {
|
|
|
49
48
|
* @returns - the referrer
|
|
50
49
|
*/
|
|
51
50
|
getReferrer() {
|
|
52
|
-
if (this.pageViewData
|
|
51
|
+
if (this.pageViewData?.referrer)
|
|
53
52
|
return this.pageViewData.referrer;
|
|
54
53
|
if (typeof window === 'undefined')
|
|
55
54
|
return null;
|
|
@@ -63,24 +62,33 @@ export class PageViewEvent extends BaseEvent {
|
|
|
63
62
|
* @returns the mapped object to be sent as payload
|
|
64
63
|
*/
|
|
65
64
|
mapAttributes() {
|
|
66
|
-
let
|
|
67
|
-
type: 'VIEW'
|
|
65
|
+
let pageViewPayload = {
|
|
66
|
+
type: 'VIEW'
|
|
68
67
|
};
|
|
69
|
-
const pageVariantId = this.
|
|
68
|
+
const pageVariantId = this.pageViewData &&
|
|
69
|
+
this.getPageVariantId(this.pageViewData.pageVariantId, this.extensionData['pageVariantId']);
|
|
70
70
|
if (pageVariantId !== null)
|
|
71
|
-
|
|
71
|
+
pageViewPayload.ext = { ...pageViewPayload.ext, pageVariantId };
|
|
72
72
|
if (Object.keys(this.extensionData).length > 0) {
|
|
73
73
|
delete this.extensionData['pageVariantId'];
|
|
74
|
-
|
|
74
|
+
pageViewPayload.ext = { ...pageViewPayload.ext, ...this.extensionData };
|
|
75
75
|
}
|
|
76
76
|
if (this.includeUTMParameters) {
|
|
77
77
|
const utmParameters = this.getUTMParameters();
|
|
78
|
-
|
|
78
|
+
pageViewPayload = { ...pageViewPayload, ...utmParameters };
|
|
79
79
|
}
|
|
80
80
|
const referrer = this.getReferrer();
|
|
81
81
|
if (referrer !== null)
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
pageViewPayload = { ...pageViewPayload, referrer };
|
|
83
|
+
if (this.pageViewData?.searchData)
|
|
84
|
+
pageViewPayload.sc_search = {
|
|
85
|
+
data: this.pageViewData.searchData,
|
|
86
|
+
metadata: {
|
|
87
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
88
|
+
ut_api_version: '1.0'
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
return pageViewPayload;
|
|
84
92
|
}
|
|
85
93
|
/**
|
|
86
94
|
* Sends the event to Sitecore EP
|
|
@@ -89,9 +97,8 @@ export class PageViewEvent extends BaseEvent {
|
|
|
89
97
|
async send() {
|
|
90
98
|
const baseAttr = this.mapBaseEventPayload();
|
|
91
99
|
const eventAttrs = this.mapAttributes();
|
|
92
|
-
const fetchBody = Object.assign({}, eventAttrs, baseAttr);
|
|
93
100
|
PageViewEvent.isFirstPageView = false;
|
|
94
|
-
return await this.sendEvent(
|
|
101
|
+
return await this.sendEvent({ ...baseAttr, ...eventAttrs }, this.settings);
|
|
95
102
|
}
|
|
96
103
|
/**
|
|
97
104
|
* Retrieves UTM parameters from the url query string
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { EPResponse } from '@sitecore-cloudsdk/core';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import type { EPResponse } from '@sitecore-cloudsdk/core';
|
|
2
|
+
import type { PageViewData } from './page-view-event';
|
|
3
|
+
import type { Request } from '@sitecore-cloudsdk/utils';
|
|
4
4
|
/**
|
|
5
5
|
* A function that sends a VIEW event to SitecoreCloud API
|
|
6
6
|
*
|
|
@@ -8,4 +8,4 @@ import { PageViewData } from './page-view-event';
|
|
|
8
8
|
* @param pageViewData - The required/optional attributes in order to be send to SitecoreCloud API
|
|
9
9
|
* @returns The response object that Sitecore EP returns
|
|
10
10
|
*/
|
|
11
|
-
export declare function pageViewServer<T extends Request>(request: T, pageViewData
|
|
11
|
+
export declare function pageViewServer<T extends Request>(request: T, pageViewData?: PageViewData): Promise<EPResponse | null>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
|
|
2
|
-
import {
|
|
2
|
+
import { getCookieValueFromRequest, getSettingsServer, handleGetSettingsError } from '@sitecore-cloudsdk/core';
|
|
3
|
+
import { ErrorMessages } from '../../consts';
|
|
3
4
|
import { PageViewEvent } from './page-view-event';
|
|
4
5
|
import { sendEvent } from '../send-event/sendEvent';
|
|
5
|
-
import { ErrorMessages } from '../../consts';
|
|
6
6
|
/**
|
|
7
7
|
* A function that sends a VIEW event to SitecoreCloud API
|
|
8
8
|
*
|
|
@@ -12,7 +12,7 @@ import { ErrorMessages } from '../../consts';
|
|
|
12
12
|
*/
|
|
13
13
|
export function pageViewServer(request, pageViewData) {
|
|
14
14
|
const settings = handleGetSettingsError(getSettingsServer, ErrorMessages.IE_0005);
|
|
15
|
-
const id =
|
|
15
|
+
const id = getCookieValueFromRequest(request, settings.cookieSettings.cookieNames.browserId);
|
|
16
16
|
// Host is irrelevant but necessary to support relative URL
|
|
17
17
|
const requestUrl = new URL(request.url, `https://localhost`);
|
|
18
18
|
return new PageViewEvent({
|
|
@@ -20,6 +20,6 @@ export function pageViewServer(request, pageViewData) {
|
|
|
20
20
|
pageViewData,
|
|
21
21
|
searchParams: requestUrl.search,
|
|
22
22
|
sendEvent,
|
|
23
|
-
settings
|
|
23
|
+
settings
|
|
24
24
|
}).send();
|
|
25
25
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { EPResponse } from '@sitecore-cloudsdk/core';
|
|
2
|
-
import { PageViewData } from './page-view-event';
|
|
1
|
+
import type { EPResponse } from '@sitecore-cloudsdk/core';
|
|
2
|
+
import type { PageViewData } from './page-view-event';
|
|
3
3
|
/**
|
|
4
4
|
* A function that sends a VIEW event to SitecoreCloud API
|
|
5
5
|
*
|
|
6
|
-
* @param pageViewData - The
|
|
6
|
+
* @param pageViewData - The optional attributes in order to be send to SitecoreCloud API
|
|
7
7
|
* This object will be flattened and sent in the ext object of the payload
|
|
8
8
|
* @returns The response object that Sitecore EP returns
|
|
9
9
|
*/
|
|
10
|
-
export declare function pageView(pageViewData
|
|
10
|
+
export declare function pageView(pageViewData?: PageViewData): Promise<EPResponse | null>;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
|
|
2
2
|
import { getBrowserId, getSettings, handleGetSettingsError } from '@sitecore-cloudsdk/core';
|
|
3
|
+
import { ErrorMessages } from '../../consts';
|
|
3
4
|
import { PageViewEvent } from './page-view-event';
|
|
4
5
|
import { awaitInit } from '../../initializer/browser/initializer';
|
|
5
6
|
import { sendEvent } from '../send-event/sendEvent';
|
|
6
|
-
import { ErrorMessages } from '../../consts';
|
|
7
7
|
/**
|
|
8
8
|
* A function that sends a VIEW event to SitecoreCloud API
|
|
9
9
|
*
|
|
10
|
-
* @param pageViewData - The
|
|
10
|
+
* @param pageViewData - The optional attributes in order to be send to SitecoreCloud API
|
|
11
11
|
* This object will be flattened and sent in the ext object of the payload
|
|
12
12
|
* @returns The response object that Sitecore EP returns
|
|
13
13
|
*/
|
|
@@ -20,6 +20,6 @@ export async function pageView(pageViewData) {
|
|
|
20
20
|
pageViewData,
|
|
21
21
|
searchParams: window.location.search,
|
|
22
22
|
sendEvent,
|
|
23
|
-
settings
|
|
23
|
+
settings
|
|
24
24
|
}).send();
|
|
25
25
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type {
|
|
1
|
+
import type { BasePayload, CustomEventPayload, IdentityEventPayload, PageViewEventPayload } from '..';
|
|
2
|
+
import type { EPResponse, Settings } from '@sitecore-cloudsdk/core';
|
|
3
3
|
/**
|
|
4
4
|
* This factory function sends an event to Edge Proxy
|
|
5
5
|
* @param body - The event data to send
|
|
@@ -1,31 +1,36 @@
|
|
|
1
1
|
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
|
|
2
|
-
import { API_VERSION, debug } from '@sitecore-cloudsdk/core';
|
|
3
|
-
import { LIBRARY_VERSION,
|
|
2
|
+
import { API_VERSION, debug, processDebugResponse } from '@sitecore-cloudsdk/core';
|
|
3
|
+
import { EVENTS_NAMESPACE, LIBRARY_VERSION, X_CLIENT_SOFTWARE_ID } from '../../consts';
|
|
4
4
|
/**
|
|
5
5
|
* This factory function sends an event to Edge Proxy
|
|
6
6
|
* @param body - The event data to send
|
|
7
7
|
* @param settings - The global settings
|
|
8
8
|
*/
|
|
9
9
|
export async function sendEvent(body, settings) {
|
|
10
|
+
// eslint-disable-next-line max-len
|
|
10
11
|
const eventUrl = `${settings.sitecoreEdgeUrl}/v1/events/${API_VERSION}/events?sitecoreContextId=${settings.sitecoreEdgeContextId}&siteId=${settings.siteName}`;
|
|
12
|
+
const startTimestamp = Date.now();
|
|
13
|
+
let debugResponse = {};
|
|
11
14
|
const fetchOptions = {
|
|
12
15
|
body: JSON.stringify(body),
|
|
13
16
|
headers: {
|
|
14
|
-
|
|
17
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
15
18
|
'Content-Type': 'application/json',
|
|
16
|
-
|
|
17
|
-
'X-Library-Version': LIBRARY_VERSION
|
|
19
|
+
'X-Client-Software-ID': X_CLIENT_SOFTWARE_ID,
|
|
20
|
+
'X-Library-Version': LIBRARY_VERSION
|
|
21
|
+
/* eslint-enable @typescript-eslint/naming-convention */
|
|
18
22
|
},
|
|
19
|
-
method: 'POST'
|
|
23
|
+
method: 'POST'
|
|
20
24
|
};
|
|
21
25
|
debug(EVENTS_NAMESPACE)('Events request: %s with options: %O', eventUrl, fetchOptions);
|
|
22
26
|
return await fetch(eventUrl, fetchOptions)
|
|
23
27
|
.then((response) => {
|
|
24
|
-
|
|
28
|
+
debugResponse = processDebugResponse(EVENTS_NAMESPACE, response);
|
|
25
29
|
return response.json();
|
|
26
30
|
})
|
|
27
31
|
.then((data) => {
|
|
28
|
-
|
|
32
|
+
debugResponse.body = data;
|
|
33
|
+
debug(EVENTS_NAMESPACE)('Events response in %dms : %O', Date.now() - startTimestamp, debugResponse);
|
|
29
34
|
return data;
|
|
30
35
|
})
|
|
31
36
|
.catch((error) => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
|
|
2
|
+
import { getBrowserId, getGuestId as getGuestIdFromCore, getSettings, handleGetSettingsError } from '@sitecore-cloudsdk/core';
|
|
2
3
|
import { ErrorMessages } from '../consts';
|
|
3
4
|
import { awaitInit } from '../initializer/browser/initializer';
|
|
4
|
-
import { getBrowserId, getGuestId as getGuestIdFromCore, getSettings, handleGetSettingsError, } from '@sitecore-cloudsdk/core';
|
|
5
5
|
/**
|
|
6
6
|
* A function that returns the guest id.
|
|
7
7
|
* @returns - A promise that resolves with the guest id
|
|
@@ -1,5 +1,17 @@
|
|
|
1
|
-
import { BrowserSettings } from '@sitecore-cloudsdk/core';
|
|
1
|
+
import type { BrowserSettings } from '@sitecore-cloudsdk/core';
|
|
2
2
|
export declare let initPromise: Promise<void> | null;
|
|
3
|
+
declare global {
|
|
4
|
+
interface Window {
|
|
5
|
+
Engage: {
|
|
6
|
+
[x: string]: any;
|
|
7
|
+
getBrowserId?: () => string;
|
|
8
|
+
versions?: {
|
|
9
|
+
personalize?: string;
|
|
10
|
+
events?: string;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
}
|
|
3
15
|
/**
|
|
4
16
|
* Initiates the Events library using the global settings added by the developer
|
|
5
17
|
* @param settings - Global settings added by the developer
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { EVENTS_NAMESPACE, ErrorMessages, LIBRARY_VERSION } from '../../consts';
|
|
3
|
+
import { debug, getBrowserId, initCore } from '@sitecore-cloudsdk/core';
|
|
4
4
|
export let initPromise = null;
|
|
5
5
|
/**
|
|
6
6
|
* Initiates the Events library using the global settings added by the developer
|
|
@@ -25,8 +25,8 @@ export async function init(settings) {
|
|
|
25
25
|
getBrowserId: () => getBrowserId(),
|
|
26
26
|
versions: {
|
|
27
27
|
...window.Engage?.versions,
|
|
28
|
-
events: LIBRARY_VERSION
|
|
29
|
-
}
|
|
28
|
+
events: LIBRARY_VERSION
|
|
29
|
+
}
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
32
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import type { Request, Response } from '@sitecore-cloudsdk/utils';
|
|
2
|
+
import type { ServerSettings } from '@sitecore-cloudsdk/core';
|
|
3
3
|
/**
|
|
4
4
|
* Initiates the server Events library using the global settings added by the developer
|
|
5
5
|
* @param request - The request object, either a Middleware Request or an HTTP Request
|
|
@@ -7,4 +7,4 @@ import { HttpResponse, MiddlewareNextResponse, Request } from '@sitecore-cloudsd
|
|
|
7
7
|
* @param settings - Global settings added by the developer
|
|
8
8
|
* @returns A promise that resolves with an object that handles the library functionality
|
|
9
9
|
*/
|
|
10
|
-
export declare function initServer
|
|
10
|
+
export declare function initServer(request: Request, response: Response, settings: ServerSettings): Promise<void>;
|