Skip to content

Commit

Permalink
Add skuName in variant property
Browse files Browse the repository at this point in the history
  • Loading branch information
Bruno Dias committed May 14, 2019
1 parent bbedce5 commit ad05314
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Changed

- Add skuName in variant property.

## [0.3.0] - 2019-05-14

### Fixed
Expand Down
32 changes: 26 additions & 6 deletions react/events/enhancedCommerce.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,38 @@
/** Product viewed event
* https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce#measuring-actvities
*/
export const productDetail = (product: any) => {

interface Item {
itemId: string
name: string
}

interface Product {
brand: string
categoryId: string
productId: string
productName: string
selectedSku: string
items: Item[]
}

const getSkuName = (selectedSku: string, items: Item[]) =>
(items.find((item: Item) => selectedSku === item.itemId) || ({} as Item)).name

export const productDetail = (product: Product) => {
ga('ec:addProduct', {
brand: product.brand,
category: product.categoryId,
id: product.productId,
name: product.productName,
variant: product.variant,
variant: getSkuName(product.selectedSku, product.items),
})

ga('ec:setAction', 'detail')

ga('send', 'event', {
eventAction: 'Detail -> View',
eventCategory: 'Ecommerce -> Product',
eventAction: 'Detail',
eventCategory: 'Ecommerce',
nonInteraction: 1,
})
}
Expand Down Expand Up @@ -43,8 +63,8 @@ export const purchase = (order: any) => {
})

ga('send', 'event', {
eventAction: 'Purchase -> View',
eventCategory: 'Ecommerce -> OrderPlaced',
eventAction: 'Purchase',
eventCategory: 'Ecommerce',
nonInteraction: 1,
})
}

0 comments on commit ad05314

Please sign in to comment.