From 18b4e3ee3e913ed18e0f55c64411e3257993f358 Mon Sep 17 00:00:00 2001 From: cristiancustomsoft Date: Thu, 21 Jul 2022 08:49:39 +0300 Subject: [PATCH] New events and updates --- CHANGELOG.md | 4 ++++ react/modules/extraEvents.ts | 31 ++++++++++++++++++++++++++----- react/modules/legacyEvents.ts | 1 + react/typings/events.d.ts | 31 +++++++++++++++++++++++++++++++ 4 files changed, 62 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1827f356..83f0ae6c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Added +- `firstName`, `lastName`, `fullName`, `email`, `phone` on dataLayer for userData event +- New events: `sortProducts`, `filterProducts` +- Information about product on `productView` event ## [3.3.1] - 2022-04-04 diff --git a/react/modules/extraEvents.ts b/react/modules/extraEvents.ts index f21e3964..b4fc31ed 100644 --- a/react/modules/extraEvents.ts +++ b/react/modules/extraEvents.ts @@ -1,13 +1,12 @@ import push from './push' -import { PixelMessage } from '../typings/events' +import { PixelMessage, FilterProductsData } from '../typings/events' async function emailToHash(email:string) { - const msgUint8 = new TextEncoder().encode(email); + const msgUint8 = new TextEncoder().encode(email); const hashBuffer = await crypto.subtle.digest('SHA-256', msgUint8); const hashArray = Array.from(new Uint8Array(hashBuffer)); - const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join(''); - return hashHex; + return hashArray.map(b => b.toString(16).padStart(2, '0')).join(''); } export async function sendExtraEvents(e: PixelMessage) { @@ -39,12 +38,34 @@ export async function sendExtraEvents(e: PixelMessage) { push({ event: 'userData', userId: data.id, - emailHash: emailHash + emailHash: emailHash, + firstName: data.firstName, + lastName: data.lastName, + fullName: `${data.firstName} ${data.lastName}`, + email: data.email, + phone: data.phone }) break } + case 'vtex:sortProducts': { + push({ + event: 'sortProducts', + value: e.data.value + }) + break + } + + case 'vtex:filterProducts': { + const { values } = e.data as FilterProductsData + push({ + event: 'filterProducts', + values: values + }) + break + } + default: { break } diff --git a/react/modules/legacyEvents.ts b/react/modules/legacyEvents.ts index 0fdadb1a..9517af8c 100644 --- a/react/modules/legacyEvents.ts +++ b/react/modules/legacyEvents.ts @@ -58,6 +58,7 @@ export async function sendLegacyEvents(e: PixelMessage) { case 'productView': { push({ event: 'productView', + product: e.data.product }) break } diff --git a/react/typings/events.d.ts b/react/typings/events.d.ts index ec26396e..0e89d391 100644 --- a/react/typings/events.d.ts +++ b/react/typings/events.d.ts @@ -17,6 +17,7 @@ export interface PixelMessage extends MessageEvent { | CartData | PromoViewData | PromotionClickData + | FilterProductsData } export interface EventData { @@ -164,6 +165,12 @@ export interface PromotionClickData extends EventData { promotions: Promotion[] } +export interface FilterProductsData { + event: 'filterProducts' + eventName: 'vtex:filterProducts' + values: FilterProductsValues[] +} + interface Promotion { id?: string name?: string @@ -365,6 +372,12 @@ export interface Product { productName: string productReference: string selectedSku: Item + properties: ProductProperties[] +} + +interface ProductProperties { + name: string + values: string[] } export interface Item { @@ -397,6 +410,24 @@ interface ItemSummary { sellers: Seller[] } +interface FilterProductsValues { + children: string | null + hidden: boolean + href: string + id: string + key: string + link: string | null + linkEncoded: string | null + map: string + name: string + newQuerySegment: string + quantity: number + range: string | null + selected: boolean + title: string + value: string +} + export interface Seller { commertialOffer: CommertialOffer sellerId: string