@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
package/dist/cjs/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sitecore-cloudsdk/events",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1-rc.1",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"homepage": "https://doc.sitecore.com/xmc/en/developers/sdk/latest/cloud-sdk/index.html",
|
|
6
6
|
"exports": {
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
}
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@sitecore-cloudsdk/core": "^0.3.
|
|
20
|
-
"@sitecore-cloudsdk/utils": "^0.3.
|
|
19
|
+
"@sitecore-cloudsdk/core": "^0.3.1-rc.1",
|
|
20
|
+
"@sitecore-cloudsdk/utils": "^0.3.1-rc.1"
|
|
21
21
|
},
|
|
22
22
|
"scripts": {
|
|
23
23
|
"build": "npm run build:cjs && npm run build:es",
|
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
* Returns the version of the library.
|
|
3
3
|
*/
|
|
4
4
|
export declare const LIBRARY_VERSION: string;
|
|
5
|
+
/**
|
|
6
|
+
* Returns the name & version of the library in a String.
|
|
7
|
+
*/
|
|
8
|
+
export declare const X_CLIENT_SOFTWARE_ID: string;
|
|
5
9
|
export declare enum ErrorMessages {
|
|
6
10
|
IE_0001 = "[IE-0001] The \"window\" object is not available on the server side. Use the \"window\" object only on the client side, and in the correct execution context.",
|
|
7
11
|
IE_0004 = "[IE-0004] You must first initialize the \"events/browser\" module. Run the \"init\" function.",
|
|
@@ -3,15 +3,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.EVENTS_NAMESPACE = exports.ErrorMessages = exports.LIBRARY_VERSION = void 0;
|
|
6
|
+
exports.EVENTS_NAMESPACE = exports.ErrorMessages = exports.X_CLIENT_SOFTWARE_ID = exports.LIBRARY_VERSION = void 0;
|
|
7
7
|
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
|
|
8
8
|
/* eslint-disable @typescript-eslint/naming-convention */
|
|
9
|
-
const package_json_1 = __importDefault(require("../../package.json"));
|
|
10
9
|
const consts_1 = require("./events/consts");
|
|
10
|
+
const package_json_1 = __importDefault(require("../../package.json"));
|
|
11
11
|
/**
|
|
12
12
|
* Returns the version of the library.
|
|
13
13
|
*/
|
|
14
14
|
exports.LIBRARY_VERSION = package_json_1.default.version;
|
|
15
|
+
/**
|
|
16
|
+
* Returns the name & version of the library in a String.
|
|
17
|
+
*/
|
|
18
|
+
exports.X_CLIENT_SOFTWARE_ID = `${package_json_1.default.name} ${exports.LIBRARY_VERSION}`;
|
|
19
|
+
/* eslint-disable max-len */
|
|
15
20
|
var ErrorMessages;
|
|
16
21
|
(function (ErrorMessages) {
|
|
17
22
|
ErrorMessages["IE_0001"] = "[IE-0001] The \"window\" object is not available on the server side. Use the \"window\" object only on the client side, and in the correct execution context.";
|
|
@@ -23,4 +28,5 @@ var ErrorMessages;
|
|
|
23
28
|
ErrorMessages["IV_0005"] = "[IV-0005] \"extensionData\" supports maximum 50 attributes. Reduce the number of attributes.";
|
|
24
29
|
ErrorMessages["MV_0003"] = "[MV-0003] \"identifiers\" is required.";
|
|
25
30
|
})(ErrorMessages || (exports.ErrorMessages = ErrorMessages = {}));
|
|
31
|
+
/* eslint-enable max-len */
|
|
26
32
|
exports.EVENTS_NAMESPACE = 'sitecore-cloudsdk:events';
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.addToEventQueue = void 0;
|
|
4
4
|
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
|
|
5
|
-
const initializer_1 = require("../initializer/browser/initializer");
|
|
6
|
-
const eventStorage_1 = require("./eventStorage");
|
|
7
5
|
const core_1 = require("@sitecore-cloudsdk/core");
|
|
8
6
|
const consts_1 = require("../consts");
|
|
7
|
+
const initializer_1 = require("../initializer/browser/initializer");
|
|
8
|
+
const eventStorage_1 = require("./eventStorage");
|
|
9
9
|
/**
|
|
10
10
|
* A function that adds event to the queue
|
|
11
11
|
*
|
|
@@ -18,7 +18,7 @@ async function addToEventQueue(eventData) {
|
|
|
18
18
|
const queueEventPayload = {
|
|
19
19
|
eventData,
|
|
20
20
|
id,
|
|
21
|
-
settings
|
|
21
|
+
settings
|
|
22
22
|
};
|
|
23
23
|
eventStorage_1.eventQueue.enqueueEvent(queueEventPayload);
|
|
24
24
|
}
|
|
@@ -35,7 +35,7 @@ class EventQueue {
|
|
|
35
35
|
queueEventPayload.eventData.language = queueEventPayload.eventData.language ?? (0, core_1.language)();
|
|
36
36
|
new events_1.CustomEvent({
|
|
37
37
|
sendEvent: sendEvent_1.sendEvent,
|
|
38
|
-
...queueEventPayload
|
|
38
|
+
...queueEventPayload
|
|
39
39
|
});
|
|
40
40
|
const eventQueue = this.getEventQueue();
|
|
41
41
|
eventQueue.push(queueEventPayload);
|
|
@@ -46,14 +46,13 @@ class EventQueue {
|
|
|
46
46
|
*/
|
|
47
47
|
async sendAllEvents() {
|
|
48
48
|
const eventQueue = this.getEventQueue();
|
|
49
|
-
for (const queueEventPayload of eventQueue)
|
|
49
|
+
for (const queueEventPayload of eventQueue)
|
|
50
50
|
await new events_1.CustomEvent({
|
|
51
51
|
eventData: queueEventPayload.eventData,
|
|
52
52
|
id: queueEventPayload.id,
|
|
53
53
|
sendEvent: sendEvent_1.sendEvent,
|
|
54
|
-
settings: queueEventPayload.settings
|
|
54
|
+
settings: queueEventPayload.settings
|
|
55
55
|
}).send();
|
|
56
|
-
}
|
|
57
56
|
this.clearQueue();
|
|
58
57
|
}
|
|
59
58
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EventAttributesInput } from './common-interfaces';
|
|
1
|
+
import type { EventAttributesInput } from './common-interfaces';
|
|
2
2
|
export declare class BaseEvent {
|
|
3
3
|
private baseEventData;
|
|
4
4
|
private readonly browserId;
|
|
@@ -29,6 +29,7 @@ export interface BasePayload {
|
|
|
29
29
|
language?: string;
|
|
30
30
|
page?: string;
|
|
31
31
|
pos: string;
|
|
32
|
+
requested_at: string;
|
|
32
33
|
}
|
|
33
34
|
type BaseEventData = EventAttributesInput;
|
|
34
35
|
export {};
|
|
@@ -23,15 +23,16 @@ class BaseEvent {
|
|
|
23
23
|
*/
|
|
24
24
|
mapBaseEventPayload() {
|
|
25
25
|
return {
|
|
26
|
-
|
|
26
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
27
27
|
browser_id: this.browserId,
|
|
28
28
|
channel: this.baseEventData.channel,
|
|
29
|
-
/* eslint-disable @typescript-eslint/naming-convention */
|
|
30
29
|
client_key: '',
|
|
31
30
|
currency: this.baseEventData.currency,
|
|
32
31
|
language: this.language,
|
|
33
32
|
page: this.page,
|
|
34
33
|
pos: '',
|
|
34
|
+
requested_at: new Date().toISOString()
|
|
35
|
+
/* eslint-enable @typescript-eslint/naming-convention */
|
|
35
36
|
};
|
|
36
37
|
}
|
|
37
38
|
}
|
|
@@ -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,33 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CustomEvent = void 0;
|
|
4
|
-
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
|
|
5
4
|
const base_event_1 = require("../base-event");
|
|
5
|
+
const consts_1 = require("../../consts");
|
|
6
|
+
const consts_2 = require("../consts");
|
|
6
7
|
const utils_1 = require("@sitecore-cloudsdk/utils");
|
|
7
|
-
const consts_1 = require("../consts");
|
|
8
|
-
const consts_2 = require("../../consts");
|
|
9
8
|
class CustomEvent extends base_event_1.BaseEvent {
|
|
10
9
|
/**
|
|
11
10
|
* A class that extends from {@link BaseEvent} and has all the required functionality to send a VIEW event
|
|
12
11
|
* @param args - Unified object containing the required properties
|
|
13
12
|
*/
|
|
14
13
|
constructor(args) {
|
|
15
|
-
const { channel, currency, language, page, type, extensionData, ...rest } = args.eventData;
|
|
14
|
+
const { channel, currency, language, page, type, extensionData, searchData, ...rest } = args.eventData;
|
|
16
15
|
super({ channel, currency, language, page }, args.id);
|
|
17
16
|
this.extensionData = {};
|
|
18
17
|
this.sendEvent = args.sendEvent;
|
|
19
18
|
this.settings = args.settings;
|
|
20
19
|
this.customEventPayload = {
|
|
21
20
|
type,
|
|
22
|
-
...rest
|
|
21
|
+
...rest
|
|
23
22
|
};
|
|
24
23
|
if (extensionData)
|
|
25
24
|
this.extensionData = (0, utils_1.flattenObject)({ object: extensionData });
|
|
26
25
|
const numberOfExtensionDataProperties = Object.entries(this.extensionData).length;
|
|
27
|
-
if (numberOfExtensionDataProperties >
|
|
28
|
-
throw new Error(
|
|
26
|
+
if (numberOfExtensionDataProperties > consts_2.MAX_EXT_ATTRIBUTES)
|
|
27
|
+
throw new Error(consts_1.ErrorMessages.IV_0005);
|
|
29
28
|
if (numberOfExtensionDataProperties > 0)
|
|
30
29
|
this.customEventPayload.ext = this.extensionData;
|
|
30
|
+
if (searchData)
|
|
31
|
+
this.customEventPayload.sc_search = {
|
|
32
|
+
data: searchData,
|
|
33
|
+
metadata: {
|
|
34
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
35
|
+
ut_api_version: '1.0'
|
|
36
|
+
}
|
|
37
|
+
};
|
|
31
38
|
}
|
|
32
39
|
/**
|
|
33
40
|
* 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
|
*
|
|
@@ -4,9 +4,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
exports.event = void 0;
|
|
5
5
|
const core_1 = require("@sitecore-cloudsdk/core");
|
|
6
6
|
const custom_event_1 = require("./custom-event");
|
|
7
|
+
const consts_1 = require("../../consts");
|
|
7
8
|
const initializer_1 = require("../../initializer/browser/initializer");
|
|
8
9
|
const sendEvent_1 = require("../send-event/sendEvent");
|
|
9
|
-
const consts_1 = require("../../consts");
|
|
10
10
|
/**
|
|
11
11
|
* A function that sends an event to SitecoreCloud API with the specified type
|
|
12
12
|
*
|
|
@@ -21,7 +21,7 @@ async function event(eventData) {
|
|
|
21
21
|
eventData,
|
|
22
22
|
id,
|
|
23
23
|
sendEvent: sendEvent_1.sendEvent,
|
|
24
|
-
settings
|
|
24
|
+
settings
|
|
25
25
|
}).send();
|
|
26
26
|
}
|
|
27
27
|
exports.event = event;
|
|
@@ -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
|
*
|
|
@@ -4,8 +4,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
exports.eventServer = void 0;
|
|
5
5
|
const core_1 = require("@sitecore-cloudsdk/core");
|
|
6
6
|
const custom_event_1 = require("./custom-event");
|
|
7
|
-
const sendEvent_1 = require("../send-event/sendEvent");
|
|
8
7
|
const consts_1 = require("../../consts");
|
|
8
|
+
const sendEvent_1 = require("../send-event/sendEvent");
|
|
9
9
|
/**
|
|
10
10
|
* A function that sends an event to SitecoreCloud API with the specified type
|
|
11
11
|
*
|
|
@@ -15,12 +15,12 @@ const consts_1 = require("../../consts");
|
|
|
15
15
|
*/
|
|
16
16
|
function eventServer(request, eventData) {
|
|
17
17
|
const settings = (0, core_1.handleGetSettingsError)(core_1.getSettingsServer, consts_1.ErrorMessages.IE_0005);
|
|
18
|
-
const id = (0, core_1.
|
|
18
|
+
const id = (0, core_1.getCookieValueFromRequest)(request, settings.cookieSettings.cookieNames.browserId);
|
|
19
19
|
return new custom_event_1.CustomEvent({
|
|
20
20
|
eventData,
|
|
21
21
|
id,
|
|
22
22
|
sendEvent: sendEvent_1.sendEvent,
|
|
23
|
-
settings
|
|
23
|
+
settings
|
|
24
24
|
}).send();
|
|
25
25
|
}
|
|
26
26
|
exports.eventServer = eventServer;
|
|
@@ -4,9 +4,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
exports.form = void 0;
|
|
5
5
|
const core_1 = require("@sitecore-cloudsdk/core");
|
|
6
6
|
const custom_event_1 = require("./custom-event");
|
|
7
|
-
const sendEvent_1 = require("../send-event/sendEvent");
|
|
8
|
-
const initializer_1 = require("../../initializer/browser/initializer");
|
|
9
7
|
const consts_1 = require("../../consts");
|
|
8
|
+
const initializer_1 = require("../../initializer/browser/initializer");
|
|
9
|
+
const sendEvent_1 = require("../send-event/sendEvent");
|
|
10
10
|
/**
|
|
11
11
|
* A function that sends a form event to SitecoreCloud API
|
|
12
12
|
*
|
|
@@ -23,13 +23,13 @@ async function form(formId, interactionType) {
|
|
|
23
23
|
eventData: {
|
|
24
24
|
extensionData: {
|
|
25
25
|
formId,
|
|
26
|
-
interactionType: interactionType.toUpperCase()
|
|
26
|
+
interactionType: interactionType.toUpperCase()
|
|
27
27
|
},
|
|
28
|
-
type: 'FORM'
|
|
28
|
+
type: 'FORM'
|
|
29
29
|
},
|
|
30
30
|
id,
|
|
31
31
|
sendEvent: sendEvent_1.sendEvent,
|
|
32
|
-
settings
|
|
32
|
+
settings
|
|
33
33
|
});
|
|
34
34
|
formEvent.page = undefined;
|
|
35
35
|
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,11 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.IdentityEvent = void 0;
|
|
4
|
-
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
|
|
5
|
-
const base_event_1 = require("../base-event");
|
|
6
|
-
const consts_1 = require("../consts");
|
|
7
4
|
const utils_1 = require("@sitecore-cloudsdk/utils");
|
|
8
|
-
const
|
|
5
|
+
const base_event_1 = require("../base-event");
|
|
6
|
+
const consts_1 = require("../../consts");
|
|
7
|
+
const consts_2 = require("../consts");
|
|
9
8
|
class IdentityEvent extends base_event_1.BaseEvent {
|
|
10
9
|
/**
|
|
11
10
|
* A class that extends from {@link BaseEvent} and has all the required functionality to send a VIEW event
|
|
@@ -24,8 +23,8 @@ class IdentityEvent extends base_event_1.BaseEvent {
|
|
|
24
23
|
if (extensionData)
|
|
25
24
|
this.extensionData = (0, utils_1.flattenObject)({ object: extensionData });
|
|
26
25
|
this.numberOfExtensionDataProperties = Object.entries(this.extensionData).length;
|
|
27
|
-
if (this.numberOfExtensionDataProperties >
|
|
28
|
-
throw new Error(
|
|
26
|
+
if (this.numberOfExtensionDataProperties > consts_2.MAX_EXT_ATTRIBUTES)
|
|
27
|
+
throw new Error(consts_1.ErrorMessages.IV_0005);
|
|
29
28
|
}
|
|
30
29
|
/**
|
|
31
30
|
* Function that validates the identifiers object, email and date attributes for CDN users
|
|
@@ -33,15 +32,15 @@ class IdentityEvent extends base_event_1.BaseEvent {
|
|
|
33
32
|
*/
|
|
34
33
|
validateAttributes(identityData) {
|
|
35
34
|
if (identityData.identifiers.length === 0)
|
|
36
|
-
throw new Error(
|
|
35
|
+
throw new Error(consts_1.ErrorMessages.MV_0003);
|
|
37
36
|
if (identityData.dob !== undefined && !(0, utils_1.isShortISODateString)(identityData.dob))
|
|
38
|
-
throw new Error(
|
|
37
|
+
throw new Error(consts_1.ErrorMessages.IV_0002);
|
|
39
38
|
identityData.identifiers.forEach((identifier) => {
|
|
40
39
|
if (identifier.expiryDate && !(0, utils_1.isShortISODateString)(identifier.expiryDate))
|
|
41
|
-
throw new Error(
|
|
40
|
+
throw new Error(consts_1.ErrorMessages.IV_0004);
|
|
42
41
|
});
|
|
43
42
|
if (identityData.email && !(0, utils_1.isValidEmail)(identityData.email))
|
|
44
|
-
throw new Error(
|
|
43
|
+
throw new Error(consts_1.ErrorMessages.IV_0003);
|
|
45
44
|
}
|
|
46
45
|
/**
|
|
47
46
|
* A function that maps the identity event input data with the payload sent to the API
|
|
@@ -60,7 +59,7 @@ class IdentityEvent extends base_event_1.BaseEvent {
|
|
|
60
59
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
61
60
|
expiry_date: value.expiryDate,
|
|
62
61
|
id: value.id,
|
|
63
|
-
provider: value.provider
|
|
62
|
+
provider: value.provider
|
|
64
63
|
};
|
|
65
64
|
}),
|
|
66
65
|
lastname: this.identityData.lastName,
|
|
@@ -71,7 +70,7 @@ class IdentityEvent extends base_event_1.BaseEvent {
|
|
|
71
70
|
state: this.identityData.state,
|
|
72
71
|
street: this.identityData.street,
|
|
73
72
|
title: this.identityData.title,
|
|
74
|
-
type: 'IDENTITY'
|
|
73
|
+
type: 'IDENTITY'
|
|
75
74
|
};
|
|
76
75
|
if (this.numberOfExtensionDataProperties > 0)
|
|
77
76
|
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
|
*
|
|
@@ -3,10 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.identity = void 0;
|
|
4
4
|
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
|
|
5
5
|
const core_1 = require("@sitecore-cloudsdk/core");
|
|
6
|
+
const consts_1 = require("../../consts");
|
|
6
7
|
const identity_event_1 = require("./identity-event");
|
|
7
8
|
const initializer_1 = require("../../initializer/browser/initializer");
|
|
8
9
|
const sendEvent_1 = require("../send-event/sendEvent");
|
|
9
|
-
const consts_1 = require("../../consts");
|
|
10
10
|
/**
|
|
11
11
|
* A function that sends an IDENTITY event to SitecoreCloud API
|
|
12
12
|
*
|
|
@@ -21,7 +21,7 @@ async function identity(identityData) {
|
|
|
21
21
|
id,
|
|
22
22
|
identityData,
|
|
23
23
|
sendEvent: sendEvent_1.sendEvent,
|
|
24
|
-
settings
|
|
24
|
+
settings
|
|
25
25
|
}).send();
|
|
26
26
|
}
|
|
27
27
|
exports.identity = identity;
|
|
@@ -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
|
*
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.identityServer = void 0;
|
|
5
5
|
const core_1 = require("@sitecore-cloudsdk/core");
|
|
6
|
+
const consts_1 = require("../../consts");
|
|
6
7
|
const identity_event_1 = require("./identity-event");
|
|
7
8
|
const sendEvent_1 = require("../send-event/sendEvent");
|
|
8
|
-
const consts_1 = require("../../consts");
|
|
9
9
|
/**
|
|
10
10
|
* A function that sends an IDENTITY event to SitecoreCloud API
|
|
11
11
|
*
|
|
@@ -15,12 +15,12 @@ const consts_1 = require("../../consts");
|
|
|
15
15
|
*/
|
|
16
16
|
function identityServer(request, identityData) {
|
|
17
17
|
const settings = (0, core_1.handleGetSettingsError)(core_1.getSettingsServer, consts_1.ErrorMessages.IE_0005);
|
|
18
|
-
const id = (0, core_1.
|
|
18
|
+
const id = (0, core_1.getCookieValueFromRequest)(request, settings.cookieSettings.cookieNames.browserId);
|
|
19
19
|
return new identity_event_1.IdentityEvent({
|
|
20
20
|
id,
|
|
21
21
|
identityData,
|
|
22
22
|
sendEvent: sendEvent_1.sendEvent,
|
|
23
|
-
settings: settings
|
|
23
|
+
settings: settings
|
|
24
24
|
}).send();
|
|
25
25
|
}
|
|
26
26
|
exports.identityServer = identityServer;
|
|
@@ -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,22 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PageViewEvent = void 0;
|
|
4
|
-
const utils_1 = require("@sitecore-cloudsdk/utils");
|
|
5
|
-
const base_event_1 = require("../base-event");
|
|
6
4
|
const consts_1 = require("../consts");
|
|
5
|
+
const base_event_1 = require("../base-event");
|
|
7
6
|
const consts_2 = require("../../consts");
|
|
7
|
+
const utils_1 = require("@sitecore-cloudsdk/utils");
|
|
8
8
|
class PageViewEvent extends base_event_1.BaseEvent {
|
|
9
9
|
/**
|
|
10
10
|
* A class that extends from {@link BaseEvent} and has all the required functionality to send a VIEW event
|
|
11
11
|
* @param args - Unified object containing the required properties
|
|
12
12
|
*/
|
|
13
13
|
constructor(args) {
|
|
14
|
-
const { channel, currency, language, page, extensionData } = args.pageViewData;
|
|
14
|
+
const { channel, currency, language, page, extensionData } = { ...args.pageViewData };
|
|
15
15
|
super({
|
|
16
16
|
channel,
|
|
17
17
|
currency,
|
|
18
18
|
language,
|
|
19
|
-
page
|
|
19
|
+
page
|
|
20
20
|
}, args.id);
|
|
21
21
|
this.extensionData = {};
|
|
22
22
|
this.pageViewData = args.pageViewData;
|
|
@@ -28,8 +28,7 @@ class PageViewEvent extends base_event_1.BaseEvent {
|
|
|
28
28
|
const numberOfExtensionDataProperties = Object.entries(this.extensionData).length;
|
|
29
29
|
if (numberOfExtensionDataProperties > consts_1.MAX_EXT_ATTRIBUTES)
|
|
30
30
|
throw new Error(consts_2.ErrorMessages.IV_0005);
|
|
31
|
-
this.includeUTMParameters =
|
|
32
|
-
args.pageViewData.includeUTMParameters === undefined ? true : args.pageViewData.includeUTMParameters;
|
|
31
|
+
this.includeUTMParameters = (args.pageViewData && args.pageViewData.includeUTMParameters) ?? true;
|
|
33
32
|
}
|
|
34
33
|
/**
|
|
35
34
|
* Gets the variant ID from the url if not passed by the developer
|
|
@@ -52,7 +51,7 @@ class PageViewEvent extends base_event_1.BaseEvent {
|
|
|
52
51
|
* @returns - the referrer
|
|
53
52
|
*/
|
|
54
53
|
getReferrer() {
|
|
55
|
-
if (this.pageViewData
|
|
54
|
+
if (this.pageViewData?.referrer)
|
|
56
55
|
return this.pageViewData.referrer;
|
|
57
56
|
if (typeof window === 'undefined')
|
|
58
57
|
return null;
|
|
@@ -66,24 +65,33 @@ class PageViewEvent extends base_event_1.BaseEvent {
|
|
|
66
65
|
* @returns the mapped object to be sent as payload
|
|
67
66
|
*/
|
|
68
67
|
mapAttributes() {
|
|
69
|
-
let
|
|
70
|
-
type: 'VIEW'
|
|
68
|
+
let pageViewPayload = {
|
|
69
|
+
type: 'VIEW'
|
|
71
70
|
};
|
|
72
|
-
const pageVariantId = this.
|
|
71
|
+
const pageVariantId = this.pageViewData &&
|
|
72
|
+
this.getPageVariantId(this.pageViewData.pageVariantId, this.extensionData['pageVariantId']);
|
|
73
73
|
if (pageVariantId !== null)
|
|
74
|
-
|
|
74
|
+
pageViewPayload.ext = { ...pageViewPayload.ext, pageVariantId };
|
|
75
75
|
if (Object.keys(this.extensionData).length > 0) {
|
|
76
76
|
delete this.extensionData['pageVariantId'];
|
|
77
|
-
|
|
77
|
+
pageViewPayload.ext = { ...pageViewPayload.ext, ...this.extensionData };
|
|
78
78
|
}
|
|
79
79
|
if (this.includeUTMParameters) {
|
|
80
80
|
const utmParameters = this.getUTMParameters();
|
|
81
|
-
|
|
81
|
+
pageViewPayload = { ...pageViewPayload, ...utmParameters };
|
|
82
82
|
}
|
|
83
83
|
const referrer = this.getReferrer();
|
|
84
84
|
if (referrer !== null)
|
|
85
|
-
|
|
86
|
-
|
|
85
|
+
pageViewPayload = { ...pageViewPayload, referrer };
|
|
86
|
+
if (this.pageViewData?.searchData)
|
|
87
|
+
pageViewPayload.sc_search = {
|
|
88
|
+
data: this.pageViewData.searchData,
|
|
89
|
+
metadata: {
|
|
90
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
91
|
+
ut_api_version: '1.0'
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
return pageViewPayload;
|
|
87
95
|
}
|
|
88
96
|
/**
|
|
89
97
|
* Sends the event to Sitecore EP
|
|
@@ -92,9 +100,8 @@ class PageViewEvent extends base_event_1.BaseEvent {
|
|
|
92
100
|
async send() {
|
|
93
101
|
const baseAttr = this.mapBaseEventPayload();
|
|
94
102
|
const eventAttrs = this.mapAttributes();
|
|
95
|
-
const fetchBody = Object.assign({}, eventAttrs, baseAttr);
|
|
96
103
|
PageViewEvent.isFirstPageView = false;
|
|
97
|
-
return await this.sendEvent(
|
|
104
|
+
return await this.sendEvent({ ...baseAttr, ...eventAttrs }, this.settings);
|
|
98
105
|
}
|
|
99
106
|
/**
|
|
100
107
|
* Retrieves UTM parameters from the url query string
|