@schibsted/pulse-sdk 8.0.0-rc.20 → 8.0.0-rc.21
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/Tracker.js +170 -334
- package/dist/cjs/builders/session-browser.js +4 -79
- package/dist/cjs/session/store.js +96 -0
- package/dist/cjs/tpaas-builders/builders/device.js +42 -70
- package/dist/cjs/tpaas-builders/builders/pageInfo.js +2 -3
- package/dist/cjs/tpaas-builders/builders/session.js +2 -114
- package/dist/cjs/tpaas-builders/builders/utm.js +2 -8
- package/dist/cjs/tpaas-builders/builders.js +135 -148
- package/dist/cjs/tpaas-context/adapters.js +85 -0
- package/dist/cjs/tpaas-context/browser.js +51 -0
- package/dist/cjs/tpaas-context/index.js +6 -0
- package/dist/cjs/tpaas-context/prepare.js +177 -0
- package/dist/cjs/tpaas-context/session.js +23 -0
- package/dist/cjs/tpaas-schemas/constants.js +68 -75
- package/dist/cjs/tracker-proxy/consts.js +1 -2
- package/dist/cjs/version.js +1 -1
- package/dist/ejs/Tracker.js +171 -335
- package/dist/ejs/builders/session-browser.js +4 -77
- package/dist/ejs/session/store.js +90 -0
- package/dist/ejs/tpaas-builders/builders/device.js +42 -70
- package/dist/ejs/tpaas-builders/builders/pageInfo.js +2 -3
- package/dist/ejs/tpaas-builders/builders/session.js +1 -111
- package/dist/ejs/tpaas-builders/builders/utm.js +2 -8
- package/dist/ejs/tpaas-builders/builders.js +135 -147
- package/dist/ejs/tpaas-context/adapters.js +80 -0
- package/dist/ejs/tpaas-context/browser.js +47 -0
- package/dist/ejs/tpaas-context/index.js +1 -0
- package/dist/ejs/tpaas-context/prepare.js +137 -0
- package/dist/ejs/tpaas-context/session.js +19 -0
- package/dist/ejs/tpaas-schemas/constants.js +66 -73
- package/dist/ejs/tracker-proxy/consts.js +1 -2
- package/dist/ejs/version.js +1 -1
- package/dist/types/Tracker.d.ts +27 -23
- package/dist/types/builders/session-browser.d.ts +0 -13
- package/dist/types/session/store.d.ts +34 -0
- package/dist/types/tpaas-builders/builders/consents.d.ts +2 -2
- package/dist/types/tpaas-builders/builders/device.d.ts +2 -2
- package/dist/types/tpaas-builders/builders/experiments.d.ts +2 -2
- package/dist/types/tpaas-builders/builders/pageInfo.d.ts +2 -1
- package/dist/types/tpaas-builders/builders/pageviewId.d.ts +2 -2
- package/dist/types/tpaas-builders/builders/provider.d.ts +2 -2
- package/dist/types/tpaas-builders/builders/session.d.ts +1 -12
- package/dist/types/tpaas-builders/builders/trackerBuilder.d.ts +2 -2
- package/dist/types/tpaas-builders/builders/user.d.ts +2 -2
- package/dist/types/tpaas-builders/builders/utm.d.ts +2 -1
- package/dist/types/tpaas-builders/builders.d.ts +70 -70
- package/dist/types/tpaas-builders/index.d.ts +0 -1
- package/dist/types/tpaas-context/adapters.d.ts +26 -0
- package/dist/types/tpaas-context/browser.d.ts +8 -0
- package/dist/types/tpaas-context/index.d.ts +2 -0
- package/dist/types/tpaas-context/prepare.d.ts +38 -0
- package/dist/types/tpaas-context/session.d.ts +10 -0
- package/dist/types/tpaas-context/types.d.ts +66 -0
- package/dist/types/tpaas-schemas/constants.d.ts +66 -73
- package/dist/types/tpaas-schemas/types/ITpaasEvent.d.ts +2 -4
- package/dist/types/tpaas-schemas/types/schemas/{IAnonymousViewUIElement.d.ts → IAnonymousImpressionUIElement.d.ts} +2 -2
- package/dist/types/tpaas-schemas/types/schemas/IEngagementAudio.d.ts +6 -2
- package/dist/types/tpaas-schemas/types/schemas/IEngagementTeaser.d.ts +2 -2
- package/dist/types/tpaas-schemas/types/schemas/IEngagementTvModule.d.ts +4 -1
- package/dist/types/tpaas-schemas/types/schemas/IEngagementTvSearch.d.ts +4 -4
- package/dist/types/tpaas-schemas/types/schemas/IEngagementVideo.d.ts +6 -2
- package/dist/types/tpaas-schemas/types/schemas/IEngagementVideoAd.d.ts +10 -8
- package/dist/types/tpaas-schemas/types/schemas/IImpressionTeaser.d.ts +2 -2
- package/dist/types/tpaas-schemas/types/schemas/ILeaveWeather.d.ts +2 -0
- package/dist/types/tpaas-schemas/types/schemas/index.d.ts +1 -2
- package/dist/types/tpaas-schemas/types.d.ts +2 -2
- package/dist/types/tracker-proxy/consts.d.ts +1 -1
- package/dist/types/types.d.ts +2 -4
- package/dist/types/version.d.ts +1 -1
- package/package.json +1 -1
- package/dist/types/tpaas-builders/types.d.ts +0 -36
- package/dist/types/tpaas-schemas/types/schemas/IRequestAd.d.ts +0 -95
- /package/dist/cjs/{tpaas-builders → tpaas-context}/types.js +0 -0
- /package/dist/ejs/{tpaas-builders → tpaas-context}/types.js +0 -0
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.prepareAnonymousTpaasEventContext = prepareAnonymousTpaasEventContext;
|
|
40
|
+
exports.prepareTpaasEventContext = prepareTpaasEventContext;
|
|
41
|
+
const loglevel_1 = __importDefault(require("loglevel"));
|
|
42
|
+
const cis_sync_1 = require("../cis-sync");
|
|
43
|
+
const identity = __importStar(require("../identity"));
|
|
44
|
+
const version_1 = require("../version");
|
|
45
|
+
const map_page_to_page_ref_1 = require("../wrapper/utils/map-page-to-page-ref");
|
|
46
|
+
const adapters_1 = require("./adapters");
|
|
47
|
+
const browser_1 = require("./browser");
|
|
48
|
+
const session_1 = require("./session");
|
|
49
|
+
// This looks overkill, but a mapping feels safer than doing string operations (capitalize) with javascript
|
|
50
|
+
const mapDeployStageToTpaasStage = (deployStage) => {
|
|
51
|
+
switch (deployStage) {
|
|
52
|
+
case 'dev':
|
|
53
|
+
return 'Dev';
|
|
54
|
+
case 'pre':
|
|
55
|
+
return 'Pre';
|
|
56
|
+
case 'pro':
|
|
57
|
+
return 'Pro';
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* The context fields derived from the tracker state, shared by all TPaaS events.
|
|
62
|
+
*/
|
|
63
|
+
const getStateContext = (state) => ({
|
|
64
|
+
version: version_1.SDK_VERSION,
|
|
65
|
+
isHybrid: !!state.isHybrid,
|
|
66
|
+
pageviewId: state.pageViewId,
|
|
67
|
+
providerId: state.providerId,
|
|
68
|
+
providerName: state.provider?.name,
|
|
69
|
+
providerGroup: state.provider?.group,
|
|
70
|
+
providerStage: state.stage,
|
|
71
|
+
providerProduct: state.product,
|
|
72
|
+
providerVersion: state.version,
|
|
73
|
+
component: state.component,
|
|
74
|
+
componentVersion: state.componentVersion,
|
|
75
|
+
routingStage: mapDeployStageToTpaasStage(state.deployStageTpaas),
|
|
76
|
+
});
|
|
77
|
+
/**
|
|
78
|
+
* Deep copies the tracking input, so a caller that reuses and changes the same input object afterwards
|
|
79
|
+
* cannot change an event that is still being prepared. When the input cannot be copied, it is used as it is.
|
|
80
|
+
*/
|
|
81
|
+
const copyInput = (input) => {
|
|
82
|
+
try {
|
|
83
|
+
return structuredClone(input);
|
|
84
|
+
}
|
|
85
|
+
catch (ex) {
|
|
86
|
+
// older browsers, or inputs with values that cannot be cloned (functions, Promises, framework proxies)
|
|
87
|
+
loglevel_1.default.debug('Could not copy the tracking input, using it as is', ex);
|
|
88
|
+
return input;
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
const getPageRef = async (pageInfo) => {
|
|
92
|
+
const { id, type, url } = await pageInfo;
|
|
93
|
+
return (0, map_page_to_page_ref_1.mapPageToPageRef)(id, type, url);
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* Resolves the context of an anonymous TPaaS event.
|
|
97
|
+
* Callers specify the event schema because it cannot be inferred from `InputParams<I>`.
|
|
98
|
+
*
|
|
99
|
+
* @private
|
|
100
|
+
*/
|
|
101
|
+
async function prepareAnonymousTpaasEventContext(source, input) {
|
|
102
|
+
// Read everything before any asynchronous work, so the context reflects the moment the event
|
|
103
|
+
// was tracked and a later update or View event cannot change it.
|
|
104
|
+
const createdAt = new Date();
|
|
105
|
+
const eventInput = copyInput(input);
|
|
106
|
+
const browser = (0, browser_1.captureBrowserContext)();
|
|
107
|
+
const stateContext = getStateContext(source.state);
|
|
108
|
+
const experiments = source.builders.experiments;
|
|
109
|
+
const { referrer } = source.currentPage;
|
|
110
|
+
try {
|
|
111
|
+
await source.applyRemoteConfig();
|
|
112
|
+
}
|
|
113
|
+
catch (ex) {
|
|
114
|
+
loglevel_1.default.trace('Failed to sync remote config', ex);
|
|
115
|
+
}
|
|
116
|
+
return {
|
|
117
|
+
input: eventInput,
|
|
118
|
+
createdAt,
|
|
119
|
+
browser,
|
|
120
|
+
...stateContext,
|
|
121
|
+
experiments: (0, adapters_1.adaptExperiments)(experiments),
|
|
122
|
+
currentPageReferrer: await referrer,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Resolves the context of a TPaaS event.
|
|
127
|
+
* Callers specify the event schema because it cannot be inferred from `InputParams<I>`.
|
|
128
|
+
*
|
|
129
|
+
* @private
|
|
130
|
+
*/
|
|
131
|
+
async function prepareTpaasEventContext(source, input) {
|
|
132
|
+
// Read everything before any asynchronous work, so the context reflects the moment the event
|
|
133
|
+
// was tracked and a later update or View event cannot change it.
|
|
134
|
+
// The session is resolved here too, so sessions are updated in the order events are tracked.
|
|
135
|
+
const createdAt = new Date();
|
|
136
|
+
const eventInput = copyInput(input);
|
|
137
|
+
const session = (0, session_1.resolveSession)(createdAt);
|
|
138
|
+
const browser = (0, browser_1.captureBrowserContext)();
|
|
139
|
+
const stateContext = getStateContext(source.state);
|
|
140
|
+
const builders = { ...source.builders };
|
|
141
|
+
const { info, content, sports, referrer } = source.currentPage;
|
|
142
|
+
// Session listeners run synchronously and may update the tracker or start another View.
|
|
143
|
+
// Notify them only after this event's context has been captured.
|
|
144
|
+
source.onSessionResolved();
|
|
145
|
+
try {
|
|
146
|
+
await source.syncRemoteResources(builders);
|
|
147
|
+
}
|
|
148
|
+
catch (ex) {
|
|
149
|
+
loglevel_1.default.trace('Failed to sync remote resources', ex);
|
|
150
|
+
// remote config and CIS failures are also ignored for the old track() method. doing the same here
|
|
151
|
+
}
|
|
152
|
+
// Consents are intentionally not read upfront. Read them after remote synchronization
|
|
153
|
+
// so a blocking tracking call can use newly resolved consents.
|
|
154
|
+
const [actor, consents, currentPage, currentPageReferrer] = await Promise.all([
|
|
155
|
+
identity.getActor(builders),
|
|
156
|
+
source.getConsents(),
|
|
157
|
+
getPageRef(info),
|
|
158
|
+
referrer,
|
|
159
|
+
]);
|
|
160
|
+
const { environmentId, jwe } = (0, cis_sync_1.parsePulseCookies)();
|
|
161
|
+
return {
|
|
162
|
+
input: eventInput,
|
|
163
|
+
createdAt,
|
|
164
|
+
session,
|
|
165
|
+
browser,
|
|
166
|
+
...stateContext,
|
|
167
|
+
user: (0, adapters_1.adaptActorToNewFormat)(actor),
|
|
168
|
+
consents: (0, adapters_1.adaptConsentsToNewFormat)(consents),
|
|
169
|
+
experiments: (0, adapters_1.adaptExperiments)(builders.experiments),
|
|
170
|
+
currentPage,
|
|
171
|
+
currentPageContent: content,
|
|
172
|
+
currentPageSports: sports,
|
|
173
|
+
currentPageReferrer,
|
|
174
|
+
environmentId,
|
|
175
|
+
jwe,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveSession = void 0;
|
|
4
|
+
const store_1 = require("../session/store");
|
|
5
|
+
const utils_1 = require("../utils");
|
|
6
|
+
/**
|
|
7
|
+
* Registers an event created at `createdAt` in the stored session and returns it in the TPaaS format.
|
|
8
|
+
*
|
|
9
|
+
* Call it synchronously, together with capturing `createdAt`, before any asynchronous work.
|
|
10
|
+
* Sessions are then updated in the order events are tracked, which is also their creation order.
|
|
11
|
+
*
|
|
12
|
+
* @private
|
|
13
|
+
*/
|
|
14
|
+
const resolveSession = (createdAt) => {
|
|
15
|
+
const { sessionId, startTime, isFirstEvent } = (0, store_1.touchSession)(createdAt);
|
|
16
|
+
return {
|
|
17
|
+
isFirstEvent,
|
|
18
|
+
sessionId,
|
|
19
|
+
startTime: startTime.toISOString(),
|
|
20
|
+
xDomainId: (0, utils_1.getXDomainId)(),
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
exports.resolveSession = resolveSession;
|