Skip to content

Commit

Permalink
Fix view_item output
Browse files Browse the repository at this point in the history
  • Loading branch information
stefandoorn committed Jun 8, 2023
1 parent 0173cfb commit cd95aeb
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/TagManager/ViewItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,23 +71,25 @@ private function addViewItemData(ProductInterface $product): void
);

$data = [
'item_id' => $this->productIdentifierHelper->getProductIdentifier($product),
'item_name' => $product->getName(),
'affiliation' => $this->channelContext->getChannel()->getName(),
'item_category' => null !== $mainTaxon ? $mainTaxon->getName() : '',
'price' => $productVariantPrice / 100,
'index' => 0,
'items' => [
'item_id' => $this->productIdentifierHelper->getProductIdentifier($product),
'item_name' => $product->getName(),
'affiliation' => $this->channelContext->getChannel()->getName(),
'item_category' => null !== $mainTaxon ? $mainTaxon->getName() : '',
'price' => $productVariantPrice / 100,
'index' => 0,
],
'currency' => $this->currencyContext->getCurrencyCode(),
'value' => $productVariantPrice / 100,
];

// https://developers.google.com/analytics/devguides/collection/ga4/ecommerce?client_type=gtag#view_item_details
// https://developers.google.com/analytics/devguides/collection/ga4/ecommerce?client_type=gtm#view_item_details
$this->googleTagManager->addPush([
'ecommerce' => null,
]);

$this->googleTagManager->addPush([
'event' => 'view_item',
'currency' => $this->currencyContext->getCurrencyCode(),
'value' => $data['price'],
'ecommerce' => $data,
]);
}
Expand Down

0 comments on commit cd95aeb

Please sign in to comment.