@azzas/azzas-tracker-web 1.0.80 → 1.0.81
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/README.md +130 -130
- package/dist/mod.cjs +162 -4
- package/dist/mod.cjs.map +1 -1
- package/dist/mod.d.cts +0 -0
- package/dist/mod.d.ts +0 -0
- package/dist/mod.global.js +162 -4
- package/dist/mod.global.js.map +1 -1
- package/dist/mod.js +162 -4
- package/dist/mod.js.map +1 -1
- package/dist/mod.vtex.global.js +211 -44
- package/package.json +38 -38
package/README.md
CHANGED
|
@@ -1,130 +1,130 @@
|
|
|
1
|
-
# azzas-tracker-web
|
|
2
|
-
|
|
3
|
-
Pacote interno para **Data Tracking** das lojas WEB, centralizando a captura e envio de eventos para diferentes plataformas de mídia (Meta, Dito, DataLayer, etc).
|
|
4
|
-
|
|
5
|
-
O objetivo é fornecer uma **camada única e consistente de tracking**, garantindo que todos os eventos sejam tratados, formatados e enviados de forma confiável.
|
|
6
|
-
|
|
7
|
-
E, principalmente, centralizar a complexidade e a “inteligência” de tracking **fora dos repositórios das lojas**.
|
|
8
|
-
|
|
9
|
-
---
|
|
10
|
-
|
|
11
|
-
## Fluxo do Tracking
|
|
12
|
-
|
|
13
|
-
O pacote segue o seguinte fluxo de eventos:
|
|
14
|
-
|
|
15
|
-
1. **User Action**
|
|
16
|
-
Ações do usuário na loja (ex: adicionar ao carrinho, iniciar checkout, finalizar compra).
|
|
17
|
-
|
|
18
|
-
2. **Tracks**
|
|
19
|
-
Ponto central que recebe o contexto do evento vindo da ação do usuário e encaminha para o *Formatter*.
|
|
20
|
-
|
|
21
|
-
3. **Formatter**
|
|
22
|
-
Acessa a constante `EVENTS` e, baseado no contexto do evento, puxa os parâmetros obrigatórios e entrega a biblioteca de parâmetros (`/params`).
|
|
23
|
-
|
|
24
|
-
4. **Params Library**
|
|
25
|
-
Contém **getters** e **resolvers** que garantem que os dados sejam legítimos e que todos os parâmetros sejam corretamente tratados.
|
|
26
|
-
|
|
27
|
-
5. **Adapters**
|
|
28
|
-
Módulos responsáveis por enviar os dados formatados para cada destino (Meta, Datalayer, Dito, etc).
|
|
29
|
-
|
|
30
|
-

