Skip to content

Commit

Permalink
Merge pull request #279 from vtex-apps/fix/gtm-major-compatibility
Browse files Browse the repository at this point in the history
Fixing GTM events to follow Google's defined patterns
  • Loading branch information
Ícaro Azevedo authored Jun 8, 2021
2 parents 69d451d + 22db985 commit 1dd514a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ 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]
### Fixed
- GTM events to follow Google's defined patterns

## [2.59.0] - 2021-04-22
### Added
Expand Down
33 changes: 26 additions & 7 deletions react/ProductList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,34 @@ const ProductList: FC<Props> = ({ renderAsChildren, classes }) => {

const handleQuantityChange = useCallback(
(uniqueId: string, quantity: number, item: OrderFormItem) => {
const adjustedItem = {
...mapCartItemToPixel(item),
quantity,
if (quantity === item.quantity) {
return
}

const quantityIncreased = quantity > item.quantity

if (quantityIncreased) {
const adjustedItem = {
...mapCartItemToPixel(item),
quantity: quantity - item.quantity,
}

push({
event: 'addToCart',
items: [adjustedItem],
})
} else {
const adjustedItem = {
...mapCartItemToPixel(item),
quantity: item.quantity - quantity,
}

push({
event: 'removeFromCart',
items: [adjustedItem],
})
}

push({
event: 'addToCart',
items: [adjustedItem],
})
updateQuantity({ uniqueId, quantity }, options)
},
[push, updateQuantity]
Expand Down

0 comments on commit 1dd514a

Please sign in to comment.