@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,137 @@
|
|
|
1
|
+
import logger from 'loglevel';
|
|
2
|
+
import { parsePulseCookies } from '../cis-sync';
|
|
3
|
+
import * as identity from '../identity';
|
|
4
|
+
import { SDK_VERSION } from '../version';
|
|
5
|
+
import { mapPageToPageRef } from '../wrapper/utils/map-page-to-page-ref';
|
|
6
|
+
import { adaptActorToNewFormat, adaptConsentsToNewFormat, adaptExperiments } from './adapters';
|
|
7
|
+
import { captureBrowserContext } from './browser';
|
|
8
|
+
import { resolveSession } from './session';
|
|
9
|
+
// This looks overkill, but a mapping feels safer than doing string operations (capitalize) with javascript
|
|
10
|
+
const mapDeployStageToTpaasStage = (deployStage) => {
|
|
11
|
+
switch (deployStage) {
|
|
12
|
+
case 'dev':
|
|
13
|
+
return 'Dev';
|
|
14
|
+
case 'pre':
|
|
15
|
+
return 'Pre';
|
|
16
|
+
case 'pro':
|
|
17
|
+
return 'Pro';
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* The context fields derived from the tracker state, shared by all TPaaS events.
|
|
22
|
+
*/
|
|
23
|
+
const getStateContext = (state) => ({
|
|
24
|
+
version: SDK_VERSION,
|
|
25
|
+
isHybrid: !!state.isHybrid,
|
|
26
|
+
pageviewId: state.pageViewId,
|
|
27
|
+
providerId: state.providerId,
|
|
28
|
+
providerName: state.provider?.name,
|
|
29
|
+
providerGroup: state.provider?.group,
|
|
30
|
+
providerStage: state.stage,
|
|
31
|
+
providerProduct: state.product,
|
|
32
|
+
providerVersion: state.version,
|
|
33
|
+
component: state.component,
|
|
34
|
+
componentVersion: state.componentVersion,
|
|
35
|
+
routingStage: mapDeployStageToTpaasStage(state.deployStageTpaas),
|
|
36
|
+
});
|
|
37
|
+
/**
|
|
38
|
+
* Deep copies the tracking input, so a caller that reuses and changes the same input object afterwards
|
|
39
|
+
* cannot change an event that is still being prepared. When the input cannot be copied, it is used as it is.
|
|
40
|
+
*/
|
|
41
|
+
const copyInput = (input) => {
|
|
42
|
+
try {
|
|
43
|
+
return structuredClone(input);
|
|
44
|
+
}
|
|
45
|
+
catch (ex) {
|
|
46
|
+
// older browsers, or inputs with values that cannot be cloned (functions, Promises, framework proxies)
|
|
47
|
+
logger.debug('Could not copy the tracking input, using it as is', ex);
|
|
48
|
+
return input;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
const getPageRef = async (pageInfo) => {
|
|
52
|
+
const { id, type, url } = await pageInfo;
|
|
53
|
+
return mapPageToPageRef(id, type, url);
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Resolves the context of an anonymous TPaaS event.
|
|
57
|
+
* Callers specify the event schema because it cannot be inferred from `InputParams<I>`.
|
|
58
|
+
*
|
|
59
|
+
* @private
|
|
60
|
+
*/
|
|
61
|
+
export async function prepareAnonymousTpaasEventContext(source, input) {
|
|
62
|
+
// Read everything before any asynchronous work, so the context reflects the moment the event
|
|
63
|
+
// was tracked and a later update or View event cannot change it.
|
|
64
|
+
const createdAt = new Date();
|
|
65
|
+
const eventInput = copyInput(input);
|
|
66
|
+
const browser = captureBrowserContext();
|
|
67
|
+
const stateContext = getStateContext(source.state);
|
|
68
|
+
const experiments = source.builders.experiments;
|
|
69
|
+
const { referrer } = source.currentPage;
|
|
70
|
+
try {
|
|
71
|
+
await source.applyRemoteConfig();
|
|
72
|
+
}
|
|
73
|
+
catch (ex) {
|
|
74
|
+
logger.trace('Failed to sync remote config', ex);
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
input: eventInput,
|
|
78
|
+
createdAt,
|
|
79
|
+
browser,
|
|
80
|
+
...stateContext,
|
|
81
|
+
experiments: adaptExperiments(experiments),
|
|
82
|
+
currentPageReferrer: await referrer,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Resolves the context of a TPaaS event.
|
|
87
|
+
* Callers specify the event schema because it cannot be inferred from `InputParams<I>`.
|
|
88
|
+
*
|
|
89
|
+
* @private
|
|
90
|
+
*/
|
|
91
|
+
export async function prepareTpaasEventContext(source, input) {
|
|
92
|
+
// Read everything before any asynchronous work, so the context reflects the moment the event
|
|
93
|
+
// was tracked and a later update or View event cannot change it.
|
|
94
|
+
// The session is resolved here too, so sessions are updated in the order events are tracked.
|
|
95
|
+
const createdAt = new Date();
|
|
96
|
+
const eventInput = copyInput(input);
|
|
97
|
+
const session = resolveSession(createdAt);
|
|
98
|
+
const browser = captureBrowserContext();
|
|
99
|
+
const stateContext = getStateContext(source.state);
|
|
100
|
+
const builders = { ...source.builders };
|
|
101
|
+
const { info, content, sports, referrer } = source.currentPage;
|
|
102
|
+
// Session listeners run synchronously and may update the tracker or start another View.
|
|
103
|
+
// Notify them only after this event's context has been captured.
|
|
104
|
+
source.onSessionResolved();
|
|
105
|
+
try {
|
|
106
|
+
await source.syncRemoteResources(builders);
|
|
107
|
+
}
|
|
108
|
+
catch (ex) {
|
|
109
|
+
logger.trace('Failed to sync remote resources', ex);
|
|
110
|
+
// remote config and CIS failures are also ignored for the old track() method. doing the same here
|
|
111
|
+
}
|
|
112
|
+
// Consents are intentionally not read upfront. Read them after remote synchronization
|
|
113
|
+
// so a blocking tracking call can use newly resolved consents.
|
|
114
|
+
const [actor, consents, currentPage, currentPageReferrer] = await Promise.all([
|
|
115
|
+
identity.getActor(builders),
|
|
116
|
+
source.getConsents(),
|
|
117
|
+
getPageRef(info),
|
|
118
|
+
referrer,
|
|
119
|
+
]);
|
|
120
|
+
const { environmentId, jwe } = parsePulseCookies();
|
|
121
|
+
return {
|
|
122
|
+
input: eventInput,
|
|
123
|
+
createdAt,
|
|
124
|
+
session,
|
|
125
|
+
browser,
|
|
126
|
+
...stateContext,
|
|
127
|
+
user: adaptActorToNewFormat(actor),
|
|
128
|
+
consents: adaptConsentsToNewFormat(consents),
|
|
129
|
+
experiments: adaptExperiments(builders.experiments),
|
|
130
|
+
currentPage,
|
|
131
|
+
currentPageContent: content,
|
|
132
|
+
currentPageSports: sports,
|
|
133
|
+
currentPageReferrer,
|
|
134
|
+
environmentId,
|
|
135
|
+
jwe,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { touchSession } from '../session/store';
|
|
2
|
+
import { getXDomainId } from '../utils';
|
|
3
|
+
/**
|
|
4
|
+
* Registers an event created at `createdAt` in the stored session and returns it in the TPaaS format.
|
|
5
|
+
*
|
|
6
|
+
* Call it synchronously, together with capturing `createdAt`, before any asynchronous work.
|
|
7
|
+
* Sessions are then updated in the order events are tracked, which is also their creation order.
|
|
8
|
+
*
|
|
9
|
+
* @private
|
|
10
|
+
*/
|
|
11
|
+
export const resolveSession = (createdAt) => {
|
|
12
|
+
const { sessionId, startTime, isFirstEvent } = touchSession(createdAt);
|
|
13
|
+
return {
|
|
14
|
+
isFirstEvent,
|
|
15
|
+
sessionId,
|
|
16
|
+
startTime: startTime.toISOString(),
|
|
17
|
+
xDomainId: getXDomainId(),
|
|
18
|
+
};
|
|
19
|
+
};
|