Skip to content

Commit

Permalink
Merge pull request #6 from vtex-apps/fix/variant
Browse files Browse the repository at this point in the history
Add skuName in variant property
  • Loading branch information
Bruno Dias authored May 14, 2019
2 parents bbedce5 + eb01f11 commit be9a3b6
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

## [0.3.1] - 2019-05-14

### Changed

- Add skuName in variant property.

## [0.3.0] - 2019-05-14

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "google-analytics",
"vendor": "vtex",
"version": "0.3.0",
"version": "0.3.1",
"title": "Google Analytics",
"description": "Google Analytics app",
"mustUpdateAt": "2019-04-03",
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 be9a3b6

Please sign in to comment.