fix: Poprawki dataLayer GA4 — purchase price, format kluczy, fałszywa konwersja GADS
- purchase: id→item_id (string), name→item_name, price fallback na price_brutto gdy brak promo, user_data poza ecommerce - begin_checkout: id→item_id, name→item_name, dodano google_business_vertical - Usunięto fałszywą konwersję GADS (gtag conversion) ze strony checkout - view_item: dodano currency PLN, price jako number zamiast string - Dodano event view_cart na stronie koszyka - add_to_cart: quantity parseInt zamiast string Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -33,6 +33,35 @@
|
||||
</div>
|
||||
<? endif; ?>
|
||||
</div>
|
||||
<? if ( $this -> settings['google_tag_manager_id'] && is_array( $this -> basket ) && count( $this -> basket ) ):?>
|
||||
<script>
|
||||
dataLayer.push({
|
||||
event: "view_cart",
|
||||
ecommerce: {
|
||||
currency: "PLN",
|
||||
value: <?= \Shared\Helpers\Helpers::normalize_decimal( \Domain\Basket\BasketCalculator::summaryPrice( $this -> basket, $this -> coupon ) );?>,
|
||||
items: [
|
||||
<?
|
||||
$view_cart_items = '';
|
||||
foreach ( $this -> basket as $position_hash => $position ):
|
||||
$product = (new \Domain\Product\ProductRepository($GLOBALS['mdb']))->findCached( (int)$position['product-id'], $GLOBALS['lang_id'] );
|
||||
$price_product = \Domain\Basket\BasketCalculator::calculateBasketProductPrice((float)$product['price_brutto_promo'], (float)$product['price_brutto'], $this->coupon, $position);
|
||||
if ( $view_cart_items ) $view_cart_items .= ',';
|
||||
$view_cart_items .= '{';
|
||||
$view_cart_items .= '"item_id": "' . $product['id'] . '",';
|
||||
$view_cart_items .= '"item_name": "' . $product['language']['name'] . '",';
|
||||
$view_cart_items .= '"price": ' . \Shared\Helpers\Helpers::normalize_decimal( $price_product['price_new'] ) . ',';
|
||||
$view_cart_items .= '"quantity": ' . (int)$position['quantity'] . ',';
|
||||
$view_cart_items .= '"google_business_vertical": "retail"';
|
||||
$view_cart_items .= '}';
|
||||
endforeach;
|
||||
echo $view_cart_items;
|
||||
?>
|
||||
]
|
||||
}
|
||||
});
|
||||
</script>
|
||||
<? endif;?>
|
||||
<script>
|
||||
(function(o, r, l, e, n) {
|
||||
o[l] = o[l] || [];
|
||||
|
||||
Reference in New Issue
Block a user