<?
// много кода, а в конце:
echo '</br>Спасибо за заказ</br>'.$message;
echo "<script>
$(document).ready(function(){
//ga('require', 'ec');
ga('set', '&cu', 'RUB');
<?
$dbBasket = CSaleBasket::GetList(
array('NAME' => 'ASC'),
array('ORDER_ID' => $order_id),
false,
false,
array('ID', 'NAME', 'QUANTITY', 'PRICE', 'CURRENCY', 'PRODUCT_ID')
);
$aCart = Array();
while ($arBasket = $dbBasket->Fetch()) {
if(isset($aCart[$arBasket[PRODUCT_ID]]))
$aCart[$arBasket[PRODUCT_ID]] = $arBasket[QUANTITY] + $aCart[$arBasket[PRODUCT_ID]];
else
$aCart[$arBasket[PRODUCT_ID]] = $arBasket[QUANTITY];
}
$dbBasket = CSaleBasket::GetList(
array('NAME' => 'ASC'),
array('ORDER_ID' => $order_id),
false,
false,
array('ID', 'NAME', 'QUANTITY', 'PRICE', 'CURRENCY', 'PRODUCT_ID')
);
$aCartGoogle = Array();
while ($arBasket = $dbBasket->Fetch()){?>
<?if(!isset($aCartGoogle[$arBasket[PRODUCT_ID]])){?>
ga('ec:addProduct', {
'id': '<?=$arBasket[PRODUCT_ID]?>',
'name': '<?=$arBasket[NAME]?>',
'category': '',
'brand': '',
'variant': '',
'price': '<?=$arBasket[PRICE]?>',
'quantity': <?=$aCart[$arBasket[PRODUCT_ID]]?> // количество товара
});
<?}?>
<?}?>
ga('ec:setAction', 'purchase', {
id: '<?=$order_id?>', // ID заказа
affiliation: '',
revenue: '<?=$_POST[LPRICES]?>', // Общая сумма в рублях
tax: '0.00', // налог
shipping: '0.00', // доставка
coupon: ''
});
ga('send', 'pageview');
})
</script>";
$USER->Logout();
?>