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

feat: autocomplete dataLayer events #153

Open
wants to merge 1 commit 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
7 changes: 7 additions & 0 deletions react/modules/enhancedEcommerceEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
addShippingInfo,
viewCart,
search,
autocomplete,
login,
refund,
addToWishlist,
Expand Down Expand Up @@ -378,6 +379,12 @@ export async function sendEnhancedEcommerceEvents(e: PixelMessage) {
break
}

case 'vtex:autocomplete': {
autocomplete(e.data)

break
}

case 'vtex:share': {
share(e.data)

Expand Down
15 changes: 14 additions & 1 deletion react/modules/gaEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
SignUpData,
ShareData,
PromotionClickData,
AutocompleteData,
} from '../typings/events'
import updateEcommerce from './updateEcommerce'
import {
Expand Down Expand Up @@ -366,7 +367,9 @@ export function addToWishlist(eventData: AddToWishlistData) {
...categoriesHierarchy,
...customDimensions({
productReference,
skuReference: sku ? sku.referenceId.Value : items.selectedItem.referenceId,
skuReference: sku
? sku.referenceId.Value
: items.selectedItem.referenceId,
skuName: sku ? sku.name : items.selectedItem.name,
quantity,
}),
Expand Down Expand Up @@ -444,6 +447,16 @@ export function search(eventData: SearchData) {
updateEcommerce(eventName, { ecommerce: data })
}

export function autocomplete(eventData: AutocompleteData) {
const { eventType } = eventData

const data = {
term: eventData.search.term,
}

updateEcommerce(eventType, { ecommerce: data })
}

export function share(eventData: ShareData) {
const eventName = 'share'

Expand Down
12 changes: 12 additions & 0 deletions react/typings/events.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export interface PixelMessage extends MessageEvent {
| RefundData
| AddToWishlistData
| SearchData
| AutocompleteData
}

export interface EventData {
Expand Down Expand Up @@ -273,13 +274,24 @@ export interface RefundData extends EventData {
}
}

export interface SearchAutocompleteData {
term: string
}

export interface SearchData extends EventData {
event: 'search'
eventType: 'vtex:search'
eventName: 'vtex:search'
term: string
}

export interface AutocompleteData extends EventData {
event: 'autocomplete'
eventType: string
eventName: 'vtex:autocomplete'
search: SearchAutocompleteData
}

export interface ShareData extends EventData {
event: 'share'
eventType: 'vtex:share'
Expand Down