Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New events and updates #93

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
31 changes: 26 additions & 5 deletions react/modules/extraEvents.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions react/modules/legacyEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export async function sendLegacyEvents(e: PixelMessage) {
case 'productView': {
push({
event: 'productView',
product: e.data.product
})
break
}
Expand Down
31 changes: 31 additions & 0 deletions react/typings/events.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface PixelMessage extends MessageEvent {
| CartData
| PromoViewData
| PromotionClickData
| FilterProductsData
}

export interface EventData {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -365,6 +372,12 @@ export interface Product {
productName: string
productReference: string
selectedSku: Item
properties: ProductProperties[]
}

interface ProductProperties {
name: string
values: string[]
}

export interface Item {
Expand Down Expand Up @@ -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
Expand Down