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>
|
</div>
|
||||||
<? endif; ?>
|
<? endif; ?>
|
||||||
</div>
|
</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>
|
<script>
|
||||||
(function(o, r, l, e, n) {
|
(function(o, r, l, e, n) {
|
||||||
o[l] = o[l] || [];
|
o[l] = o[l] || [];
|
||||||
|
|||||||
@@ -73,10 +73,11 @@
|
|||||||
$begin_checkout_items .= ',';
|
$begin_checkout_items .= ',';
|
||||||
|
|
||||||
$begin_checkout_items .= '{';
|
$begin_checkout_items .= '{';
|
||||||
$begin_checkout_items .= '"id": "' . $product['id'] . '",';
|
$begin_checkout_items .= '"item_id": "' . $product['id'] . '",';
|
||||||
$begin_checkout_items .= '"name": "' . $product['language']['name'] . '",';
|
$begin_checkout_items .= '"item_name": "' . $product['language']['name'] . '",';
|
||||||
$begin_checkout_items .= '"price": ' . \Shared\Helpers\Helpers::normalize_decimal( $price_product['price_new'] ) . ',';
|
$begin_checkout_items .= '"price": ' . \Shared\Helpers\Helpers::normalize_decimal( $price_product['price_new'] ) . ',';
|
||||||
$begin_checkout_items .= '"quantity": ' . $position['quantity'];
|
$begin_checkout_items .= '"quantity": ' . (int)$position['quantity'] . ',';
|
||||||
|
$begin_checkout_items .= '"google_business_vertical": "retail"';
|
||||||
$begin_checkout_items .= '}';
|
$begin_checkout_items .= '}';
|
||||||
?>
|
?>
|
||||||
<? endforeach;?>
|
<? endforeach;?>
|
||||||
@@ -184,11 +185,5 @@
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
gtag('event', 'conversion', {
|
|
||||||
'send_to': 'AW-11122553653/O1ImCNnJ9ecYELXm0rcp',
|
|
||||||
'value': <?= \Shared\Helpers\Helpers::normalize_decimal( \Domain\Basket\BasketCalculator::summaryPrice( $this -> basket, $this -> coupon ) );?>,
|
|
||||||
'currency': 'PLN'
|
|
||||||
});
|
|
||||||
console.log( 'Fired up event GADS purchase conversion marianek.pl' );
|
|
||||||
<? endif;?>
|
<? endif;?>
|
||||||
</script>
|
</script>
|
||||||
@@ -170,25 +170,27 @@
|
|||||||
currency: "PLN",
|
currency: "PLN",
|
||||||
value: <?= \Shared\Helpers\Helpers::normalize_decimal( round( $this -> order['summary'], 2 ) ) - str_replace( ',', '.', round( $this -> order['transport_cost'], 2 ) );?>,
|
value: <?= \Shared\Helpers\Helpers::normalize_decimal( round( $this -> order['summary'], 2 ) ) - str_replace( ',', '.', round( $this -> order['transport_cost'], 2 ) );?>,
|
||||||
shipping: <?= \Shared\Helpers\Helpers::normalize_decimal( $this -> order['transport_cost'] );?>,
|
shipping: <?= \Shared\Helpers\Helpers::normalize_decimal( $this -> order['transport_cost'] );?>,
|
||||||
user_email: "<?= $this -> order['client_email'] ?>",
|
|
||||||
user_phone: "<?= $this -> order['client_phone'] ?>",
|
|
||||||
user_name: "<?= $this -> order['client_name'] ?>",
|
|
||||||
user_surname: "<?= $this -> order['client_surname'] ?>",
|
|
||||||
user_street: "<?= $this -> order['client_street'] ?>",
|
|
||||||
user_city: "<?= $this -> order['client_city'] ?>",
|
|
||||||
user_country: "Polska",
|
|
||||||
user_postal_code: "<?= $this -> order['client_postal_code'] ?>",
|
|
||||||
items: [
|
items: [
|
||||||
<? foreach ( $this -> order['products'] as $product ):?>
|
<? foreach ( $this -> order['products'] as $product ):?>
|
||||||
{
|
{
|
||||||
id: <?= (int)$product['product_id'];?>,
|
item_id: "<?= $product['product_id'];?>",
|
||||||
name: '<?= $product['name'];?>',
|
item_name: '<?= $product['name'];?>',
|
||||||
quantity: <?= $product['quantity'];?>,
|
quantity: <?= (int)$product['quantity'];?>,
|
||||||
price: <?= $product['price_brutto_promo'];?>,
|
price: <?= (float)$product['price_brutto_promo'] > 0 ? \Shared\Helpers\Helpers::normalize_decimal( $product['price_brutto_promo'] ) : \Shared\Helpers\Helpers::normalize_decimal( $product['price_brutto'] );?>,
|
||||||
google_business_vertical: 'retail'
|
google_business_vertical: 'retail'
|
||||||
}<? if ( $product != end( $this -> order['products'] ) ) echo ',';?>
|
}<? if ( $product != end( $this -> order['products'] ) ) echo ',';?>
|
||||||
<? endforeach;?>
|
<? endforeach;?>
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
user_data: {
|
||||||
|
email: "<?= $this -> order['client_email'] ?>",
|
||||||
|
phone_number: "<?= $this -> order['client_phone'] ?>",
|
||||||
|
first_name: "<?= $this -> order['client_name'] ?>",
|
||||||
|
last_name: "<?= $this -> order['client_surname'] ?>",
|
||||||
|
street: "<?= $this -> order['client_street'] ?>",
|
||||||
|
city: "<?= $this -> order['client_city'] ?>",
|
||||||
|
country: "PL",
|
||||||
|
postal_code: "<?= $this -> order['client_postal_code'] ?>"
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
<? endif;?>
|
<? endif;?>
|
||||||
|
|||||||
@@ -247,16 +247,17 @@
|
|||||||
dataLayer.push({
|
dataLayer.push({
|
||||||
event: "view_item",
|
event: "view_item",
|
||||||
ecommerce: {
|
ecommerce: {
|
||||||
|
currency: "PLN",
|
||||||
|
value: <? if ( $this -> product['price_brutto_promo'] ): echo \Shared\Helpers\Helpers::normalize_decimal( $this -> product['price_brutto_promo'] ); else: echo \Shared\Helpers\Helpers::normalize_decimal( $this -> product['price_brutto'] ); endif;?>,
|
||||||
items: [
|
items: [
|
||||||
{
|
{
|
||||||
item_id: "<?= $this -> product['id'];?>",
|
item_id: "<?= $this -> product['id'];?>",
|
||||||
item_name: "<?= str_replace( '"', '', $this -> product['language']['name'] );?>",
|
item_name: "<?= str_replace( '"', '', $this -> product['language']['name'] );?>",
|
||||||
price: '<? if ( $this -> product['price_brutto_promo'] ): echo \Shared\Helpers\Helpers::normalize_decimal( $this -> product['price_brutto_promo'] ); else: echo \Shared\Helpers\Helpers::normalize_decimal( $this -> product['price_brutto'] ); endif;?>',
|
price: <? if ( $this -> product['price_brutto_promo'] ): echo \Shared\Helpers\Helpers::normalize_decimal( $this -> product['price_brutto_promo'] ); else: echo \Shared\Helpers\Helpers::normalize_decimal( $this -> product['price_brutto'] ); endif;?>,
|
||||||
quantity: 1,
|
quantity: 1,
|
||||||
google_business_vertical: "retail"
|
google_business_vertical: "retail"
|
||||||
}
|
}
|
||||||
],
|
]
|
||||||
value: <? if ( $this -> product['price_brutto_promo'] ): echo \Shared\Helpers\Helpers::normalize_decimal( $this -> product['price_brutto_promo'] ); else: echo \Shared\Helpers\Helpers::normalize_decimal( $this -> product['price_brutto'] ); endif;?>
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
<? endif;?>
|
<? endif;?>
|
||||||
@@ -573,7 +574,7 @@
|
|||||||
item_id: "<?= $this -> product['id'];?>",
|
item_id: "<?= $this -> product['id'];?>",
|
||||||
item_name: "<?= str_replace( '"', '', $this -> product['language']['name'] );?>",
|
item_name: "<?= str_replace( '"', '', $this -> product['language']['name'] );?>",
|
||||||
price: <? if ( $this -> product['price_brutto_promo'] ): echo \Shared\Helpers\Helpers::normalize_decimal( $this -> product['price_brutto_promo'] ); else: echo \Shared\Helpers\Helpers::normalize_decimal( $this -> product['price_brutto'] ); endif;?>,
|
price: <? if ( $this -> product['price_brutto_promo'] ): echo \Shared\Helpers\Helpers::normalize_decimal( $this -> product['price_brutto_promo'] ); else: echo \Shared\Helpers\Helpers::normalize_decimal( $this -> product['price_brutto'] ); endif;?>,
|
||||||
quantity: quantity,
|
quantity: parseInt(quantity),
|
||||||
google_business_vertical: "retail"
|
google_business_vertical: "retail"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user