@sitecore-cloudsdk/events 0.1.4 → 0.1.5
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 +4 -8
- package/dist/cjs/src/lib/consts.d.ts +0 -10
- package/dist/cjs/src/lib/consts.js +2 -13
- package/dist/cjs/src/lib/ep/EventApiClient.d.ts +18 -0
- package/dist/cjs/src/lib/ep/EventApiClient.js +34 -0
- package/dist/cjs/src/lib/eventStorage/addToEventQueue.d.ts +1 -1
- package/dist/cjs/src/lib/eventStorage/addToEventQueue.js +3 -8
- package/dist/cjs/src/lib/eventStorage/clearEventQueue.d.ts +1 -1
- package/dist/cjs/src/lib/eventStorage/clearEventQueue.js +3 -4
- package/dist/cjs/src/lib/eventStorage/eventStorage.d.ts +8 -4
- package/dist/cjs/src/lib/eventStorage/eventStorage.js +15 -15
- package/dist/cjs/src/lib/eventStorage/processEventQueue.d.ts +1 -1
- package/dist/cjs/src/lib/eventStorage/processEventQueue.js +3 -4
- package/dist/cjs/src/lib/events/base-event.d.ts +3 -1
- package/dist/cjs/src/lib/events/base-event.js +2 -1
- package/dist/cjs/src/lib/events/custom-event/custom-event.d.ts +3 -4
- package/dist/cjs/src/lib/events/custom-event/custom-event.js +4 -6
- package/dist/cjs/src/lib/events/custom-event/event.js +3 -7
- package/dist/cjs/src/lib/events/custom-event/eventServer.js +4 -4
- package/dist/cjs/src/lib/events/custom-event/form.js +4 -8
- package/dist/cjs/src/lib/events/identity/identity-event.d.ts +3 -4
- package/dist/cjs/src/lib/events/identity/identity-event.js +8 -10
- package/dist/cjs/src/lib/events/identity/identity.js +5 -8
- package/dist/cjs/src/lib/events/identity/identityServer.js +3 -3
- package/dist/cjs/src/lib/events/page-view/page-view-event.d.ts +3 -4
- package/dist/cjs/src/lib/events/page-view/page-view-event.js +5 -6
- package/dist/cjs/src/lib/events/page-view/page-view-server.js +3 -3
- package/dist/cjs/src/lib/events/page-view/page-view.js +4 -9
- package/dist/cjs/src/lib/getGuestId/getGuestId.js +4 -6
- package/dist/cjs/src/lib/initializer/browser/initializer.d.ts +19 -6
- package/dist/cjs/src/lib/initializer/browser/initializer.js +39 -21
- package/dist/cjs/src/lib/initializer/server/initializer.d.ts +16 -1
- package/dist/cjs/src/lib/initializer/server/initializer.js +28 -1
- package/dist/cjs/src/server.d.ts +1 -0
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/package.json +4 -8
- package/dist/esm/src/lib/consts.d.ts +0 -10
- package/dist/esm/src/lib/consts.js +1 -12
- package/dist/esm/src/lib/ep/EventApiClient.d.ts +18 -0
- package/dist/esm/src/lib/ep/EventApiClient.js +30 -0
- package/dist/esm/src/lib/eventStorage/addToEventQueue.d.ts +1 -1
- package/dist/esm/src/lib/eventStorage/addToEventQueue.js +3 -8
- package/dist/esm/src/lib/eventStorage/clearEventQueue.d.ts +1 -1
- package/dist/esm/src/lib/eventStorage/clearEventQueue.js +3 -4
- package/dist/esm/src/lib/eventStorage/eventStorage.d.ts +8 -4
- package/dist/esm/src/lib/eventStorage/eventStorage.js +14 -15
- package/dist/esm/src/lib/eventStorage/processEventQueue.d.ts +1 -1
- package/dist/esm/src/lib/eventStorage/processEventQueue.js +3 -4
- package/dist/esm/src/lib/events/base-event.d.ts +3 -1
- package/dist/esm/src/lib/events/base-event.js +2 -1
- package/dist/esm/src/lib/events/custom-event/custom-event.d.ts +3 -4
- package/dist/esm/src/lib/events/custom-event/custom-event.js +4 -6
- package/dist/esm/src/lib/events/custom-event/event.js +4 -8
- package/dist/esm/src/lib/events/custom-event/eventServer.js +5 -5
- package/dist/esm/src/lib/events/custom-event/form.js +4 -8
- package/dist/esm/src/lib/events/identity/identity-event.d.ts +3 -4
- package/dist/esm/src/lib/events/identity/identity-event.js +8 -10
- package/dist/esm/src/lib/events/identity/identity.js +5 -8
- package/dist/esm/src/lib/events/identity/identityServer.js +4 -4
- package/dist/esm/src/lib/events/page-view/page-view-event.d.ts +3 -4
- package/dist/esm/src/lib/events/page-view/page-view-event.js +5 -6
- package/dist/esm/src/lib/events/page-view/page-view-server.js +4 -4
- package/dist/esm/src/lib/events/page-view/page-view.js +4 -9
- package/dist/esm/src/lib/getGuestId/getGuestId.js +4 -6
- package/dist/esm/src/lib/initializer/browser/initializer.d.ts +19 -6
- package/dist/esm/src/lib/initializer/browser/initializer.js +37 -20
- package/dist/esm/src/lib/initializer/server/initializer.d.ts +16 -1
- package/dist/esm/src/lib/initializer/server/initializer.js +26 -1
- package/dist/esm/src/server.d.ts +1 -0
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -8
- package/dist/cjs/src/lib/events/send-event/sendEvent.d.ts +0 -17
- package/dist/cjs/src/lib/events/send-event/sendEvent.js +0 -29
- package/dist/esm/src/lib/events/send-event/sendEvent.d.ts +0 -17
- package/dist/esm/src/lib/events/send-event/sendEvent.js +0 -25
|
@@ -1,19 +1,8 @@
|
|
|
1
1
|
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
|
|
2
2
|
/* eslint-disable @typescript-eslint/naming-convention */
|
|
3
3
|
import packageJson from '../../package.json';
|
|
4
|
-
import { MAX_EXT_ATTRIBUTES } from './events/consts';
|
|
5
4
|
/**
|
|
6
5
|
* Returns the version of the library.
|
|
7
6
|
*/
|
|
8
7
|
export const LIBRARY_VERSION = packageJson.version;
|
|
9
|
-
|
|
10
|
-
(function (ErrorMessages) {
|
|
11
|
-
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.";
|
|
12
|
-
ErrorMessages["IE_0004"] = "[IE-0004] You must first initialize the \"events/browser\" module. Run the \"init\" function.";
|
|
13
|
-
ErrorMessages["IE_0005"] = "[IE-0005] You must first initialize the \"events/server\" module. Run the \"init\" function.";
|
|
14
|
-
ErrorMessages["IV_0002"] = "[IV-0002] Incorrect value for \"dob\". Format the value according to ISO 8601.";
|
|
15
|
-
ErrorMessages["IV_0003"] = "[IV-0003] Incorrect value for \"email\". Set the value to a valid email address.";
|
|
16
|
-
ErrorMessages["IV_0004"] = "[IV-0004] Incorrect value for \"expiryDate\". Format the value according to ISO 8601.";
|
|
17
|
-
ErrorMessages["IV_0005"] = "[IV-0005] This event supports maximum 50 attributes. Reduce the number of attributes.";
|
|
18
|
-
ErrorMessages["MV_0003"] = "[MV-0003] \"identifiers\" is required.";
|
|
19
|
-
})(ErrorMessages || (ErrorMessages = {}));
|
|
8
|
+
// just a commit change
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { EPResponse } from '@sitecore-cloudsdk/core';
|
|
2
|
+
import type { BasePayload, PageViewEventPayload, IdentityEventPayload, CustomEventPayload } from '../events';
|
|
3
|
+
export declare class EventApiClient implements EventApiClient {
|
|
4
|
+
private targetURL;
|
|
5
|
+
private readonly eventUrl;
|
|
6
|
+
constructor(targetURL: string, sitecoreEdgeContextId: string, siteName: string);
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* The interface of EventApiClient class
|
|
10
|
+
*/
|
|
11
|
+
export interface EventApiClient {
|
|
12
|
+
send(body: EPFetchBody & BasePayload): Promise<EPResponse | null>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The type describing all possible event payloads
|
|
16
|
+
*/
|
|
17
|
+
type EPFetchBody = PageViewEventPayload | IdentityEventPayload | CustomEventPayload;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
|
|
2
|
+
import { API_VERSION } from '@sitecore-cloudsdk/core';
|
|
3
|
+
import { LIBRARY_VERSION } from '../consts';
|
|
4
|
+
export class EventApiClient {
|
|
5
|
+
constructor(targetURL, sitecoreEdgeContextId, siteName) {
|
|
6
|
+
this.targetURL = targetURL;
|
|
7
|
+
this.eventUrl = `${this.targetURL}/events/${API_VERSION}/events?sitecoreContextId=${sitecoreEdgeContextId}&siteId=${siteName}`;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* A function that sends the payload to Sitecore EP
|
|
11
|
+
* @param body - The Request body for the Sitecore EP
|
|
12
|
+
* @returns - A promise that resolves with either the Sitecore EP response object or null
|
|
13
|
+
*/
|
|
14
|
+
async send(body) {
|
|
15
|
+
const fetchOptions = {
|
|
16
|
+
body: JSON.stringify(body),
|
|
17
|
+
headers: {
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
19
|
+
'Content-Type': 'application/json',
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
21
|
+
'X-Library-Version': LIBRARY_VERSION,
|
|
22
|
+
},
|
|
23
|
+
method: 'POST',
|
|
24
|
+
};
|
|
25
|
+
return await fetch(this.eventUrl, fetchOptions)
|
|
26
|
+
.then((response) => response.json())
|
|
27
|
+
.then((data) => data)
|
|
28
|
+
.catch(() => null);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -6,4 +6,4 @@ import { CustomEventInput, ExtensionData } from '../events';
|
|
|
6
6
|
* @param extensionData - The optional extensionData attributes that will be sent to SitecoreCloud API.
|
|
7
7
|
* This object will be flattened and sent in the ext object of the payload
|
|
8
8
|
*/
|
|
9
|
-
export declare function addToEventQueue(type: string, eventData: CustomEventInput, extensionData?: ExtensionData):
|
|
9
|
+
export declare function addToEventQueue(type: string, eventData: CustomEventInput, extensionData?: ExtensionData): void;
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import { awaitInit } from '../initializer/browser/initializer';
|
|
3
|
-
import { eventQueue } from './eventStorage';
|
|
4
|
-
import { getBrowserId, getSettings } from '@sitecore-cloudsdk/core';
|
|
1
|
+
import { getDependencies } from '../initializer/browser/initializer';
|
|
5
2
|
/**
|
|
6
3
|
* A function that adds event to the queue
|
|
7
4
|
* @param type - The required type of the event
|
|
@@ -9,10 +6,8 @@ import { getBrowserId, getSettings } from '@sitecore-cloudsdk/core';
|
|
|
9
6
|
* @param extensionData - The optional extensionData attributes that will be sent to SitecoreCloud API.
|
|
10
7
|
* This object will be flattened and sent in the ext object of the payload
|
|
11
8
|
*/
|
|
12
|
-
export
|
|
13
|
-
|
|
14
|
-
const settings = getSettings();
|
|
15
|
-
const id = getBrowserId();
|
|
9
|
+
export function addToEventQueue(type, eventData, extensionData) {
|
|
10
|
+
const { id, settings, eventQueue } = getDependencies();
|
|
16
11
|
const queueEventPayload = {
|
|
17
12
|
eventData,
|
|
18
13
|
extensionData,
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
|
|
2
|
-
import {
|
|
3
|
-
import { eventQueue } from './eventStorage';
|
|
2
|
+
import { getDependencies } from '../initializer/browser/initializer';
|
|
4
3
|
/**
|
|
5
4
|
* Deletes the queue from session.
|
|
6
5
|
*/
|
|
7
|
-
export
|
|
8
|
-
|
|
6
|
+
export function clearEventQueue() {
|
|
7
|
+
const { eventQueue } = getDependencies();
|
|
9
8
|
eventQueue.clearQueue();
|
|
10
9
|
}
|
|
@@ -1,9 +1,16 @@
|
|
|
1
|
+
import { EventApiClient } from '../ep/EventApiClient';
|
|
1
2
|
import { CustomEventArguments } from '../events';
|
|
2
|
-
declare class EventQueue {
|
|
3
|
+
export declare class EventQueue {
|
|
4
|
+
private storage;
|
|
5
|
+
private eventApiClient;
|
|
3
6
|
/**
|
|
4
7
|
* Initialize the Event Storage
|
|
8
|
+
* @param storage - Interface that describes the storage functionality
|
|
9
|
+
* @param eventApiClient - The API client which sends events to EP
|
|
10
|
+
* @param infer - The instance of the infer class
|
|
5
11
|
*/
|
|
6
12
|
private key;
|
|
13
|
+
constructor(storage: Storage, eventApiClient: EventApiClient);
|
|
7
14
|
/** Returns the stored array of data with type QueueEventPayload, or empty array if the given key does not exist. */
|
|
8
15
|
private getEventQueue;
|
|
9
16
|
/**
|
|
@@ -20,7 +27,6 @@ declare class EventQueue {
|
|
|
20
27
|
* Clears the queue from storage.
|
|
21
28
|
*/
|
|
22
29
|
clearQueue(): void;
|
|
23
|
-
private getSessionStorage;
|
|
24
30
|
}
|
|
25
31
|
/**
|
|
26
32
|
* This Storage interface represents the required storage functionality.
|
|
@@ -31,5 +37,3 @@ export interface Storage {
|
|
|
31
37
|
removeItem(key: string): void;
|
|
32
38
|
}
|
|
33
39
|
export type QueueEventPayload = Pick<CustomEventArguments, 'eventData' | 'extensionData' | 'type' | 'settings' | 'id'>;
|
|
34
|
-
export declare const eventQueue: EventQueue;
|
|
35
|
-
export {};
|
|
@@ -1,18 +1,23 @@
|
|
|
1
1
|
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
|
|
2
2
|
import { pageName, language } from '@sitecore-cloudsdk/core';
|
|
3
3
|
import { CustomEvent } from '../events';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
export class EventQueue {
|
|
5
|
+
constructor(storage, eventApiClient) {
|
|
6
|
+
this.storage = storage;
|
|
7
|
+
this.eventApiClient = eventApiClient;
|
|
7
8
|
/**
|
|
8
9
|
* Initialize the Event Storage
|
|
10
|
+
* @param storage - Interface that describes the storage functionality
|
|
11
|
+
* @param eventApiClient - The API client which sends events to EP
|
|
12
|
+
* @param infer - The instance of the infer class
|
|
9
13
|
*/
|
|
10
14
|
this.key = 'EventQueue';
|
|
11
15
|
}
|
|
12
16
|
/** Returns the stored array of data with type QueueEventPayload, or empty array if the given key does not exist. */
|
|
13
17
|
getEventQueue() {
|
|
14
|
-
const
|
|
15
|
-
|
|
18
|
+
const storedQueue = this.storage.getItem(this.key);
|
|
19
|
+
if (!storedQueue)
|
|
20
|
+
return [];
|
|
16
21
|
try {
|
|
17
22
|
const parsedQueueEvent = JSON.parse(storedQueue);
|
|
18
23
|
return Array.isArray(parsedQueueEvent) ? parsedQueueEvent : [];
|
|
@@ -27,16 +32,15 @@ class EventQueue {
|
|
|
27
32
|
* Performs validation by creating a new CustomEvent.
|
|
28
33
|
*/
|
|
29
34
|
enqueueEvent(queueEventPayload) {
|
|
30
|
-
const sessionStorage = this.getSessionStorage();
|
|
31
35
|
queueEventPayload.eventData.page = queueEventPayload.eventData.page ?? pageName();
|
|
32
36
|
queueEventPayload.eventData.language = queueEventPayload.eventData.language ?? language();
|
|
33
37
|
new CustomEvent({
|
|
34
|
-
|
|
38
|
+
eventApiClient: this.eventApiClient,
|
|
35
39
|
...queueEventPayload,
|
|
36
40
|
});
|
|
37
41
|
const eventQueue = this.getEventQueue();
|
|
38
42
|
eventQueue.push(queueEventPayload);
|
|
39
|
-
|
|
43
|
+
this.storage.setItem(this.key, JSON.stringify(eventQueue));
|
|
40
44
|
}
|
|
41
45
|
/**
|
|
42
46
|
* Iterates the queue, and sends sequently the custom events to Sitecore EP.
|
|
@@ -45,10 +49,10 @@ class EventQueue {
|
|
|
45
49
|
const eventQueue = this.getEventQueue();
|
|
46
50
|
for (const queueEventPayload of eventQueue) {
|
|
47
51
|
await new CustomEvent({
|
|
52
|
+
eventApiClient: this.eventApiClient,
|
|
48
53
|
eventData: queueEventPayload.eventData,
|
|
49
54
|
extensionData: queueEventPayload.extensionData,
|
|
50
55
|
id: queueEventPayload.id,
|
|
51
|
-
sendEvent,
|
|
52
56
|
settings: queueEventPayload.settings,
|
|
53
57
|
type: queueEventPayload.type,
|
|
54
58
|
}).send();
|
|
@@ -59,11 +63,6 @@ class EventQueue {
|
|
|
59
63
|
* Clears the queue from storage.
|
|
60
64
|
*/
|
|
61
65
|
clearQueue() {
|
|
62
|
-
|
|
63
|
-
sessionStorage.removeItem(this.key);
|
|
64
|
-
}
|
|
65
|
-
getSessionStorage() {
|
|
66
|
-
return sessionStorage;
|
|
66
|
+
this.storage.removeItem(this.key);
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
|
-
export const eventQueue = new EventQueue();
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
|
|
2
|
-
import {
|
|
3
|
-
import { eventQueue } from './eventStorage';
|
|
2
|
+
import { getDependencies } from '../initializer/browser/initializer';
|
|
4
3
|
/**
|
|
5
4
|
* A function that sends all queue events to SitecoreCloud API.
|
|
6
5
|
* Clears the queue upon completion.
|
|
7
6
|
*/
|
|
8
|
-
export
|
|
9
|
-
|
|
7
|
+
export function processEventQueue() {
|
|
8
|
+
const { eventQueue } = getDependencies();
|
|
10
9
|
eventQueue.sendAllEvents();
|
|
11
10
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import type { Settings } from '@sitecore-cloudsdk/core';
|
|
1
2
|
import { EventAttributesInput } from './common-interfaces';
|
|
2
3
|
export declare class BaseEvent {
|
|
3
4
|
private baseEventData;
|
|
5
|
+
protected settings: Settings;
|
|
4
6
|
private readonly browserId;
|
|
5
7
|
private readonly language;
|
|
6
8
|
page: string;
|
|
@@ -11,7 +13,7 @@ export declare class BaseEvent {
|
|
|
11
13
|
* @param id - The browser id
|
|
12
14
|
* @param infer - The source of methods to estimate language and page parameters
|
|
13
15
|
*/
|
|
14
|
-
constructor(baseEventData: BaseEventData, id: string);
|
|
16
|
+
constructor(baseEventData: BaseEventData, settings: Settings, id: string);
|
|
15
17
|
/**
|
|
16
18
|
* A function that returns the properties for sending events to Sitecore EP
|
|
17
19
|
* @returns an object that is required
|
|
@@ -8,8 +8,9 @@ export class BaseEvent {
|
|
|
8
8
|
* @param id - The browser id
|
|
9
9
|
* @param infer - The source of methods to estimate language and page parameters
|
|
10
10
|
*/
|
|
11
|
-
constructor(baseEventData, id) {
|
|
11
|
+
constructor(baseEventData, settings, id) {
|
|
12
12
|
this.baseEventData = baseEventData;
|
|
13
|
+
this.settings = settings;
|
|
13
14
|
this.browserId = id;
|
|
14
15
|
this.language = this.baseEventData.language ?? language();
|
|
15
16
|
this.page = this.baseEventData.page ?? pageName();
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { BaseEvent } from '../base-event';
|
|
2
2
|
import { EventAttributesInput } from '../common-interfaces';
|
|
3
|
-
import {
|
|
3
|
+
import { EventApiClient } from '../../ep/EventApiClient';
|
|
4
4
|
import { EPResponse, Settings } from '@sitecore-cloudsdk/core';
|
|
5
5
|
import { BasicTypes, NestedObject } from '@sitecore-cloudsdk/utils';
|
|
6
6
|
export declare class CustomEvent extends BaseEvent {
|
|
7
7
|
customEventPayload: CustomEventPayload;
|
|
8
|
-
private
|
|
8
|
+
private eventApiClient;
|
|
9
9
|
private extensionData;
|
|
10
|
-
private settings;
|
|
11
10
|
/**
|
|
12
11
|
* A class that extends from {@link BaseEvent} and has all the required functionality to send a VIEW event
|
|
13
12
|
* @param args - Unified object containing the required properties
|
|
@@ -23,7 +22,7 @@ export declare class CustomEvent extends BaseEvent {
|
|
|
23
22
|
* Interface of the unified arguments object for custom event
|
|
24
23
|
*/
|
|
25
24
|
export interface CustomEventArguments {
|
|
26
|
-
|
|
25
|
+
eventApiClient: EventApiClient;
|
|
27
26
|
eventData: CustomEventData;
|
|
28
27
|
id: string;
|
|
29
28
|
extensionData?: NestedObject;
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
import { BaseEvent } from '../base-event';
|
|
3
3
|
import { flattenObject } from '@sitecore-cloudsdk/utils';
|
|
4
4
|
import { MAX_EXT_ATTRIBUTES } from '../consts';
|
|
5
|
-
import { ErrorMessages } from '../../consts';
|
|
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
|
|
@@ -10,10 +9,9 @@ export class CustomEvent extends BaseEvent {
|
|
|
10
9
|
*/
|
|
11
10
|
constructor(args) {
|
|
12
11
|
const { channel, currency, language, page, ...rest } = args.eventData;
|
|
13
|
-
super({ channel, currency, language, page }, args.id);
|
|
12
|
+
super({ channel, currency, language, page }, args.settings, args.id);
|
|
14
13
|
this.extensionData = {};
|
|
15
|
-
this.
|
|
16
|
-
this.settings = args.settings;
|
|
14
|
+
this.eventApiClient = args.eventApiClient;
|
|
17
15
|
this.customEventPayload = {
|
|
18
16
|
type: args.type,
|
|
19
17
|
...rest,
|
|
@@ -22,7 +20,7 @@ export class CustomEvent extends BaseEvent {
|
|
|
22
20
|
this.extensionData = flattenObject({ object: args.extensionData });
|
|
23
21
|
const numberOfExtensionDataProperties = Object.entries(this.extensionData).length;
|
|
24
22
|
if (numberOfExtensionDataProperties > MAX_EXT_ATTRIBUTES)
|
|
25
|
-
throw new Error(
|
|
23
|
+
throw new Error(`[IV-0005] This event supports maximum ${MAX_EXT_ATTRIBUTES} attributes. Reduce the number of attributes.`);
|
|
26
24
|
if (numberOfExtensionDataProperties > 0)
|
|
27
25
|
this.customEventPayload.ext = this.extensionData;
|
|
28
26
|
}
|
|
@@ -33,6 +31,6 @@ export class CustomEvent extends BaseEvent {
|
|
|
33
31
|
async send() {
|
|
34
32
|
const baseAttr = this.mapBaseEventPayload();
|
|
35
33
|
const fetchBody = Object.assign({}, this.customEventPayload, baseAttr);
|
|
36
|
-
return await this.
|
|
34
|
+
return await this.eventApiClient.send(fetchBody);
|
|
37
35
|
}
|
|
38
36
|
}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
|
|
2
|
-
import { getBrowserId, getSettings } from '@sitecore-cloudsdk/core';
|
|
3
2
|
import { CustomEvent } from './custom-event';
|
|
4
|
-
import {
|
|
5
|
-
import { sendEvent } from '../send-event/sendEvent';
|
|
3
|
+
import { getDependencies } from '../../initializer/browser/initializer';
|
|
6
4
|
/**
|
|
7
5
|
* A function that sends an event to SitecoreCloud API with the specified type
|
|
8
6
|
* @param type - The required type of the event
|
|
@@ -11,15 +9,13 @@ import { sendEvent } from '../send-event/sendEvent';
|
|
|
11
9
|
* This object will be flattened and sent in the ext object of the payload
|
|
12
10
|
* @returns The response object that Sitecore EP returns
|
|
13
11
|
*/
|
|
14
|
-
export
|
|
15
|
-
|
|
16
|
-
const settings = getSettings();
|
|
17
|
-
const id = getBrowserId();
|
|
12
|
+
export function event(type, eventData, extensionData) {
|
|
13
|
+
const { eventApiClient, id, settings } = getDependencies();
|
|
18
14
|
return new CustomEvent({
|
|
15
|
+
eventApiClient,
|
|
19
16
|
eventData,
|
|
20
17
|
extensionData,
|
|
21
18
|
id,
|
|
22
|
-
sendEvent,
|
|
23
19
|
settings,
|
|
24
20
|
type,
|
|
25
21
|
}).send();
|
|
@@ -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 { getBrowserIdFromRequest
|
|
2
|
+
import { getBrowserIdFromRequest } from '@sitecore-cloudsdk/core';
|
|
3
3
|
import { CustomEvent } from './custom-event';
|
|
4
|
-
import {
|
|
4
|
+
import { getServerDependencies } from '../../initializer/server/initializer';
|
|
5
5
|
/**
|
|
6
6
|
* A function that sends an event to SitecoreCloud API with the specified type
|
|
7
7
|
* @param type - The required type of the event
|
|
@@ -11,14 +11,14 @@ import { sendEvent } from '../send-event/sendEvent';
|
|
|
11
11
|
* @returns The response object that Sitecore EP returns
|
|
12
12
|
*/
|
|
13
13
|
export function eventServer(type, eventData, request, extensionData) {
|
|
14
|
-
const settings =
|
|
14
|
+
const { eventApiClient, settings } = getServerDependencies();
|
|
15
15
|
const id = getBrowserIdFromRequest(request, settings.cookieSettings.cookieName);
|
|
16
16
|
return new CustomEvent({
|
|
17
|
+
eventApiClient,
|
|
17
18
|
eventData,
|
|
18
19
|
extensionData,
|
|
19
20
|
id,
|
|
20
|
-
|
|
21
|
-
settings,
|
|
21
|
+
settings: settings,
|
|
22
22
|
type,
|
|
23
23
|
}).send();
|
|
24
24
|
}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
|
|
2
|
-
import {
|
|
2
|
+
import { getDependencies } from '../../initializer/browser/initializer';
|
|
3
3
|
import { CustomEvent } from './custom-event';
|
|
4
|
-
import { sendEvent } from '../send-event/sendEvent';
|
|
5
|
-
import { awaitInit } from '../../initializer/browser/initializer';
|
|
6
4
|
/**
|
|
7
5
|
* A function that sends a form event to SitecoreCloud API
|
|
8
6
|
* @param formId - The required form ID string
|
|
@@ -10,18 +8,16 @@ import { awaitInit } from '../../initializer/browser/initializer';
|
|
|
10
8
|
* settings object, you must specify it here
|
|
11
9
|
* @returns The response object that Sitecore EP returns or null
|
|
12
10
|
*/
|
|
13
|
-
export
|
|
14
|
-
|
|
15
|
-
const settings = getSettings();
|
|
16
|
-
const id = getBrowserId();
|
|
11
|
+
export function form(formId, interactionType) {
|
|
12
|
+
const { eventApiClient, id, settings } = getDependencies();
|
|
17
13
|
const formEvent = new CustomEvent({
|
|
14
|
+
eventApiClient,
|
|
18
15
|
eventData: {},
|
|
19
16
|
extensionData: {
|
|
20
17
|
formId,
|
|
21
18
|
interactionType: interactionType.toUpperCase(),
|
|
22
19
|
},
|
|
23
20
|
id,
|
|
24
|
-
sendEvent,
|
|
25
21
|
settings,
|
|
26
22
|
type: 'FORM',
|
|
27
23
|
});
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { BaseEvent } from '../base-event';
|
|
2
2
|
import { ExtensionData, EventAttributesInput } from '../common-interfaces';
|
|
3
|
+
import { EventApiClient } from '../../ep/EventApiClient';
|
|
3
4
|
import { FlattenedObject } from '@sitecore-cloudsdk/utils';
|
|
4
5
|
import { EPResponse, Infer, Settings } from '@sitecore-cloudsdk/core';
|
|
5
|
-
import { SendEvent } from '../send-event/sendEvent';
|
|
6
6
|
export declare class IdentityEvent extends BaseEvent {
|
|
7
7
|
private eventData;
|
|
8
|
-
private
|
|
8
|
+
private eventApiClient;
|
|
9
9
|
private extensionData;
|
|
10
10
|
private numberOfExtensionDataProperties;
|
|
11
|
-
private settings;
|
|
12
11
|
/**
|
|
13
12
|
* A class that extends from {@link BaseEvent} and has all the required functionality to send a VIEW event
|
|
14
13
|
* @param args - Unified object containing the required properties
|
|
@@ -90,7 +89,7 @@ export interface IdentityEventPayload {
|
|
|
90
89
|
* Interface of the unified arguments object for identity event
|
|
91
90
|
*/
|
|
92
91
|
export interface IdentityEventArguments {
|
|
93
|
-
|
|
92
|
+
eventApiClient: EventApiClient;
|
|
94
93
|
eventData: IdentityEventAttributesInput;
|
|
95
94
|
extensionData?: ExtensionData;
|
|
96
95
|
id: string;
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
import { BaseEvent } from '../base-event';
|
|
3
3
|
import { MAX_EXT_ATTRIBUTES } from '../consts';
|
|
4
4
|
import { isShortISODateString, isValidEmail, flattenObject } from '@sitecore-cloudsdk/utils';
|
|
5
|
-
import { ErrorMessages } 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
|
|
@@ -10,18 +9,17 @@ export class IdentityEvent extends BaseEvent {
|
|
|
10
9
|
*/
|
|
11
10
|
constructor(args) {
|
|
12
11
|
const { channel, currency, language, page } = args.eventData;
|
|
13
|
-
super({ channel, currency, language, page }, args.id);
|
|
12
|
+
super({ channel, currency, language, page }, args.settings, args.id);
|
|
14
13
|
this.extensionData = {};
|
|
15
14
|
this.numberOfExtensionDataProperties = 0;
|
|
16
15
|
this.validateAttributes(args.eventData);
|
|
17
16
|
this.eventData = args.eventData;
|
|
18
|
-
this.
|
|
19
|
-
this.settings = args.settings;
|
|
17
|
+
this.eventApiClient = args.eventApiClient;
|
|
20
18
|
if (args.extensionData)
|
|
21
19
|
this.extensionData = flattenObject({ object: args.extensionData });
|
|
22
20
|
this.numberOfExtensionDataProperties = Object.entries(this.extensionData).length;
|
|
23
21
|
if (this.numberOfExtensionDataProperties > MAX_EXT_ATTRIBUTES)
|
|
24
|
-
throw new Error(
|
|
22
|
+
throw new Error(`[IV-0005] This event supports maximum ${MAX_EXT_ATTRIBUTES} attributes. Reduce the number of attributes.`);
|
|
25
23
|
}
|
|
26
24
|
/**
|
|
27
25
|
* Function that validates the identifiers object, email and date attributes for CDN users
|
|
@@ -29,15 +27,15 @@ export class IdentityEvent extends BaseEvent {
|
|
|
29
27
|
*/
|
|
30
28
|
validateAttributes(eventData) {
|
|
31
29
|
if (eventData.identifiers.length === 0)
|
|
32
|
-
throw new Error(
|
|
30
|
+
throw new Error(`[MV-0003] "identifiers" is required.`);
|
|
33
31
|
if (eventData.dob !== undefined && !isShortISODateString(eventData.dob))
|
|
34
|
-
throw new Error(
|
|
32
|
+
throw new Error(`[IV-0002] Incorrect value for "dob". Format the value according to ISO 8601.`);
|
|
35
33
|
eventData.identifiers.forEach((identifier) => {
|
|
36
34
|
if (identifier.expiryDate && !isShortISODateString(identifier.expiryDate))
|
|
37
|
-
throw new Error(
|
|
35
|
+
throw new Error(`[IV-0004] Incorrect value for "expiryDate". Format the value according to ISO 8601.`);
|
|
38
36
|
});
|
|
39
37
|
if (eventData.email && !isValidEmail(eventData.email))
|
|
40
|
-
throw new Error(
|
|
38
|
+
throw new Error(`[IV-0003] Incorrect value for "email". Set the value to a valid email address.`);
|
|
41
39
|
}
|
|
42
40
|
/**
|
|
43
41
|
* A function that maps the identity event input data with the payload sent to the API
|
|
@@ -81,6 +79,6 @@ export class IdentityEvent extends BaseEvent {
|
|
|
81
79
|
const baseAttr = this.mapBaseEventPayload();
|
|
82
80
|
const eventAttrs = this.mapAttributes();
|
|
83
81
|
const fetchBody = Object.assign({}, eventAttrs, baseAttr);
|
|
84
|
-
return await this.
|
|
82
|
+
return await this.eventApiClient.send(fetchBody);
|
|
85
83
|
}
|
|
86
84
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
|
|
2
|
+
import { getDependencies } from '../../initializer/browser/initializer';
|
|
2
3
|
import { IdentityEvent } from './identity-event';
|
|
3
|
-
import { awaitInit } from '../../initializer/browser/initializer';
|
|
4
|
-
import { sendEvent } from '../send-event/sendEvent';
|
|
5
4
|
/**
|
|
6
5
|
* A function that sends an IDENTITY event to SitecoreCloud API
|
|
7
6
|
* @param eventData - The required/optional attributes in order to be send to SitecoreCloud API
|
|
@@ -9,15 +8,13 @@ import { sendEvent } from '../send-event/sendEvent';
|
|
|
9
8
|
* This object will be flattened and sent in the ext object of the payload
|
|
10
9
|
* @returns The response object that Sitecore EP returns
|
|
11
10
|
*/
|
|
12
|
-
export
|
|
13
|
-
|
|
14
|
-
const settings = getSettings();
|
|
15
|
-
const id = getBrowserId();
|
|
11
|
+
export function identity(eventData, extensionData) {
|
|
12
|
+
const { eventApiClient, id, settings } = getDependencies();
|
|
16
13
|
return new IdentityEvent({
|
|
14
|
+
eventApiClient,
|
|
17
15
|
eventData,
|
|
18
16
|
extensionData,
|
|
19
17
|
id,
|
|
20
|
-
sendEvent,
|
|
21
18
|
settings,
|
|
22
19
|
}).send();
|
|
23
20
|
}
|
|
@@ -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 { getBrowserIdFromRequest
|
|
2
|
+
import { getBrowserIdFromRequest } from '@sitecore-cloudsdk/core';
|
|
3
|
+
import { getServerDependencies } from '../../initializer/server/initializer';
|
|
3
4
|
import { IdentityEvent } from './identity-event';
|
|
4
|
-
import { sendEvent } from '../send-event/sendEvent';
|
|
5
5
|
/**
|
|
6
6
|
* A function that sends an IDENTITY event to SitecoreCloud API
|
|
7
7
|
* @param eventData - The required/optional attributes in order to be send to SitecoreCloud API
|
|
@@ -11,13 +11,13 @@ import { sendEvent } from '../send-event/sendEvent';
|
|
|
11
11
|
* @returns The response object that Sitecore EP returns
|
|
12
12
|
*/
|
|
13
13
|
export function identityServer(eventData, request, extensionData) {
|
|
14
|
-
const settings =
|
|
14
|
+
const { eventApiClient, settings } = getServerDependencies();
|
|
15
15
|
const id = getBrowserIdFromRequest(request, settings.cookieSettings.cookieName);
|
|
16
16
|
return new IdentityEvent({
|
|
17
|
+
eventApiClient,
|
|
17
18
|
eventData,
|
|
18
19
|
extensionData,
|
|
19
20
|
id,
|
|
20
|
-
sendEvent,
|
|
21
21
|
settings: settings,
|
|
22
22
|
}).send();
|
|
23
23
|
}
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import { EPResponse, Infer, Settings } from '@sitecore-cloudsdk/core';
|
|
2
2
|
import { FlattenedObject, NestedObject } from '@sitecore-cloudsdk/utils';
|
|
3
3
|
import { BaseEvent } from '../base-event';
|
|
4
|
+
import { EventApiClient } from '../../ep/EventApiClient';
|
|
4
5
|
import { EventAttributesInput } from '../common-interfaces';
|
|
5
|
-
import { SendEvent } from '../send-event/sendEvent';
|
|
6
6
|
export declare class PageViewEvent extends BaseEvent {
|
|
7
7
|
static isFirstPageView: boolean;
|
|
8
|
-
private
|
|
8
|
+
private eventApiClient;
|
|
9
9
|
private eventData;
|
|
10
10
|
private extensionData;
|
|
11
11
|
private urlSearchParams;
|
|
12
12
|
private includeUTMParameters;
|
|
13
|
-
settings: Settings;
|
|
14
13
|
/**
|
|
15
14
|
* A class that extends from {@link BaseEvent} and has all the required functionality to send a VIEW event
|
|
16
15
|
* @param args - Unified object containing the required properties
|
|
@@ -48,7 +47,7 @@ export declare class PageViewEvent extends BaseEvent {
|
|
|
48
47
|
* Interface of the unified arguments object for page view event
|
|
49
48
|
*/
|
|
50
49
|
export interface PageViewEventArguments {
|
|
51
|
-
|
|
50
|
+
eventApiClient: EventApiClient;
|
|
52
51
|
eventData: PageViewEventInput;
|
|
53
52
|
id: string;
|
|
54
53
|
settings: Settings;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
|
|
1
2
|
import { flattenObject } from '@sitecore-cloudsdk/utils';
|
|
2
3
|
import { BaseEvent } from '../base-event';
|
|
3
4
|
import { MAX_EXT_ATTRIBUTES, UTM_PREFIX } from '../consts';
|
|
4
|
-
import { ErrorMessages } from '../../consts';
|
|
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
|
|
@@ -14,17 +14,16 @@ export class PageViewEvent extends BaseEvent {
|
|
|
14
14
|
currency,
|
|
15
15
|
language,
|
|
16
16
|
page,
|
|
17
|
-
}, args.id);
|
|
17
|
+
}, args.settings, args.id);
|
|
18
18
|
this.extensionData = {};
|
|
19
19
|
this.eventData = args.eventData;
|
|
20
|
-
this.sendEvent = args.sendEvent;
|
|
21
|
-
this.settings = args.settings;
|
|
22
20
|
this.urlSearchParams = new URLSearchParams(decodeURI(args.searchParams));
|
|
23
21
|
if (args.extensionData)
|
|
24
22
|
this.extensionData = flattenObject({ object: args.extensionData });
|
|
25
23
|
const numberOfExtensionDataProperties = Object.entries(this.extensionData).length;
|
|
26
24
|
if (numberOfExtensionDataProperties > MAX_EXT_ATTRIBUTES)
|
|
27
|
-
throw new Error(
|
|
25
|
+
throw new Error(`[IV-0005] This event supports maximum ${MAX_EXT_ATTRIBUTES} attributes. Reduce the number of attributes.`);
|
|
26
|
+
this.eventApiClient = args.eventApiClient;
|
|
28
27
|
this.includeUTMParameters =
|
|
29
28
|
args.eventData.includeUTMParameters === undefined ? true : args.eventData.includeUTMParameters;
|
|
30
29
|
}
|
|
@@ -91,7 +90,7 @@ export class PageViewEvent extends BaseEvent {
|
|
|
91
90
|
const eventAttrs = this.mapAttributes();
|
|
92
91
|
const fetchBody = Object.assign({}, eventAttrs, baseAttr);
|
|
93
92
|
PageViewEvent.isFirstPageView = false;
|
|
94
|
-
return await this.
|
|
93
|
+
return await this.eventApiClient.send(fetchBody);
|
|
95
94
|
}
|
|
96
95
|
/**
|
|
97
96
|
* Retrieves UTM parameters from the url query string
|