mkfashion-sdk 1.2.2 → 1.2.3
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/.gitattributes +2 -0
- package/package.json +1 -1
- package/src/mkfashion.js +0 -59
package/.gitattributes
ADDED
package/package.json
CHANGED
package/src/mkfashion.js
CHANGED
|
@@ -30,13 +30,6 @@ const mkfashion = {
|
|
|
30
30
|
apiUrl: 'https://mkfashion-api.mk3dlabs.com',
|
|
31
31
|
debug: false,
|
|
32
32
|
|
|
33
|
-
// GA4 Measurement Protocol
|
|
34
|
-
_ga4: {
|
|
35
|
-
measurementId: 'G-LPV8HY4JPQ',
|
|
36
|
-
apiSecret: 'hNzENdMxTcOJTA4COfzEFA',
|
|
37
|
-
clientId: null
|
|
38
|
-
},
|
|
39
|
-
|
|
40
33
|
// Estado interno
|
|
41
34
|
_iframe: null,
|
|
42
35
|
_modal: null,
|
|
@@ -583,11 +576,6 @@ const mkfashion = {
|
|
|
583
576
|
this._triggerCallback('onError', data)
|
|
584
577
|
break
|
|
585
578
|
|
|
586
|
-
case 'analytics_event':
|
|
587
|
-
this._log('Evento analytics', data)
|
|
588
|
-
this._sendToGA4(data.event_name, data.params)
|
|
589
|
-
break
|
|
590
|
-
|
|
591
579
|
default:
|
|
592
580
|
this._log('Acao desconhecida:', action)
|
|
593
581
|
}
|
|
@@ -603,53 +591,6 @@ const mkfashion = {
|
|
|
603
591
|
this._messageHandler = null
|
|
604
592
|
this._log('Listener de mensagens removido')
|
|
605
593
|
}
|
|
606
|
-
},
|
|
607
|
-
|
|
608
|
-
// ============ GA4 MEASUREMENT PROTOCOL ============
|
|
609
|
-
|
|
610
|
-
_getOrCreateClientId() {
|
|
611
|
-
if (this._ga4.clientId) {
|
|
612
|
-
return this._ga4.clientId
|
|
613
|
-
}
|
|
614
|
-
|
|
615
|
-
// Tenta pegar do localStorage
|
|
616
|
-
let clientId = localStorage.getItem('mkfashion_ga4_client_id')
|
|
617
|
-
|
|
618
|
-
if (!clientId) {
|
|
619
|
-
// Gera um novo client_id (formato: timestamp.random)
|
|
620
|
-
clientId = `${Date.now()}.${Math.floor(Math.random() * 1000000000)}`
|
|
621
|
-
localStorage.setItem('mkfashion_ga4_client_id', clientId)
|
|
622
|
-
}
|
|
623
|
-
|
|
624
|
-
this._ga4.clientId = clientId
|
|
625
|
-
return clientId
|
|
626
|
-
},
|
|
627
|
-
|
|
628
|
-
async _sendToGA4(eventName, params = {}) {
|
|
629
|
-
try {
|
|
630
|
-
const url = `https://www.google-analytics.com/mp/collect?measurement_id=${this._ga4.measurementId}&api_secret=${this._ga4.apiSecret}`
|
|
631
|
-
|
|
632
|
-
const payload = {
|
|
633
|
-
client_id: this._getOrCreateClientId(),
|
|
634
|
-
events: [{
|
|
635
|
-
name: eventName,
|
|
636
|
-
params: {
|
|
637
|
-
...params,
|
|
638
|
-
engagement_time_msec: 100
|
|
639
|
-
}
|
|
640
|
-
}]
|
|
641
|
-
}
|
|
642
|
-
|
|
643
|
-
const response = await fetch(url, {
|
|
644
|
-
method: 'POST',
|
|
645
|
-
body: JSON.stringify(payload)
|
|
646
|
-
})
|
|
647
|
-
|
|
648
|
-
this._log('GA4 evento enviado:', eventName, response.status)
|
|
649
|
-
|
|
650
|
-
} catch (error) {
|
|
651
|
-
console.error('[mKFashion] Erro ao enviar para GA4:', error)
|
|
652
|
-
}
|
|
653
594
|
}
|
|
654
595
|
}
|
|
655
596
|
|