按鈕:谷歌標記管理工具觸發
<button id="btnBuy" onclick="SendData();"
JavaScript函數:
<script>
// Measure a view of product details. This example assumes the detail view occurs on pageload,
// and also tracks a standard pageview of the details page.
var dataLayer = [];
dataLayer.push({
'ecommerce': {
'detail': {
'actionField': {'list': 'Apparel Gallery'}, // 'detail' actions have an optional list property.
'products': [{
'name': '@GetString("Ecom:Product.Name")', // Name or ID is required.
'id': '@GetValue("Ecom:Product.Number")',
'price': '@GetValue("Ecom:Product.ActualPriceWithVAT")',
'brand': '@GetString("Ecom:Manufacturer.Name")',
'category': 'PRODUCT_CATEGORY'
}]
}
}
});
function SendData()
{
var purchaseData =
dataLayer.push({
'event': 'addToCart',
'ecommerce': {
'currencyCode': 'SEK',
'add': { // 'add' actionFieldObject measures.
'products': [{ // adding a product to a shopping cart.
'name': '@GetString("Ecom:Product.Name")',
'id': '@GetValue("Ecom:Product.Number")',
'price': '@GetValue("Ecom:Product.ActualPriceWithVAT")',
'brand': '@GetString("Ecom:Manufacturer.Name")',
'category': 'Apparel',
'variant': $j('input[name=radioDim1]:checked').val(),
'quantity': $j('#QuantitySelector option:selected').val(),
'size': $j('input[name=radioDim2]:checked').closest('label').text()
}]
}
}
});
return purchaseData;
}
</script>
標籤信息: 追蹤:事件 類別:添加到購物車 行動:{{事件} } 標籤:{{頁面路徑}}
觸發器: 事件等於addToCart
我在Chrome中使用預覽模式,即使它註冊了我的點擊事件,它也沒有說觸發器被觸發。
對我來說這沒有任何意義。我必須將該變量聲明爲空數組,然後將該對象推入該數組中。它不是如何完成的? 當有人向購物車中添加產品時,調用SendData函數怎麼樣?購買變量是否應該返回或者是否足以將另一個對象添加到數組中? –