|
|
31
|
-
|
|
32
|
-
## Instalação
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
```bash
|
|
36
|
-
npm install /path/azzas-tracker-web
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
## Exemplos
|
|
41
|
-
|
|
42
|
-
Listagem dos `EVENTS` e função orquestradora `trackWebEvent`:
|
|
43
|
-
```javascript
|
|
44
|
-
const EVENTS = {
|
|
45
|
-
ADD_PERSONAL_INFO: {
|
|
46
|
-
name: 'add_personal_info',
|
|
47
|
-
destinations: ['DataLayer'],
|
|
48
|
-
requiredParams: ['brand', 'pre_filled', 'currency', 'value', 'subtotal'],
|
|
49
|
-
},
|
|
50
|
-
VIEW_CART: {
|
|
51
|
-
name: 'add_personal_info',
|
|
52
|
-
destinations: ['DataLayer', 'Meta', 'Dito'],
|
|
53
|
-
requiredParams: ['....'],
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export async function trackWebEvent(event: EventName, context: EventContext = {}) {
|
|
58
|
-
try {
|
|
59
|
-
const parameters = await getParameters(context, event);
|
|
60
|
-
return await dispatchTrackEvent(event, parameters);
|
|
61
|
-
} catch (err) {
|
|
62
|
-
return console.error(`[DT] Error tracking event ${event}:`, err);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
Uso básico da função no consumidor:
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
```javascript
|
|
71
|
-
import { trackWebEvent } from 'azzas-tracker-web';
|
|
72
|
-
|
|
73
|
-
// DATA TRACKING | add_personal_info at submit (pre-filled always false)
|
|
74
|
-
// @see notion document for more details:
|
|
75
|
-
const form: Element = document.querySelector('xxxxxx');
|
|
76
|
-
if (form) {
|
|
77
|
-
form.addEventListener('submit', () => {
|
|
78
|
-
trackWebEvent('ADD_PERSONAL_INFO', { preFilled: false, orderForm: vtexjs.checkout.orderForm });
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
***OBS***: atente-se ao adicionar eventos novos e contribua na documentação do NOTION ou apenas DOCUMENTE em algum lugar! Seu futuro EU será grato 👍
|
|
84
|
-
|
|
85
|
-
## Teste Local para Ambientes CDN/DENO
|
|
86
|
-
|
|
87
|
-
Para testar alterações na biblioteca localmente, simulando a forma como ela é carregada por uma CDN (<script src="...">), use o script npm run dev:deno.
|
|
88
|
-
|
|
89
|
-
Este comando realiza o build mais recente da biblioteca, empacota-o e inicia um servidor HTTP local usando o Deno para servir o arquivo
|
|
90
|
-
|
|
91
|
-
1. Aqui nesse repositório, rode o script que inicia o servidor local:
|
|
92
|
-
|
|
93
|
-
```bash
|
|
94
|
-
npm run dev:deno
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
O servidor será iniciado e começará a servir o seu arquivo de build no seguinte endereço: http://localhost:4507/.
|
|
98
|
-
|
|
99
|
-
2. No Projeto Consumidor (DENO/FRONT):
|
|
100
|
-
|
|
101
|
-
Altere o link do <script> no seu projeto para apontar para o servidor local.
|
|
102
|
-
|
|
103
|
-
Você deve usar: <script src="http://localhost:4507/dist/mod.global.js"></script>
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
## Boas Práticas
|
|
107
|
-
- Sempre garantir que os `requiredParams` de cada evento estejam preenchidos antes de enviar.
|
|
108
|
-
|
|
109
|
-
- Procure sempre manter o envio das ações de usuário o mais ***genérico*** possível. Toda a inteligência e complexidade do tratamento dos dados deve ficar centralizada na lib, e não nos repositórios das lojas.
|
|
110
|
-
|
|
111
|
-
- Usar nomes de eventos semânticos e consistentes (ex: VIEW_CART, ADD_PAYMENT_INFO).
|
|
112
|
-
|
|
113
|
-
- Manter os contextos enxutos, enviando apenas dados realmente necessários.
|
|
114
|
-
|
|
115
|
-
- Cada novo evento deve ser registrado em `EVENTS` com seus destinos e parâmetros obrigatórios. Essa constante talvez venha a ser dinâmica dependendo da MARCA utilizada
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
## Contribuição
|
|
119
|
-
|
|
120
|
-
- Adicionar novos eventos em `EVENTS`.
|
|
121
|
-
|
|
122
|
-
- Criar adapter correspondente caso seja necessário integrar com nova plataforma. Nesse caso deve-se avaliar qual será o serviço feito, o que será consumido, para onde será enviado.
|
|
123
|
-
|
|
124
|
-
- Garantir que todos os parâmetros obrigatórios estejam mapeados nos getters/resolvers.
|
|
125
|
-
|
|
126
|
-
- Executar build (npm run build) antes de testar no checkout/loja.
|
|
127
|
-
|
|
128
|
-
## Authors
|
|
129
|
-
|
|
130
|
-
- Lucas Soares
|
|
1
|
+
# azzas-tracker-web
|
|
2
|
+
|
|
3
|
+
Pacote interno para **Data Tracking** das lojas WEB, centralizando a captura e envio de eventos para diferentes plataformas de mídia (Meta, Dito, DataLayer, etc).
|
|
4
|
+
|
|
5
|
+
O objetivo é fornecer uma **camada única e consistente de tracking**, garantindo que todos os eventos sejam tratados, formatados e enviados de forma confiável.
|
|
6
|
+
|
|
7
|
+
E, principalmente, centralizar a complexidade e a “inteligência” de tracking **fora dos repositórios das lojas**.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Fluxo do Tracking
|
|
12
|
+
|
|
13
|
+
O pacote segue o seguinte fluxo de eventos:
|
|
14
|
+
|
|
15
|
+
1. **User Action**
|
|
16
|
+
Ações do usuário na loja (ex: adicionar ao carrinho, iniciar checkout, finalizar compra).
|
|
17
|
+
|
|
18
|
+
2. **Tracks**
|
|
19
|
+
Ponto central que recebe o contexto do evento vindo da ação do usuário e encaminha para o *Formatter*.
|
|
20
|
+
|
|
21
|
+
3. **Formatter**
|
|
22
|
+
Acessa a constante `EVENTS` e, baseado no contexto do evento, puxa os parâmetros obrigatórios e entrega a biblioteca de parâmetros (`/params`).
|
|
23
|
+
|
|
24
|
+
4. **Params Library**
|
|
25
|
+
Contém **getters** e **resolvers** que garantem que os dados sejam legítimos e que todos os parâmetros sejam corretamente tratados.
|
|
26
|
+
|
|
27
|
+
5. **Adapters**
|
|
28
|
+
Módulos responsáveis por enviar os dados formatados para cada destino (Meta, Datalayer, Dito, etc).
|
|
29
|
+
|
|
30
|
+

|
|
31
|
+
|
|
32
|
+
## Instalação
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
npm install /path/azzas-tracker-web
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
## Exemplos
|
|
41
|
+
|
|
42
|
+
Listagem dos `EVENTS` e função orquestradora `trackWebEvent`:
|
|
43
|
+
```javascript
|
|
44
|
+
const EVENTS = {
|
|
45
|
+
ADD_PERSONAL_INFO: {
|
|
46
|
+
name: 'add_personal_info',
|
|
47
|
+
destinations: ['DataLayer'],
|
|
48
|
+
requiredParams: ['brand', 'pre_filled', 'currency', 'value', 'subtotal'],
|
|
49
|
+
},
|
|
50
|
+
VIEW_CART: {
|
|
51
|
+
name: 'add_personal_info',
|
|
52
|
+
destinations: ['DataLayer', 'Meta', 'Dito'],
|
|
53
|
+
requiredParams: ['....'],
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export async function trackWebEvent(event: EventName, context: EventContext = {}) {
|
|
58
|
+
try {
|
|
59
|
+
const parameters = await getParameters(context, event);
|
|
60
|
+
return await dispatchTrackEvent(event, parameters);
|
|
61
|
+
} catch (err) {
|
|
62
|
+
return console.error(`[DT] Error tracking event ${event}:`, err);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Uso básico da função no consumidor:
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
```javascript
|
|
71
|
+
import { trackWebEvent } from 'azzas-tracker-web';
|
|
72
|
+
|
|
73
|
+
// DATA TRACKING | add_personal_info at submit (pre-filled always false)
|
|
74
|
+
// @see notion document for more details:
|
|
75
|
+
const form: Element = document.querySelector('xxxxxx');
|
|
76
|
+
if (form) {
|
|
77
|
+
form.addEventListener('submit', () => {
|
|
78
|
+
trackWebEvent('ADD_PERSONAL_INFO', { preFilled: false, orderForm: vtexjs.checkout.orderForm });
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
***OBS***: atente-se ao adicionar eventos novos e contribua na documentação do NOTION ou apenas DOCUMENTE em algum lugar! Seu futuro EU será grato 👍
|
|
84
|
+
|
|
85
|
+
## Teste Local para Ambientes CDN/DENO
|
|
86
|
+
|
|
87
|
+
Para testar alterações na biblioteca localmente, simulando a forma como ela é carregada por uma CDN (<script src="...">), use o script npm run dev:deno.
|
|
88
|
+
|
|
89
|
+
Este comando realiza o build mais recente da biblioteca, empacota-o e inicia um servidor HTTP local usando o Deno para servir o arquivo
|
|
90
|
+
|
|
91
|
+
1. Aqui nesse repositório, rode o script que inicia o servidor local:
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
npm run dev:deno
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
O servidor será iniciado e começará a servir o seu arquivo de build no seguinte endereço: http://localhost:4507/.
|
|
98
|
+
|
|
99
|
+
2. No Projeto Consumidor (DENO/FRONT):
|
|
100
|
+
|
|
101
|
+
Altere o link do <script> no seu projeto para apontar para o servidor local.
|
|
102
|
+
|
|
103
|
+
Você deve usar: <script src="http://localhost:4507/dist/mod.global.js"></script>
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
## Boas Práticas
|
|
107
|
+
- Sempre garantir que os `requiredParams` de cada evento estejam preenchidos antes de enviar.
|
|
108
|
+
|
|
109
|
+
- Procure sempre manter o envio das ações de usuário o mais ***genérico*** possível. Toda a inteligência e complexidade do tratamento dos dados deve ficar centralizada na lib, e não nos repositórios das lojas.
|
|
110
|
+
|
|
111
|
+
- Usar nomes de eventos semânticos e consistentes (ex: VIEW_CART, ADD_PAYMENT_INFO).
|
|
112
|
+
|
|
113
|
+
- Manter os contextos enxutos, enviando apenas dados realmente necessários.
|
|
114
|
+
|
|
115
|
+
- Cada novo evento deve ser registrado em `EVENTS` com seus destinos e parâmetros obrigatórios. Essa constante talvez venha a ser dinâmica dependendo da MARCA utilizada
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
## Contribuição
|
|
119
|
+
|
|
120
|
+
- Adicionar novos eventos em `EVENTS`.
|
|
121
|
+
|
|
122
|
+
- Criar adapter correspondente caso seja necessário integrar com nova plataforma. Nesse caso deve-se avaliar qual será o serviço feito, o que será consumido, para onde será enviado.
|
|
123
|
+
|
|
124
|
+
- Garantir que todos os parâmetros obrigatórios estejam mapeados nos getters/resolvers.
|
|
125
|
+
|
|
126
|
+
- Executar build (npm run build) antes de testar no checkout/loja.
|
|
127
|
+
|
|
128
|
+
## Authors
|
|
129
|
+
|
|
130
|
+
- Lucas Soares
|
package/dist/mod.cjs
CHANGED
|
@@ -630,10 +630,158 @@ async function itemsFromOrderForm(context) {
|
|
|
630
630
|
);
|
|
631
631
|
}
|
|
632
632
|
|
|
633
|
+
// src/params/utils/itemListAttribution.ts
|
|
634
|
+
var LAST_SELECTED_ITEM_KEY = "last_selected_item";
|
|
635
|
+
var STORAGE_VIEWED = "last_viewed_item";
|
|
636
|
+
var CART_LIST_HISTORY_KEY = "cart_list_history";
|
|
637
|
+
var DAY_IN_MS = 24 * 60 * 60 * 1e3;
|
|
638
|
+
function getStorage() {
|
|
639
|
+
try {
|
|
640
|
+
if (typeof window === "undefined" || !window.localStorage) return null;
|
|
641
|
+
return window.localStorage;
|
|
642
|
+
} catch (e) {
|
|
643
|
+
return null;
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
function parseJSON(value) {
|
|
647
|
+
if (!value) return null;
|
|
648
|
+
try {
|
|
649
|
+
return JSON.parse(value);
|
|
650
|
+
} catch (e) {
|
|
651
|
+
return null;
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
function isFreshTimestamp(timestamp) {
|
|
655
|
+
const elapsed = Date.now() - timestamp;
|
|
656
|
+
return elapsed >= 0 && elapsed < DAY_IN_MS;
|
|
657
|
+
}
|
|
658
|
+
function isStoredItemMemory(value) {
|
|
659
|
+
if (!value || typeof value !== "object") return false;
|
|
660
|
+
const candidate = value;
|
|
661
|
+
return typeof candidate.id === "string" && typeof candidate.list === "string" && typeof candidate.timestamp === "number";
|
|
662
|
+
}
|
|
663
|
+
function resolveIdFromUnknownItem(item) {
|
|
664
|
+
var _a, _b, _c, _d, _e;
|
|
665
|
+
const id = (_e = (_d = (_c = (_b = (_a = item == null ? void 0 : item.productID) != null ? _a : item == null ? void 0 : item.productId) != null ? _b : item == null ? void 0 : item.item_group_id) != null ? _c : item == null ? void 0 : item.item_id) != null ? _d : item == null ? void 0 : item.id) != null ? _e : null;
|
|
666
|
+
return id == null ? null : String(id);
|
|
667
|
+
}
|
|
668
|
+
function resolveItemId(item) {
|
|
669
|
+
return resolveIdFromUnknownItem(item);
|
|
670
|
+
}
|
|
671
|
+
function readStoredItem(key) {
|
|
672
|
+
const storage = getStorage();
|
|
673
|
+
if (!storage) return null;
|
|
674
|
+
try {
|
|
675
|
+
const parsed = parseJSON(storage.getItem(key));
|
|
676
|
+
return isStoredItemMemory(parsed) ? parsed : null;
|
|
677
|
+
} catch (e) {
|
|
678
|
+
return null;
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
function writeStoredItem(key, value) {
|
|
682
|
+
const storage = getStorage();
|
|
683
|
+
if (!storage) return;
|
|
684
|
+
try {
|
|
685
|
+
storage.setItem(key, JSON.stringify(value));
|
|
686
|
+
} catch (e) {
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
function readCartHistory() {
|
|
690
|
+
const storage = getStorage();
|
|
691
|
+
if (!storage) return [];
|
|
692
|
+
try {
|
|
693
|
+
const parsed = parseJSON(storage.getItem(CART_LIST_HISTORY_KEY));
|
|
694
|
+
if (!Array.isArray(parsed)) return [];
|
|
695
|
+
return parsed.filter((entry) => !!entry && typeof entry === "object" && typeof entry.id === "string" && typeof entry.list === "string");
|
|
696
|
+
} catch (e) {
|
|
697
|
+
return [];
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
function writeCartHistory(history) {
|
|
701
|
+
const storage = getStorage();
|
|
702
|
+
if (!storage) return;
|
|
703
|
+
try {
|
|
704
|
+
storage.setItem(CART_LIST_HISTORY_KEY, JSON.stringify(history));
|
|
705
|
+
} catch (e) {
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
function saveSelectedItem(productId, listName) {
|
|
709
|
+
if (productId == null || !listName) return;
|
|
710
|
+
const payload = {
|
|
711
|
+
id: String(productId),
|
|
712
|
+
list: String(listName),
|
|
713
|
+
timestamp: Date.now()
|
|
714
|
+
};
|
|
715
|
+
writeStoredItem(LAST_SELECTED_ITEM_KEY, payload);
|
|
716
|
+
}
|
|
717
|
+
function saveViewedItem(productId, listName) {
|
|
718
|
+
if (productId == null) return;
|
|
719
|
+
const payload = {
|
|
720
|
+
id: String(productId),
|
|
721
|
+
list: String(listName != null ? listName : "PDP"),
|
|
722
|
+
timestamp: Date.now()
|
|
723
|
+
};
|
|
724
|
+
writeStoredItem(STORAGE_VIEWED, payload);
|
|
725
|
+
}
|
|
726
|
+
function resolveItemListName(params) {
|
|
727
|
+
const { event, item, itemListName } = params;
|
|
728
|
+
const currentListName = itemListName != null ? itemListName : null;
|
|
729
|
+
const isResolvableEvent = event === "VIEW_ITEM" || event === "ADD_TO_CART";
|
|
730
|
+
if (!isResolvableEvent) return currentListName;
|
|
731
|
+
const currentItemId = resolveIdFromUnknownItem(item);
|
|
732
|
+
if (event === "VIEW_ITEM") {
|
|
733
|
+
if (!currentItemId) return "PDP";
|
|
734
|
+
const selectedItem = readStoredItem(LAST_SELECTED_ITEM_KEY);
|
|
735
|
+
if (!selectedItem) return "PDP";
|
|
736
|
+
if (selectedItem.id === currentItemId && isFreshTimestamp(selectedItem.timestamp)) {
|
|
737
|
+
return selectedItem.list;
|
|
738
|
+
}
|
|
739
|
+
return "PDP";
|
|
740
|
+
}
|
|
741
|
+
if (currentListName !== "PDP" && currentListName !== null) return currentListName;
|
|
742
|
+
if (!currentItemId) return currentListName;
|
|
743
|
+
const viewedItem = readStoredItem(STORAGE_VIEWED);
|
|
744
|
+
if (viewedItem && viewedItem.id === currentItemId && isFreshTimestamp(viewedItem.timestamp)) {
|
|
745
|
+
return viewedItem.list;
|
|
746
|
+
}
|
|
747
|
+
return currentListName === "PDP" ? "PDP" : null;
|
|
748
|
+
}
|
|
749
|
+
function appendCartHistory(productId, listName) {
|
|
750
|
+
if (productId == null) return;
|
|
751
|
+
const history = readCartHistory();
|
|
752
|
+
history.push({
|
|
753
|
+
id: String(productId),
|
|
754
|
+
list: listName ? String(listName) : "PDP"
|
|
755
|
+
});
|
|
756
|
+
writeCartHistory(history);
|
|
757
|
+
}
|
|
758
|
+
function pickSelectedItemFromResolvedItems(items, source) {
|
|
759
|
+
var _a;
|
|
760
|
+
if (!Array.isArray(items) || items.length === 0) return null;
|
|
761
|
+
if (typeof (source == null ? void 0 : source.index) === "number") {
|
|
762
|
+
const indexed = (_a = items.find((item) => (item == null ? void 0 : item.index) === source.index)) != null ? _a : items[source.index];
|
|
763
|
+
if (indexed && typeof indexed === "object") return indexed;
|
|
764
|
+
}
|
|
765
|
+
return items[0];
|
|
766
|
+
}
|
|
767
|
+
function persistSelectItemOriginFromResolvedItems(items, source) {
|
|
768
|
+
var _a, _b, _c;
|
|
769
|
+
const selectedItem = pickSelectedItemFromResolvedItems(items, source);
|
|
770
|
+
if (!selectedItem) return;
|
|
771
|
+
const productId = resolveIdFromUnknownItem(selectedItem);
|
|
772
|
+
const listName = (_c = (_b = (_a = selectedItem == null ? void 0 : selectedItem.item_list_name) != null ? _a : source == null ? void 0 : source.itemListName) != null ? _b : source == null ? void 0 : source.item_list_name) != null ? _c : null;
|
|
773
|
+
saveSelectedItem(productId, listName);
|
|
774
|
+
}
|
|
775
|
+
|
|
633
776
|
// src/params/resolvers/items/fromItem.ts
|
|
634
777
|
async function itemsFromItem(context, event) {
|
|
635
778
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
636
779
|
const { item, orderForm, itemListName } = context;
|
|
780
|
+
const resolvedListName = resolveItemListName({ event, item, itemListName });
|
|
781
|
+
const resolvedItemId = resolveItemId(item);
|
|
782
|
+
if (event === "ADD_TO_CART") {
|
|
783
|
+
appendCartHistory(resolvedItemId, resolvedListName);
|
|
784
|
+
}
|
|
637
785
|
return [
|
|
638
786
|
{
|
|
639
787
|
index: typeof (item == null ? void 0 : item.index) === "number" ? item.index : null,
|
|
@@ -651,7 +799,7 @@ async function itemsFromItem(context, event) {
|
|
|
651
799
|
item_variant: ((item == null ? void 0 : item.skuName) || (item == null ? void 0 : item.item_variant) || (item == null ? void 0 : item.name) || (item == null ? void 0 : item.itemOffered.name)).split(/[-/]/)[0].trim() || null,
|
|
652
800
|
item_variant2: (item == null ? void 0 : item.size) || ((_n = item == null ? void 0 : item.itemAttributes) == null ? void 0 : _n.size) || ((_p = (_o = (item == null ? void 0 : item.skuName) || (item == null ? void 0 : item.name) || (item == null ? void 0 : item.itemOffered.name)) == null ? void 0 : _o.split(/[-/]/).pop()) == null ? void 0 : _p.trim()) || null,
|
|
653
801
|
discount: getDiscount(item),
|
|
654
|
-
item_list_name:
|
|
802
|
+
item_list_name: resolvedListName,
|
|
655
803
|
item_url: (item == null ? void 0 : item.item_url) || null,
|
|
656
804
|
// add_to_cart dito
|
|
657
805
|
image_url: resizeVtexImage(item == null ? void 0 : item.image) || resizeVtexImage(item == null ? void 0 : item.imageUrl) || null
|
|
@@ -681,9 +829,14 @@ async function itemsFromList(context) {
|
|
|
681
829
|
}
|
|
682
830
|
|
|
683
831
|
// src/params/resolvers/items/fromPdp.ts
|
|
684
|
-
async function itemsFromPDP(context) {
|
|
832
|
+
async function itemsFromPDP(context, event) {
|
|
685
833
|
var _a, _b, _c, _d;
|
|
686
834
|
const { item, value, brand } = context;
|
|
835
|
+
const resolvedListName = resolveItemListName({ event, item, itemListName: null });
|
|
836
|
+
const resolvedItemId = resolveItemId(item);
|
|
837
|
+
if (event === "VIEW_ITEM") {
|
|
838
|
+
saveViewedItem(resolvedItemId, resolvedListName);
|
|
839
|
+
}
|
|
687
840
|
return [
|
|
688
841
|
{
|
|
689
842
|
price: value || 0,
|
|
@@ -700,7 +853,8 @@ async function itemsFromPDP(context) {
|
|
|
700
853
|
item_sku: (item == null ? void 0 : item.sku) || (item == null ? void 0 : item.productId) || null,
|
|
701
854
|
item_url: (item == null ? void 0 : item.url) || (item == null ? void 0 : item.item_url) || (item == null ? void 0 : item.link) || null,
|
|
702
855
|
image_url: resizeVtexImage(item == null ? void 0 : item.image) || resizeVtexImage(item == null ? void 0 : item.imageUrl) || null,
|
|
703
|
-
seller_id: (item == null ? void 0 : item.seller) || null
|
|
856
|
+
seller_id: (item == null ? void 0 : item.seller) || null,
|
|
857
|
+
item_list_name: resolvedListName
|
|
704
858
|
}
|
|
705
859
|
];
|
|
706
860
|
}
|
|
@@ -743,11 +897,15 @@ function getItems(context, eventName) {
|
|
|
743
897
|
case "REMOVE_FROM_CART":
|
|
744
898
|
return itemsFromItem(context, eventName);
|
|
745
899
|
case "SELECT_ITEM":
|
|
900
|
+
return itemsFromList(context).then((items) => {
|
|
901
|
+
persistSelectItemOriginFromResolvedItems(items, context);
|
|
902
|
+
return items;
|
|
903
|
+
});
|
|
746
904
|
case "VIEW_ITEM_LIST":
|
|
747
905
|
return itemsFromList(context);
|
|
748
906
|
case "VIEW_ITEM":
|
|
749
907
|
case "CUSTOM_VIEW_ITEM":
|
|
750
|
-
return itemsFromPDP(context);
|
|
908
|
+
return itemsFromPDP(context, eventName);
|
|
751
909
|
case "VIEW_PROMOTION":
|
|
752
910
|
case "SELECT_PROMOTION":
|
|
753
911
|
return itemsFromBanner(context);
|