mkfashion-sdk 2.7.1 → 2.7.2
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/mkfashion-sdk-2.7.2.tgz +0 -0
- package/package.json +1 -1
- package/src/mkfashion.js +47 -7
|
Binary file
|
package/package.json
CHANGED
package/src/mkfashion.js
CHANGED
|
@@ -458,10 +458,17 @@ const mkfashion = {
|
|
|
458
458
|
String(projectId).toLowerCase() === 'gregory'
|
|
459
459
|
},
|
|
460
460
|
|
|
461
|
+
// Eventos que NÃO devem virar evento analítico no collector — geralmente
|
|
462
|
+
// redundantes ou de baixo valor. O callback do cliente segue funcionando.
|
|
463
|
+
_skipCollectorEvents: ['onReady'],
|
|
464
|
+
|
|
461
465
|
_triggerCallback(name, data = null) {
|
|
462
|
-
// Emite pro collector ANTES do callback do cliente
|
|
463
|
-
|
|
466
|
+
// Emite pro collector ANTES do callback do cliente, mas pula os bloqueados.
|
|
467
|
+
if (!this._skipCollectorEvents || this._skipCollectorEvents.indexOf(name) === -1) {
|
|
468
|
+
try { this._emitToCollector(name, data) } catch (_) {}
|
|
469
|
+
}
|
|
464
470
|
|
|
471
|
+
// Callback do cliente recebe data ORIGINAL (sem sanitização — pra imagens etc).
|
|
465
472
|
if (this._callbacks && typeof this._callbacks[name] === 'function') {
|
|
466
473
|
try {
|
|
467
474
|
this._callbacks[name](data)
|
|
@@ -472,6 +479,37 @@ const mkfashion = {
|
|
|
472
479
|
}
|
|
473
480
|
},
|
|
474
481
|
|
|
482
|
+
/**
|
|
483
|
+
* Remove campos pesados/inúteis pro collector mantendo o data original
|
|
484
|
+
* intacto pro callback do cliente. Aplicado em todo evento que vai pro
|
|
485
|
+
* /v1/track/sdk.
|
|
486
|
+
*
|
|
487
|
+
* Regras:
|
|
488
|
+
* - Campos de imagem (imageUrl/image/thumbnail/photo) viram <key>Present: boolean
|
|
489
|
+
* - Strings > 2KB são truncadas com sufixo informativo
|
|
490
|
+
* - Objetos são percorridos rasamente (1 nível) — campos aninhados são preservados
|
|
491
|
+
*/
|
|
492
|
+
_sanitizeForCollector(data) {
|
|
493
|
+
if (!data || typeof data !== 'object' || Array.isArray(data)) return data
|
|
494
|
+
const HEAVY_KEYS = { imageUrl: 1, image: 1, thumbnail: 1, photo: 1, imageBase64: 1 }
|
|
495
|
+
const MAX_STRING_LEN = 2000
|
|
496
|
+
const out = {}
|
|
497
|
+
for (const k in data) {
|
|
498
|
+
if (!Object.prototype.hasOwnProperty.call(data, k)) continue
|
|
499
|
+
const v = data[k]
|
|
500
|
+
if (HEAVY_KEYS[k]) {
|
|
501
|
+
out[k + 'Present'] = !!v
|
|
502
|
+
continue
|
|
503
|
+
}
|
|
504
|
+
if (typeof v === 'string' && v.length > MAX_STRING_LEN) {
|
|
505
|
+
out[k] = v.slice(0, 200) + '...[truncated ' + v.length + 'B]'
|
|
506
|
+
continue
|
|
507
|
+
}
|
|
508
|
+
out[k] = v
|
|
509
|
+
}
|
|
510
|
+
return out
|
|
511
|
+
},
|
|
512
|
+
|
|
475
513
|
// ============ TRACKING (mk-collector-api) ============
|
|
476
514
|
|
|
477
515
|
_visitorId: null,
|
|
@@ -661,15 +699,17 @@ const mkfashion = {
|
|
|
661
699
|
|
|
662
700
|
/**
|
|
663
701
|
* Adiciona ao buffer de batch. Flush é disparado por timer ou tamanho.
|
|
664
|
-
* Todos os eventos recebem prefixo 'page_'.
|
|
702
|
+
* Todos os eventos recebem prefixo 'page_'. Aplica _sanitizeForCollector
|
|
703
|
+
* pra remover campos pesados (imageUrl etc) antes de enviar.
|
|
665
704
|
*/
|
|
666
705
|
_queueEvent(eventName, data, tsOverride) {
|
|
667
706
|
this._eventQueue = this._eventQueue || []
|
|
707
|
+
const sanitized = this._sanitizeForCollector(data)
|
|
668
708
|
const params = { identifier: this._config.identifier || null }
|
|
669
|
-
if (
|
|
670
|
-
Object.assign(params,
|
|
671
|
-
} else if (
|
|
672
|
-
params.value =
|
|
709
|
+
if (sanitized && typeof sanitized === 'object' && !Array.isArray(sanitized)) {
|
|
710
|
+
Object.assign(params, sanitized)
|
|
711
|
+
} else if (sanitized !== null && sanitized !== undefined) {
|
|
712
|
+
params.value = sanitized
|
|
673
713
|
}
|
|
674
714
|
this._eventQueue.push({
|
|
675
715
|
name: 'page_' + this._normalizeEventName(eventName),
|