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