mkfashion-sdk 2.7.0 → 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.
Binary file
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mkfashion-sdk",
3
- "version": "2.7.0",
3
+ "version": "2.7.2",
4
4
  "description": "SDK para integrar o provador virtual mKFashion com suporte a Wake Commerce e tracking analytics completo",
5
5
  "main": "src/mkfashion.js",
6
6
  "scripts": {
package/src/mkfashion.js CHANGED
@@ -305,12 +305,17 @@ const mkfashion = {
305
305
  this._log('Disponibilidade recebida', data)
306
306
 
307
307
  // NOTA: availability check é decisão interna (mostra botão ou não) e
308
- // NÃO é emitido pro collector — não traz valor analítico. O sinal de
309
- // "impressão" vem do auto-tracking (page_view), e o sinal de "produto
310
- // tem try-on" vem do page_button_rendered no init().
311
- // Apenas inicializa _config pra que o auto-tracking saiba quem é o projeto.
308
+ // NÃO emite evento pro collector — não traz valor analítico.
309
+ //
310
+ // MAS é o gatilho mais comum em PDPs: a partir daqui temos projectId
311
+ // confirmado e ativamos o auto-tracking (page_view, click, scroll,
312
+ // form, engagement). Sem isso, páginas onde o usuário só visualiza
313
+ // (sem clicar no try-on) ficariam invisíveis no collector.
312
314
  try {
313
315
  if (!this._config) this._config = { projectId: resolved, identifier }
316
+ if (!this._autoTrackInitialized && this.autoTrack !== false) {
317
+ this._initAutoTrack()
318
+ }
314
319
  } catch (_) {}
315
320
 
316
321
  return data
@@ -453,10 +458,17 @@ const mkfashion = {
453
458
  String(projectId).toLowerCase() === 'gregory'
454
459
  },
455
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
+
456
465
  _triggerCallback(name, data = null) {
457
- // Emite pro collector ANTES do callback do cliente (não bloqueia, fire-and-forget).
458
- try { this._emitToCollector(name, data) } catch (_) {}
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
+ }
459
470
 
471
+ // Callback do cliente recebe data ORIGINAL (sem sanitização — pra imagens etc).
460
472
  if (this._callbacks && typeof this._callbacks[name] === 'function') {
461
473
  try {
462
474
  this._callbacks[name](data)
@@ -467,6 +479,37 @@ const mkfashion = {
467
479
  }
468
480
  },
469
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
+
470
513
  // ============ TRACKING (mk-collector-api) ============
471
514
 
472
515
  _visitorId: null,
@@ -656,15 +699,17 @@ const mkfashion = {
656
699
 
657
700
  /**
658
701
  * Adiciona ao buffer de batch. Flush é disparado por timer ou tamanho.
659
- * 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.
660
704
  */
661
705
  _queueEvent(eventName, data, tsOverride) {
662
706
  this._eventQueue = this._eventQueue || []
707
+ const sanitized = this._sanitizeForCollector(data)
663
708
  const params = { identifier: this._config.identifier || null }
664
- if (data && typeof data === 'object' && !Array.isArray(data)) {
665
- Object.assign(params, data)
666
- } else if (data !== null && data !== undefined) {
667
- params.value = data
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
668
713
  }
669
714
  this._eventQueue.push({
670
715
  name: 'page_' + this._normalizeEventName(eventName),