@rocketsearch/vue-uappi 0.1.6 → 0.1.7
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/package.json +1 -1
- package/runtime/components/RocketSearch.vue +2 -2
- package/runtime/listing.js +20 -3
- package/runtime/rocket.js +33 -28
package/package.json
CHANGED
|
@@ -185,7 +185,7 @@ import '../css/search.css';
|
|
|
185
185
|
import RocketSearchFacets from './search/RocketSearchFacets.vue';
|
|
186
186
|
import RocketSearchPagination from './search/RocketSearchPagination.vue';
|
|
187
187
|
import { productImage, productPath, productPrice, formatCurrency } from '../uappi.js';
|
|
188
|
-
import { TRACKING_PARAMS, didYouMeanQuery, dispatchDidYouMeanClick, ratingLabel } from '../listing.js';
|
|
188
|
+
import { TRACKING_PARAMS, gridClickMeta, didYouMeanQuery, dispatchDidYouMeanClick, ratingLabel } from '../listing.js';
|
|
189
189
|
|
|
190
190
|
// Parâmetros de campanha nunca viram filtro na busca.
|
|
191
191
|
function emptyContext () {
|
|
@@ -511,7 +511,7 @@ export default {
|
|
|
511
511
|
this.$rocket.dispatchEvent('click', {
|
|
512
512
|
productId: String(product.id),
|
|
513
513
|
position: index,
|
|
514
|
-
meta:
|
|
514
|
+
meta: gridClickMeta(this.term, this.isCategory && this.categoryId)
|
|
515
515
|
}).catch(() => {});
|
|
516
516
|
}
|
|
517
517
|
}
|
package/runtime/listing.js
CHANGED
|
@@ -231,7 +231,8 @@ export function mergeIntoUappiPage (base, listing) {
|
|
|
231
231
|
export async function rocketCategoryListing ({ $rocket, categoryId, query, limit, base, path }) {
|
|
232
232
|
const params = Object.assign(toRocketParams(query, limit), { categoryId });
|
|
233
233
|
const response = await $rocket.search(params);
|
|
234
|
-
|
|
234
|
+
const listing = mergeIntoUappiPage(base, await withUappiProducts($rocket, response, query, { limit, path }));
|
|
235
|
+
return Object.assign(listing, { rocketCategory: true });
|
|
235
236
|
}
|
|
236
237
|
|
|
237
238
|
/** Coleção do painel pelo slug. null quando a Rocket não tem essa coleção no ar. */
|
|
@@ -242,7 +243,8 @@ export async function rocketCollectionListing ({ $rocket, slug, query, limit, ba
|
|
|
242
243
|
const response = await $rocket.collection(slug, params);
|
|
243
244
|
if (!response) return null;
|
|
244
245
|
const defaultSort = response.sortOptions && response.sortOptions[0] && response.sortOptions[0].id;
|
|
245
|
-
|
|
246
|
+
const listing = mergeIntoUappiPage(base, await withUappiProducts($rocket, response, query, { limit, path, defaultSort }));
|
|
247
|
+
return Object.assign(listing, { rocketCollection: slug });
|
|
246
248
|
}
|
|
247
249
|
|
|
248
250
|
export function dispatchListingSearch ($rocket, listing) {
|
|
@@ -278,11 +280,26 @@ export function dispatchDidYouMeanClick ($rocket, { from, suggestion, source })
|
|
|
278
280
|
}).catch(() => {});
|
|
279
281
|
}
|
|
280
282
|
|
|
283
|
+
// Contrato de eventos (spec 082): com termo é busca; grade sem termo (categoria, catálogo) é
|
|
284
|
+
// 'category-page' — 'search-page' vazio inflava a receita "Busca".
|
|
285
|
+
export function gridClickMeta (query, categoryId, collection) {
|
|
286
|
+
const term = String(query || '').trim();
|
|
287
|
+
if (term) return { source: 'search-page', query: term };
|
|
288
|
+
const meta = { source: 'category-page' };
|
|
289
|
+
if (categoryId) meta.categoryId = String(categoryId);
|
|
290
|
+
if (collection) meta.collection = collection;
|
|
291
|
+
return meta;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// Só grade servida pela Rocket (marcada por rocketSearchListing / rocketCategoryListing /
|
|
295
|
+
// rocketCollectionListing): a listagem de reserva da Uappi não é clique Rocket.
|
|
281
296
|
export function dispatchListingClick ($rocket, listing, product, position) {
|
|
297
|
+
if (!listing || !(listing.rocketSearch || listing.rocketCategory || listing.rocketCollection)) return;
|
|
282
298
|
if (!product || product.id == null) return;
|
|
299
|
+
const categoria = listing.conteudo && listing.conteudo.categoria;
|
|
283
300
|
$rocket.dispatchEvent('click', {
|
|
284
301
|
productId: String(product.id),
|
|
285
302
|
position,
|
|
286
|
-
meta:
|
|
303
|
+
meta: gridClickMeta(listing.rocketSearch && listing.rocketSearch.query, categoria && categoria.id, listing.rocketCollection)
|
|
287
304
|
}).catch(() => {});
|
|
288
305
|
}
|
package/runtime/rocket.js
CHANGED
|
@@ -16,7 +16,11 @@ const SHOWCASE_ATTR_TTL = 30 * 60 * 1000;
|
|
|
16
16
|
// Mapa persistente produto -> vitrine (last-touch por produto). Diferente do slot único,
|
|
17
17
|
// NÃO é apagado no add_to_cart: sobrevive até o checkout para atribuir GMV no purchase.
|
|
18
18
|
const SHOWCASE_ATTR_MAP_KEY = 'rs_showcase_attr_map';
|
|
19
|
-
|
|
19
|
+
// Mapa produto -> origem do último clique em grade/autocomplete (search-page, category-page,
|
|
20
|
+
// autocomplete). Por produto, não por sessão (spec 082): o slot único de antes fazia todo
|
|
21
|
+
// view/add_to_cart dos 30 min seguintes herdar a origem de um clique em outro produto.
|
|
22
|
+
const SEARCH_ATTR_MAP_KEY = 'rs_search_attr_map';
|
|
23
|
+
const SEARCH_ATTR_SOURCES = ['autocomplete', 'search-page', 'category-page'];
|
|
20
24
|
const PENDING_CART_EVENTS_KEY = 'rs_pending_add_to_cart_events';
|
|
21
25
|
const ANON_SESSION_KEY = 'rs_anon_session_id';
|
|
22
26
|
const ANON_SESSION_TTL = 30 * 60 * 1000;
|
|
@@ -381,24 +385,26 @@ export function createRocket (config) {
|
|
|
381
385
|
return attr;
|
|
382
386
|
}
|
|
383
387
|
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
388
|
+
// Last-touch por produto; poda as entradas expiradas para o mapa não crescer na sessão.
|
|
389
|
+
function saveAttributionEntry (key, productId, entry) {
|
|
390
|
+
if (productId == null || productId === '') return;
|
|
391
|
+
const map = storageGet(key) || {};
|
|
387
392
|
const now = Date.now();
|
|
388
|
-
Object.keys(map).forEach((
|
|
389
|
-
if (!map[
|
|
393
|
+
Object.keys(map).forEach((k) => {
|
|
394
|
+
if (!map[k] || !map[k].ts || now - map[k].ts > SHOWCASE_ATTR_TTL) delete map[k];
|
|
390
395
|
});
|
|
391
|
-
map[String(productId)] =
|
|
392
|
-
storageSet(
|
|
396
|
+
map[String(productId)] = Object.assign(entry, { ts: now });
|
|
397
|
+
storageSet(key, map);
|
|
393
398
|
}
|
|
394
399
|
|
|
395
|
-
function
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
400
|
+
function saveShowcaseAttributionEntry (showcaseId, productId, position) {
|
|
401
|
+
if (!showcaseId) return;
|
|
402
|
+
saveAttributionEntry(SHOWCASE_ATTR_MAP_KEY, productId, { showcaseId, position: position != null && position >= 0 ? position : null });
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
function getSearchAttribution (productId) {
|
|
406
|
+
const entry = productId != null ? (storageGet(SEARCH_ATTR_MAP_KEY) || {})[String(productId)] : null;
|
|
407
|
+
return entry && entry.ts && Date.now() - entry.ts <= SHOWCASE_ATTR_TTL ? entry : null;
|
|
402
408
|
}
|
|
403
409
|
|
|
404
410
|
rocket.getShowcaseAttribution = getShowcaseAttribution;
|
|
@@ -428,8 +434,8 @@ export function createRocket (config) {
|
|
|
428
434
|
});
|
|
429
435
|
saveShowcaseAttributionEntry(data.vitrine, data.productId, data.position);
|
|
430
436
|
}
|
|
431
|
-
if (eventType === 'click' && (data.meta.source
|
|
432
|
-
|
|
437
|
+
if (eventType === 'click' && SEARCH_ATTR_SOURCES.includes(data.meta.source)) {
|
|
438
|
+
saveAttributionEntry(SEARCH_ATTR_MAP_KEY, data.productId, { source: data.meta.source });
|
|
433
439
|
}
|
|
434
440
|
|
|
435
441
|
const sessionId = await rocket.getSessionId();
|
|
@@ -530,10 +536,8 @@ export function createRocket (config) {
|
|
|
530
536
|
rocket.fireProductView = function () {
|
|
531
537
|
if (!page.productId) return;
|
|
532
538
|
const viewData = { productId: page.productId };
|
|
533
|
-
const
|
|
534
|
-
|
|
535
|
-
if (showcaseAttr && showcaseAttr.showcaseId) viewData.meta = { source: 'showcase:' + showcaseAttr.showcaseId };
|
|
536
|
-
else if (searchAttr && searchAttr.source) viewData.meta = { source: searchAttr.source };
|
|
539
|
+
const source = resolveProductSource(page.productId);
|
|
540
|
+
if (source) viewData.meta = { source };
|
|
537
541
|
rocket.dispatchEvent('view', viewData).catch(() => {});
|
|
538
542
|
};
|
|
539
543
|
|
|
@@ -583,11 +587,13 @@ export function createRocket (config) {
|
|
|
583
587
|
return cached != null ? cached : null;
|
|
584
588
|
}
|
|
585
589
|
|
|
586
|
-
|
|
590
|
+
// Origem só com clique NESTE produto: vitrine ou grade/autocomplete. Produto que apenas
|
|
591
|
+
// apareceu na grade (searchPriceCache) não ganha origem.
|
|
592
|
+
function resolveProductSource (productId) {
|
|
593
|
+
const attr = getShowcaseAttribution(productId);
|
|
587
594
|
if (attr && attr.showcaseId) return 'showcase:' + attr.showcaseId;
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
return null;
|
|
595
|
+
const searchAttr = getSearchAttribution(productId);
|
|
596
|
+
return searchAttr ? searchAttr.source : null;
|
|
591
597
|
}
|
|
592
598
|
|
|
593
599
|
rocket.trackAddToCart = function (payload) {
|
|
@@ -602,7 +608,6 @@ export function createRocket (config) {
|
|
|
602
608
|
if (!products.length) return;
|
|
603
609
|
|
|
604
610
|
const attr = getShowcaseAttribution(products[0].productId);
|
|
605
|
-
const searchAttr = getSearchAttribution();
|
|
606
611
|
const experiment = attr && attr.experimentId != null
|
|
607
612
|
? { experimentId: attr.experimentId, variantId: attr.variantId != null ? attr.variantId : null }
|
|
608
613
|
: {};
|
|
@@ -611,7 +616,7 @@ export function createRocket (config) {
|
|
|
611
616
|
const p = products[0];
|
|
612
617
|
const meta = { quantity: p.quantity };
|
|
613
618
|
const price = resolveProductPrice(p.productId, attr);
|
|
614
|
-
const source = resolveProductSource(p.productId
|
|
619
|
+
const source = resolveProductSource(p.productId);
|
|
615
620
|
if (source) meta.source = source;
|
|
616
621
|
if (price != null) meta.totalValue = price * p.quantity;
|
|
617
622
|
const eventData = Object.assign({ productId: p.productId, meta }, experiment);
|
|
@@ -624,7 +629,7 @@ export function createRocket (config) {
|
|
|
624
629
|
if (p.skuId) item.skuId = p.skuId;
|
|
625
630
|
const price = resolveProductPrice(p.productId, attr);
|
|
626
631
|
if (price != null) item.totalValue = price * p.quantity;
|
|
627
|
-
const source = resolveProductSource(p.productId
|
|
632
|
+
const source = resolveProductSource(p.productId);
|
|
628
633
|
if (source) item.source = source;
|
|
629
634
|
if (attr && attr.showcaseId && String(attr.productId) === String(p.productId)) item.showcaseId = Number(attr.showcaseId);
|
|
630
635
|
return item;
|