@adobe/spacecat-shared-rum-api-client 2.38.7 → 2.38.8
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/CHANGELOG.md +7 -0
- package/package.json +1 -1
- package/src/common/traffic.js +65 -29
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
# [@adobe/spacecat-shared-rum-api-client-v2.38.8](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-rum-api-client-v2.38.7...@adobe/spacecat-shared-rum-api-client-v2.38.8) (2025-10-31)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **traffic-attribution:** limit vendors per source ([#1079](https://github.com/adobe/spacecat-shared/issues/1079)) ([9165913](https://github.com/adobe/spacecat-shared/commit/9165913f379a00df409fe86961ba5df1f5a2a840))
|
|
7
|
+
|
|
1
8
|
# [@adobe/spacecat-shared-rum-api-client-v2.38.7](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-rum-api-client-v2.38.6...@adobe/spacecat-shared-rum-api-client-v2.38.7) (2025-10-29)
|
|
2
9
|
|
|
3
10
|
|
package/package.json
CHANGED
package/src/common/traffic.js
CHANGED
|
@@ -146,27 +146,61 @@ const not = (truth) => (text) => {
|
|
|
146
146
|
|
|
147
147
|
const notEmpty = (text) => hasText(text);
|
|
148
148
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
149
|
+
// overrides
|
|
150
|
+
const OVERRIDES = [
|
|
151
|
+
{ when: (ctx) => (ctx.utmSource || '').toLowerCase() === 'chatgpt.com', set: { type: 'earned', category: 'llm', vendor: 'openai' } },
|
|
152
|
+
];
|
|
152
153
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
{
|
|
156
|
-
|
|
157
|
-
|
|
154
|
+
function applyOverrides(classification, context) {
|
|
155
|
+
const override = OVERRIDES.find((rule) => rule.when(context));
|
|
156
|
+
return override ? { ...classification, ...override.set } : classification;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// allowed known vendors per category
|
|
160
|
+
const ALLOWED_VENDORS = {
|
|
161
|
+
earned: {
|
|
162
|
+
llm: ['openai', 'claude', 'perplexity', 'microsoft', 'google'],
|
|
163
|
+
search: ['google', 'bing', 'yahoo', 'yandex', 'baidu', 'duckduckgo', 'brave', 'ecosia', 'aol'],
|
|
164
|
+
social: null, // any vendor allowed
|
|
165
|
+
video: ['youtube', 'vimeo', 'twitch', 'tiktok', 'dailymotion'],
|
|
166
|
+
referral: null, // any vendor allowed
|
|
158
167
|
},
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
168
|
+
paid: {
|
|
169
|
+
search: ['google', 'bing', 'yahoo', 'yandex', 'baidu', 'microsoft'],
|
|
170
|
+
social: null, // any vendor allowed
|
|
171
|
+
video: ['youtube', 'vimeo', 'twitch', 'dailymotion'],
|
|
172
|
+
display: null, // any vendor allowed
|
|
173
|
+
affiliate: null, // any vendor allowed
|
|
174
|
+
uncategorized: null, // any vendor allowed
|
|
163
175
|
},
|
|
164
|
-
|
|
176
|
+
owned: {
|
|
177
|
+
direct: ['direct'],
|
|
178
|
+
internal: null, // any vendor allowed
|
|
179
|
+
email: null, // any vendor allowed
|
|
180
|
+
sms: null, // any vendor allowed
|
|
181
|
+
qr: null, // any vendor allowed
|
|
182
|
+
push: null, // any vendor allowed
|
|
183
|
+
uncategorized: null, // any vendor allowed
|
|
184
|
+
},
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Validates if a vendor is allowed for the given type/category combination.
|
|
189
|
+
* @param {string} type - Traffic type (earned, paid, owned)
|
|
190
|
+
* @param {string} category - Traffic category (llm, search, social, etc.)
|
|
191
|
+
* @param {string} vendor - Vendor name to validate
|
|
192
|
+
* @returns {string} The vendor if allowed, empty string otherwise
|
|
193
|
+
*/
|
|
194
|
+
function validateVendor(type, category, vendor) {
|
|
195
|
+
if (!vendor) return '';
|
|
165
196
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
197
|
+
const allowedVendors = ALLOWED_VENDORS[type]?.[category];
|
|
198
|
+
|
|
199
|
+
// null/undefined means any vendor is allowed
|
|
200
|
+
if (!allowedVendors) return vendor;
|
|
201
|
+
|
|
202
|
+
// Check if vendor is in the allowed list
|
|
203
|
+
return allowedVendors.includes(vendor) ? vendor : '';
|
|
170
204
|
}
|
|
171
205
|
|
|
172
206
|
/*
|
|
@@ -283,23 +317,25 @@ export function classifyTrafficSource(url, referrer, utmSource, utmMedium, track
|
|
|
283
317
|
&& rule.utmMedium(sanitize(utmMedium))
|
|
284
318
|
&& rule.tracking(trackingParams)
|
|
285
319
|
));
|
|
286
|
-
|
|
287
|
-
|
|
320
|
+
let { type, category } = match;
|
|
321
|
+
let vendor = classifyVendor(referrerDomain, utmSource, utmMedium);
|
|
288
322
|
|
|
289
|
-
|
|
323
|
+
// apply overrides
|
|
324
|
+
const overridden = applyOverrides(
|
|
290
325
|
{ type, category, vendor },
|
|
291
|
-
{
|
|
292
|
-
utmSourceRaw: utmSource,
|
|
293
|
-
utmSource: sanitize(utmSource),
|
|
294
|
-
utmMedium: sanitize(utmMedium),
|
|
295
|
-
referrerDomain,
|
|
296
|
-
},
|
|
326
|
+
{ utmSource, utmMedium, referrerDomain },
|
|
297
327
|
);
|
|
328
|
+
type = overridden.type;
|
|
329
|
+
category = overridden.category;
|
|
330
|
+
vendor = overridden.vendor;
|
|
331
|
+
|
|
332
|
+
// validate vendor against allowed vendors for this type/category
|
|
333
|
+
const validatedVendor = validateVendor(type, category, vendor);
|
|
298
334
|
|
|
299
335
|
return {
|
|
300
|
-
type
|
|
301
|
-
category
|
|
302
|
-
vendor:
|
|
336
|
+
type,
|
|
337
|
+
category,
|
|
338
|
+
vendor: validatedVendor,
|
|
303
339
|
};
|
|
304
340
|
}
|
|
305
341
|
|