diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e18327..b5bf75f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/manifest.json b/manifest.json index 871634f..9543bd9 100644 --- a/manifest.json +++ b/manifest.json @@ -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", diff --git a/react/events/enhancedCommerce.ts b/react/events/enhancedCommerce.ts index ccafd14..f589ecc 100644 --- a/react/events/enhancedCommerce.ts +++ b/react/events/enhancedCommerce.ts @@ -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, }) } @@ -43,8 +63,8 @@ export const purchase = (order: any) => { }) ga('send', 'event', { - eventAction: 'Purchase -> View', - eventCategory: 'Ecommerce -> OrderPlaced', + eventAction: 'Purchase', + eventCategory: 'Ecommerce', nonInteraction: 1, }) }