@sitecore-cloudsdk/events 0.2.4 → 0.3.1-rc.0
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/README.md +8 -30
- package/dist/cjs/package.json +5 -6
- package/dist/cjs/src/browser.d.ts +1 -1
- package/dist/cjs/src/lib/consts.d.ts +5 -1
- package/dist/cjs/src/lib/consts.js +9 -3
- package/dist/cjs/src/lib/eventStorage/addToEventQueue.d.ts +3 -5
- package/dist/cjs/src/lib/eventStorage/addToEventQueue.js +5 -9
- package/dist/cjs/src/lib/eventStorage/eventStorage.d.ts +2 -2
- package/dist/cjs/src/lib/eventStorage/eventStorage.js +3 -6
- package/dist/cjs/src/lib/events/base-event.d.ts +3 -2
- package/dist/cjs/src/lib/events/base-event.js +3 -2
- package/dist/cjs/src/lib/events/common-interfaces.d.ts +4 -21
- package/dist/cjs/src/lib/events/custom-event/custom-event.d.ts +15 -14
- package/dist/cjs/src/lib/events/custom-event/custom-event.js +17 -10
- package/dist/cjs/src/lib/events/custom-event/event.d.ts +4 -7
- package/dist/cjs/src/lib/events/custom-event/event.js +4 -8
- package/dist/cjs/src/lib/events/custom-event/eventServer.d.ts +6 -8
- package/dist/cjs/src/lib/events/custom-event/eventServer.js +6 -9
- package/dist/cjs/src/lib/events/custom-event/form.d.ts +2 -1
- package/dist/cjs/src/lib/events/custom-event/form.js +10 -8
- package/dist/cjs/src/lib/events/identity/identity-event.d.ts +10 -9
- package/dist/cjs/src/lib/events/identity/identity-event.js +37 -37
- package/dist/cjs/src/lib/events/identity/identity.d.ts +4 -6
- package/dist/cjs/src/lib/events/identity/identity.js +6 -7
- package/dist/cjs/src/lib/events/identity/identityServer.d.ts +6 -8
- package/dist/cjs/src/lib/events/identity/identityServer.js +7 -9
- package/dist/cjs/src/lib/events/index.d.ts +3 -3
- package/dist/cjs/src/lib/events/page-view/page-view-event.d.ts +15 -7
- package/dist/cjs/src/lib/events/page-view/page-view-event.js +31 -24
- package/dist/cjs/src/lib/events/page-view/page-view-server.d.ts +6 -7
- package/dist/cjs/src/lib/events/page-view/page-view-server.js +7 -9
- package/dist/cjs/src/lib/events/page-view/page-view.d.ts +5 -6
- package/dist/cjs/src/lib/events/page-view/page-view.js +6 -7
- 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 +15 -3
- package/dist/cjs/src/lib/initializer/browser/initializer.js +6 -6
- package/dist/cjs/src/lib/initializer/server/initializer.d.ts +5 -3
- package/dist/cjs/src/lib/initializer/server/initializer.js +4 -3
- package/dist/cjs/src/server.d.ts +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/package.json +5 -6
- package/dist/esm/src/browser.d.ts +1 -1
- package/dist/esm/src/lib/consts.d.ts +5 -1
- package/dist/esm/src/lib/consts.js +8 -2
- package/dist/esm/src/lib/eventStorage/addToEventQueue.d.ts +3 -5
- package/dist/esm/src/lib/eventStorage/addToEventQueue.js +5 -9
- package/dist/esm/src/lib/eventStorage/eventStorage.d.ts +2 -2
- package/dist/esm/src/lib/eventStorage/eventStorage.js +4 -7
- package/dist/esm/src/lib/events/base-event.d.ts +3 -2
- package/dist/esm/src/lib/events/base-event.js +3 -2
- package/dist/esm/src/lib/events/common-interfaces.d.ts +4 -21
- package/dist/esm/src/lib/events/custom-event/custom-event.d.ts +15 -14
- package/dist/esm/src/lib/events/custom-event/custom-event.js +15 -8
- package/dist/esm/src/lib/events/custom-event/event.d.ts +4 -7
- package/dist/esm/src/lib/events/custom-event/event.js +4 -8
- package/dist/esm/src/lib/events/custom-event/eventServer.d.ts +6 -8
- package/dist/esm/src/lib/events/custom-event/eventServer.js +7 -10
- package/dist/esm/src/lib/events/custom-event/form.d.ts +2 -1
- package/dist/esm/src/lib/events/custom-event/form.js +10 -8
- package/dist/esm/src/lib/events/identity/identity-event.d.ts +10 -9
- package/dist/esm/src/lib/events/identity/identity-event.js +30 -30
- package/dist/esm/src/lib/events/identity/identity.d.ts +4 -6
- package/dist/esm/src/lib/events/identity/identity.js +6 -7
- package/dist/esm/src/lib/events/identity/identityServer.d.ts +6 -8
- package/dist/esm/src/lib/events/identity/identityServer.js +8 -10
- package/dist/esm/src/lib/events/index.d.ts +3 -3
- package/dist/esm/src/lib/events/page-view/page-view-event.d.ts +15 -7
- package/dist/esm/src/lib/events/page-view/page-view-event.js +31 -24
- package/dist/esm/src/lib/events/page-view/page-view-server.d.ts +6 -7
- package/dist/esm/src/lib/events/page-view/page-view-server.js +8 -10
- package/dist/esm/src/lib/events/page-view/page-view.d.ts +5 -6
- package/dist/esm/src/lib/events/page-view/page-view.js +6 -7
- 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 +15 -3
- package/dist/esm/src/lib/initializer/browser/initializer.js +7 -7
- package/dist/esm/src/lib/initializer/server/initializer.d.ts +5 -3
- package/dist/esm/src/lib/initializer/server/initializer.js +5 -4
- package/dist/esm/src/server.d.ts +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -6
|
@@ -1,46 +1,46 @@
|
|
|
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
|
|
11
|
+
*
|
|
12
12
|
* @param args - Unified object containing the required properties
|
|
13
13
|
*/
|
|
14
14
|
constructor(args) {
|
|
15
|
-
const { channel, currency, language, page } = args.
|
|
15
|
+
const { channel, currency, language, page, extensionData } = args.identityData;
|
|
16
16
|
super({ channel, currency, language, page }, args.id);
|
|
17
17
|
this.extensionData = {};
|
|
18
18
|
this.numberOfExtensionDataProperties = 0;
|
|
19
|
-
this.validateAttributes(args.
|
|
20
|
-
this.
|
|
19
|
+
this.validateAttributes(args.identityData);
|
|
20
|
+
this.identityData = args.identityData;
|
|
21
21
|
this.sendEvent = args.sendEvent;
|
|
22
22
|
this.settings = args.settings;
|
|
23
|
-
if (
|
|
24
|
-
this.extensionData = (0, utils_1.flattenObject)({ object:
|
|
23
|
+
if (extensionData)
|
|
24
|
+
this.extensionData = (0, utils_1.flattenObject)({ object: extensionData });
|
|
25
25
|
this.numberOfExtensionDataProperties = Object.entries(this.extensionData).length;
|
|
26
|
-
if (this.numberOfExtensionDataProperties >
|
|
27
|
-
throw new Error(
|
|
26
|
+
if (this.numberOfExtensionDataProperties > consts_2.MAX_EXT_ATTRIBUTES)
|
|
27
|
+
throw new Error(consts_1.ErrorMessages.IV_0005);
|
|
28
28
|
}
|
|
29
29
|
/**
|
|
30
30
|
* Function that validates the identifiers object, email and date attributes for CDN users
|
|
31
|
-
* * @param
|
|
31
|
+
* * @param identityData - The data to be validated
|
|
32
32
|
*/
|
|
33
|
-
validateAttributes(
|
|
34
|
-
if (
|
|
35
|
-
throw new Error(
|
|
36
|
-
if (
|
|
37
|
-
throw new Error(
|
|
38
|
-
|
|
33
|
+
validateAttributes(identityData) {
|
|
34
|
+
if (identityData.identifiers.length === 0)
|
|
35
|
+
throw new Error(consts_1.ErrorMessages.MV_0003);
|
|
36
|
+
if (identityData.dob !== undefined && !(0, utils_1.isShortISODateString)(identityData.dob))
|
|
37
|
+
throw new Error(consts_1.ErrorMessages.IV_0002);
|
|
38
|
+
identityData.identifiers.forEach((identifier) => {
|
|
39
39
|
if (identifier.expiryDate && !(0, utils_1.isShortISODateString)(identifier.expiryDate))
|
|
40
|
-
throw new Error(
|
|
40
|
+
throw new Error(consts_1.ErrorMessages.IV_0004);
|
|
41
41
|
});
|
|
42
|
-
if (
|
|
43
|
-
throw new Error(
|
|
42
|
+
if (identityData.email && !(0, utils_1.isValidEmail)(identityData.email))
|
|
43
|
+
throw new Error(consts_1.ErrorMessages.IV_0003);
|
|
44
44
|
}
|
|
45
45
|
/**
|
|
46
46
|
* A function that maps the identity event input data with the payload sent to the API
|
|
@@ -48,29 +48,29 @@ class IdentityEvent extends base_event_1.BaseEvent {
|
|
|
48
48
|
*/
|
|
49
49
|
mapAttributes() {
|
|
50
50
|
const identityPayload = {
|
|
51
|
-
city: this.
|
|
52
|
-
country: this.
|
|
53
|
-
dob: this.
|
|
54
|
-
email: this.
|
|
55
|
-
firstname: this.
|
|
56
|
-
gender: this.
|
|
57
|
-
identifiers: this.
|
|
51
|
+
city: this.identityData.city,
|
|
52
|
+
country: this.identityData.country,
|
|
53
|
+
dob: this.identityData.dob,
|
|
54
|
+
email: this.identityData.email,
|
|
55
|
+
firstname: this.identityData.firstName,
|
|
56
|
+
gender: this.identityData.gender,
|
|
57
|
+
identifiers: this.identityData.identifiers.map((value) => {
|
|
58
58
|
return {
|
|
59
59
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
60
60
|
expiry_date: value.expiryDate,
|
|
61
61
|
id: value.id,
|
|
62
|
-
provider: value.provider
|
|
62
|
+
provider: value.provider
|
|
63
63
|
};
|
|
64
64
|
}),
|
|
65
|
-
lastname: this.
|
|
66
|
-
mobile: this.
|
|
67
|
-
phone: this.
|
|
65
|
+
lastname: this.identityData.lastName,
|
|
66
|
+
mobile: this.identityData.mobile,
|
|
67
|
+
phone: this.identityData.phone,
|
|
68
68
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
69
|
-
postal_code: this.
|
|
70
|
-
state: this.
|
|
71
|
-
street: this.
|
|
72
|
-
title: this.
|
|
73
|
-
type: 'IDENTITY'
|
|
69
|
+
postal_code: this.identityData.postalCode,
|
|
70
|
+
state: this.identityData.state,
|
|
71
|
+
street: this.identityData.street,
|
|
72
|
+
title: this.identityData.title,
|
|
73
|
+
type: 'IDENTITY'
|
|
74
74
|
};
|
|
75
75
|
if (this.numberOfExtensionDataProperties > 0)
|
|
76
76
|
identityPayload.ext = this.extensionData;
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { IdentityEventAttributesInput } from './identity-event';
|
|
1
|
+
import type { EPResponse } from '@sitecore-cloudsdk/core';
|
|
2
|
+
import type { IdentityData } from './identity-event';
|
|
4
3
|
/**
|
|
5
4
|
* A function that sends an IDENTITY event to SitecoreCloud API
|
|
5
|
+
*
|
|
6
6
|
* @param eventData - The required/optional attributes in order to be send to SitecoreCloud API
|
|
7
|
-
* @param extensionData - The optional extensionData attributes that will be sent to SitecoreCloud API.
|
|
8
|
-
* This object will be flattened and sent in the ext object of the payload
|
|
9
7
|
* @returns The response object that Sitecore EP returns
|
|
10
8
|
*/
|
|
11
|
-
export declare function identity(
|
|
9
|
+
export declare function identity(identityData: IdentityData): Promise<EPResponse | null>;
|
|
@@ -1,28 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.identity = void 0;
|
|
4
|
+
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
|
|
4
5
|
const core_1 = require("@sitecore-cloudsdk/core");
|
|
6
|
+
const consts_1 = require("../../consts");
|
|
5
7
|
const identity_event_1 = require("./identity-event");
|
|
6
8
|
const initializer_1 = require("../../initializer/browser/initializer");
|
|
7
9
|
const sendEvent_1 = require("../send-event/sendEvent");
|
|
8
|
-
const consts_1 = require("../../consts");
|
|
9
10
|
/**
|
|
10
11
|
* A function that sends an IDENTITY event to SitecoreCloud API
|
|
12
|
+
*
|
|
11
13
|
* @param eventData - The required/optional attributes in order to be send to SitecoreCloud API
|
|
12
|
-
* @param extensionData - The optional extensionData attributes that will be sent to SitecoreCloud API.
|
|
13
|
-
* This object will be flattened and sent in the ext object of the payload
|
|
14
14
|
* @returns The response object that Sitecore EP returns
|
|
15
15
|
*/
|
|
16
|
-
async function identity(
|
|
16
|
+
async function identity(identityData) {
|
|
17
17
|
await (0, initializer_1.awaitInit)();
|
|
18
18
|
const settings = (0, core_1.handleGetSettingsError)(core_1.getSettings, consts_1.ErrorMessages.IE_0004);
|
|
19
19
|
const id = (0, core_1.getBrowserId)();
|
|
20
20
|
return new identity_event_1.IdentityEvent({
|
|
21
|
-
eventData,
|
|
22
|
-
extensionData,
|
|
23
21
|
id,
|
|
22
|
+
identityData,
|
|
24
23
|
sendEvent: sendEvent_1.sendEvent,
|
|
25
|
-
settings
|
|
24
|
+
settings
|
|
26
25
|
}).send();
|
|
27
26
|
}
|
|
28
27
|
exports.identity = identity;
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { IdentityEventAttributesInput } from './identity-event';
|
|
1
|
+
import type { EPResponse } from '@sitecore-cloudsdk/core';
|
|
2
|
+
import type { IdentityData } from './identity-event';
|
|
3
|
+
import type { Request } from '@sitecore-cloudsdk/utils';
|
|
5
4
|
/**
|
|
6
5
|
* A function that sends an IDENTITY event to SitecoreCloud API
|
|
7
|
-
*
|
|
6
|
+
*
|
|
8
7
|
* @param request - Interface with constraint for extending request
|
|
9
|
-
* @param
|
|
10
|
-
* This object will be flattened and sent in the ext object of the payload
|
|
8
|
+
* @param identityData - The required/optional attributes in order to be send to SitecoreCloud API
|
|
11
9
|
* @returns The response object that Sitecore EP returns
|
|
12
10
|
*/
|
|
13
|
-
export declare function identityServer(
|
|
11
|
+
export declare function identityServer(request: Request, identityData: IdentityData): Promise<EPResponse | null>;
|
|
@@ -3,26 +3,24 @@
|
|
|
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
|
+
*
|
|
12
12
|
* @param request - Interface with constraint for extending request
|
|
13
|
-
* @param
|
|
14
|
-
* This object will be flattened and sent in the ext object of the payload
|
|
13
|
+
* @param identityData - The required/optional attributes in order to be send to SitecoreCloud API
|
|
15
14
|
* @returns The response object that Sitecore EP returns
|
|
16
15
|
*/
|
|
17
|
-
function identityServer(
|
|
16
|
+
function identityServer(request, identityData) {
|
|
18
17
|
const settings = (0, core_1.handleGetSettingsError)(core_1.getSettingsServer, consts_1.ErrorMessages.IE_0005);
|
|
19
|
-
const id = (0, core_1.
|
|
18
|
+
const id = (0, core_1.getCookieValueFromRequest)(request, settings.cookieSettings.cookieNames.browserId);
|
|
20
19
|
return new identity_event_1.IdentityEvent({
|
|
21
|
-
eventData,
|
|
22
|
-
extensionData,
|
|
23
20
|
id,
|
|
21
|
+
identityData,
|
|
24
22
|
sendEvent: sendEvent_1.sendEvent,
|
|
25
|
-
settings: settings
|
|
23
|
+
settings: settings
|
|
26
24
|
}).send();
|
|
27
25
|
}
|
|
28
26
|
exports.identityServer = identityServer;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export { BaseEvent } from './base-event';
|
|
2
2
|
export type { BasePayload } from './base-event';
|
|
3
3
|
export { PageViewEvent } from './page-view/page-view-event';
|
|
4
|
-
export type {
|
|
4
|
+
export type { PageViewData, PageViewEventPayload } from './page-view/page-view-event';
|
|
5
5
|
export { CustomEvent } from './custom-event/custom-event';
|
|
6
|
-
export type {
|
|
6
|
+
export type { EventData, CustomEventPayload, CustomEventArguments } from './custom-event/custom-event';
|
|
7
7
|
export { IdentityEvent } from './identity/identity-event';
|
|
8
|
-
export type {
|
|
8
|
+
export type { IdentityData, IdentityEventPayload } from './identity/identity-event';
|
|
9
9
|
export type { ExtensionData } from './common-interfaces';
|
|
@@ -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
|
|
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
|
-
|
|
52
|
+
pageViewData?: PageViewData;
|
|
53
53
|
id: string;
|
|
54
54
|
settings: Settings;
|
|
55
55
|
infer?: Infer;
|
|
@@ -59,10 +59,12 @@ export interface PageViewEventArguments {
|
|
|
59
59
|
/**
|
|
60
60
|
* Type with the required/optional attributes in order to send a view event to SitecoreCloud API
|
|
61
61
|
*/
|
|
62
|
-
export interface
|
|
62
|
+
export interface PageViewData extends EventAttributesInput {
|
|
63
63
|
pageVariantId?: string;
|
|
64
64
|
referrer?: string;
|
|
65
65
|
includeUTMParameters?: boolean;
|
|
66
|
+
extensionData?: ExtensionData;
|
|
67
|
+
searchData?: NestedObject;
|
|
66
68
|
}
|
|
67
69
|
/**
|
|
68
70
|
* Interface with the utm_ parameters
|
|
@@ -79,5 +81,11 @@ export interface PageViewEventPayload extends UtmParameters {
|
|
|
79
81
|
ext?: {
|
|
80
82
|
pageVariantId?: string;
|
|
81
83
|
} & FlattenedObject;
|
|
84
|
+
sc_search?: {
|
|
85
|
+
data: NestedObject;
|
|
86
|
+
metadata: {
|
|
87
|
+
ut_api_version: string;
|
|
88
|
+
};
|
|
89
|
+
};
|
|
82
90
|
}
|
|
83
91
|
export {};
|
|
@@ -1,44 +1,43 @@
|
|
|
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 } = args.
|
|
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
|
-
this.
|
|
22
|
+
this.pageViewData = args.pageViewData;
|
|
23
23
|
this.sendEvent = args.sendEvent;
|
|
24
24
|
this.settings = args.settings;
|
|
25
25
|
this.urlSearchParams = new URLSearchParams(decodeURI(args.searchParams));
|
|
26
|
-
if (
|
|
27
|
-
this.extensionData = (0, utils_1.flattenObject)({ object:
|
|
26
|
+
if (extensionData)
|
|
27
|
+
this.extensionData = (0, utils_1.flattenObject)({ object: extensionData });
|
|
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.eventData.includeUTMParameters === undefined ? true : args.eventData.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
|
|
36
35
|
* Gets the variant ID from the extension data if not found from the url
|
|
37
36
|
* @returns - variant ID or null
|
|
38
37
|
*/
|
|
39
|
-
getPageVariantId(
|
|
40
|
-
if (
|
|
41
|
-
return
|
|
38
|
+
getPageVariantId(pageVariantIdFromPageViewData, pageVariantIdFromExt) {
|
|
39
|
+
if (pageVariantIdFromPageViewData)
|
|
40
|
+
return pageVariantIdFromPageViewData;
|
|
42
41
|
const pageVariantIdFromURL = this.urlSearchParams.get('variantid');
|
|
43
42
|
if (pageVariantIdFromURL)
|
|
44
43
|
return pageVariantIdFromURL;
|
|
@@ -52,8 +51,8 @@ class PageViewEvent extends base_event_1.BaseEvent {
|
|
|
52
51
|
* @returns - the referrer
|
|
53
52
|
*/
|
|
54
53
|
getReferrer() {
|
|
55
|
-
if (this.
|
|
56
|
-
return this.
|
|
54
|
+
if (this.pageViewData?.referrer)
|
|
55
|
+
return this.pageViewData.referrer;
|
|
57
56
|
if (typeof window === 'undefined')
|
|
58
57
|
return null;
|
|
59
58
|
if (!PageViewEvent.isFirstPageView || !document.referrer)
|
|
@@ -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
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import { EPResponse } from '@sitecore-cloudsdk/core';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import type { EPResponse } from '@sitecore-cloudsdk/core';
|
|
2
|
+
import type { PageViewData } from './page-view-event';
|
|
3
|
+
import type { Request } from '@sitecore-cloudsdk/utils';
|
|
4
4
|
/**
|
|
5
5
|
* A function that sends a VIEW event to SitecoreCloud API
|
|
6
|
-
*
|
|
6
|
+
*
|
|
7
7
|
* @param request - Interface with constraint for extending request
|
|
8
|
-
* @param
|
|
9
|
-
* This object will be flattened and sent in the ext object of the payload
|
|
8
|
+
* @param pageViewData - The required/optional attributes in order to be send to SitecoreCloud API
|
|
10
9
|
* @returns The response object that Sitecore EP returns
|
|
11
10
|
*/
|
|
12
|
-
export declare function pageViewServer<T extends Request>(
|
|
11
|
+
export declare function pageViewServer<T extends Request>(request: T, pageViewData?: PageViewData): Promise<EPResponse | null>;
|
|
@@ -3,29 +3,27 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.pageViewServer = 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 page_view_event_1 = require("./page-view-event");
|
|
7
8
|
const sendEvent_1 = require("../send-event/sendEvent");
|
|
8
|
-
const consts_1 = require("../../consts");
|
|
9
9
|
/**
|
|
10
10
|
* A function that sends a VIEW event to SitecoreCloud API
|
|
11
|
-
*
|
|
11
|
+
*
|
|
12
12
|
* @param request - Interface with constraint for extending request
|
|
13
|
-
* @param
|
|
14
|
-
* This object will be flattened and sent in the ext object of the payload
|
|
13
|
+
* @param pageViewData - The required/optional attributes in order to be send to SitecoreCloud API
|
|
15
14
|
* @returns The response object that Sitecore EP returns
|
|
16
15
|
*/
|
|
17
|
-
function pageViewServer(
|
|
16
|
+
function pageViewServer(request, pageViewData) {
|
|
18
17
|
const settings = (0, core_1.handleGetSettingsError)(core_1.getSettingsServer, consts_1.ErrorMessages.IE_0005);
|
|
19
|
-
const id = (0, core_1.
|
|
18
|
+
const id = (0, core_1.getCookieValueFromRequest)(request, settings.cookieSettings.cookieNames.browserId);
|
|
20
19
|
// Host is irrelevant but necessary to support relative URL
|
|
21
20
|
const requestUrl = new URL(request.url, `https://localhost`);
|
|
22
21
|
return new page_view_event_1.PageViewEvent({
|
|
23
|
-
eventData,
|
|
24
|
-
extensionData,
|
|
25
22
|
id,
|
|
23
|
+
pageViewData,
|
|
26
24
|
searchParams: requestUrl.search,
|
|
27
25
|
sendEvent: sendEvent_1.sendEvent,
|
|
28
|
-
settings
|
|
26
|
+
settings
|
|
29
27
|
}).send();
|
|
30
28
|
}
|
|
31
29
|
exports.pageViewServer = pageViewServer;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { EPResponse } from '@sitecore-cloudsdk/core';
|
|
2
|
-
import {
|
|
3
|
-
import { PageViewEventInput } from './page-view-event';
|
|
1
|
+
import type { EPResponse } from '@sitecore-cloudsdk/core';
|
|
2
|
+
import type { PageViewData } from './page-view-event';
|
|
4
3
|
/**
|
|
5
4
|
* A function that sends a VIEW event to SitecoreCloud API
|
|
6
|
-
*
|
|
7
|
-
* @param
|
|
5
|
+
*
|
|
6
|
+
* @param pageViewData - The optional attributes in order to be send to SitecoreCloud API
|
|
8
7
|
* This object will be flattened and sent in the ext object of the payload
|
|
9
8
|
* @returns The response object that Sitecore EP returns
|
|
10
9
|
*/
|
|
11
|
-
export declare function pageView(
|
|
10
|
+
export declare function pageView(pageViewData?: PageViewData): Promise<EPResponse | null>;
|
|
@@ -3,28 +3,27 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.pageView = 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 page_view_event_1 = require("./page-view-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 a VIEW event to SitecoreCloud API
|
|
12
|
-
*
|
|
13
|
-
* @param
|
|
12
|
+
*
|
|
13
|
+
* @param pageViewData - The optional attributes in order to be send to SitecoreCloud API
|
|
14
14
|
* This object will be flattened and sent in the ext object of the payload
|
|
15
15
|
* @returns The response object that Sitecore EP returns
|
|
16
16
|
*/
|
|
17
|
-
async function pageView(
|
|
17
|
+
async function pageView(pageViewData) {
|
|
18
18
|
await (0, initializer_1.awaitInit)();
|
|
19
19
|
const settings = (0, core_1.handleGetSettingsError)(core_1.getSettings, consts_1.ErrorMessages.IE_0004);
|
|
20
20
|
const id = (0, core_1.getBrowserId)();
|
|
21
21
|
return new page_view_event_1.PageViewEvent({
|
|
22
|
-
eventData,
|
|
23
|
-
extensionData,
|
|
24
22
|
id,
|
|
23
|
+
pageViewData,
|
|
25
24
|
searchParams: window.location.search,
|
|
26
25
|
sendEvent: sendEvent_1.sendEvent,
|
|
27
|
-
settings
|
|
26
|
+
settings
|
|
28
27
|
}).send();
|
|
29
28
|
}
|
|
30
29
|
exports.pageView = pageView;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type {
|
|
1
|
+
import type { BasePayload, CustomEventPayload, IdentityEventPayload, PageViewEventPayload } from '..';
|
|
2
|
+
import type { EPResponse, Settings } from '@sitecore-cloudsdk/core';
|
|
3
3
|
/**
|
|
4
4
|
* This factory function sends an event to Edge Proxy
|
|
5
5
|
* @param body - The event data to send
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
4
|
exports.sendEvent = void 0;
|
|
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
6
|
const consts_1 = require("../../consts");
|
|
7
7
|
/**
|
|
@@ -10,25 +10,30 @@ const consts_1 = require("../../consts");
|
|
|
10
10
|
* @param settings - The global settings
|
|
11
11
|
*/
|
|
12
12
|
async function sendEvent(body, settings) {
|
|
13
|
+
// eslint-disable-next-line max-len
|
|
13
14
|
const eventUrl = `${settings.sitecoreEdgeUrl}/v1/events/${core_1.API_VERSION}/events?sitecoreContextId=${settings.sitecoreEdgeContextId}&siteId=${settings.siteName}`;
|
|
15
|
+
const startTimestamp = Date.now();
|
|
16
|
+
let debugResponse = {};
|
|
14
17
|
const fetchOptions = {
|
|
15
18
|
body: JSON.stringify(body),
|
|
16
19
|
headers: {
|
|
17
|
-
|
|
20
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
18
21
|
'Content-Type': 'application/json',
|
|
19
|
-
|
|
20
|
-
'X-Library-Version': consts_1.LIBRARY_VERSION
|
|
22
|
+
'X-Client-Software-ID': consts_1.X_CLIENT_SOFTWARE_ID,
|
|
23
|
+
'X-Library-Version': consts_1.LIBRARY_VERSION
|
|
24
|
+
/* eslint-enable @typescript-eslint/naming-convention */
|
|
21
25
|
},
|
|
22
|
-
method: 'POST'
|
|
26
|
+
method: 'POST'
|
|
23
27
|
};
|
|
24
28
|
(0, core_1.debug)(consts_1.EVENTS_NAMESPACE)('Events request: %s with options: %O', eventUrl, fetchOptions);
|
|
25
29
|
return await fetch(eventUrl, fetchOptions)
|
|
26
30
|
.then((response) => {
|
|
27
|
-
(0, core_1.
|
|
31
|
+
debugResponse = (0, core_1.processDebugResponse)(consts_1.EVENTS_NAMESPACE, response);
|
|
28
32
|
return response.json();
|
|
29
33
|
})
|
|
30
34
|
.then((data) => {
|
|
31
|
-
|
|
35
|
+
debugResponse.body = data;
|
|
36
|
+
(0, core_1.debug)(consts_1.EVENTS_NAMESPACE)('Events response in %dms : %O', Date.now() - startTimestamp, debugResponse);
|
|
32
37
|
return data;
|
|
33
38
|
})
|
|
34
39
|
.catch((error) => {
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getGuestId = void 0;
|
|
4
4
|
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
|
|
5
|
+
const core_1 = require("@sitecore-cloudsdk/core");
|
|
5
6
|
const consts_1 = require("../consts");
|
|
6
7
|
const initializer_1 = require("../initializer/browser/initializer");
|
|
7
|
-
const core_1 = require("@sitecore-cloudsdk/core");
|
|
8
8
|
/**
|
|
9
9
|
* A function that returns the guest id.
|
|
10
10
|
* @returns - A promise that resolves with the guest id
|
|
@@ -1,11 +1,23 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { BrowserSettings } from '@sitecore-cloudsdk/core';
|
|
2
2
|
export declare let initPromise: Promise<void> | null;
|
|
3
|
+
declare global {
|
|
4
|
+
interface Window {
|
|
5
|
+
Engage: {
|
|
6
|
+
[x: string]: any;
|
|
7
|
+
getBrowserId?: () => string;
|
|
8
|
+
versions?: {
|
|
9
|
+
personalize?: string;
|
|
10
|
+
events?: string;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
}
|
|
3
15
|
/**
|
|
4
16
|
* Initiates the Events library using the global settings added by the developer
|
|
5
|
-
* @param
|
|
17
|
+
* @param settings - Global settings added by the developer
|
|
6
18
|
* @returns A promise that resolves with an object that handles the library functionality
|
|
7
19
|
*/
|
|
8
|
-
export declare function init(
|
|
20
|
+
export declare function init(settings: BrowserSettings): Promise<void>;
|
|
9
21
|
/**
|
|
10
22
|
* A function that handles the async browser init logic. Throws an error or awaits the promise.
|
|
11
23
|
*/
|