▼テンプレート
[EC-CUBE] EC-CUBEのバージョン、新規インストールかアップデートか、等
[レンタルサーバ] Xserver
[OS] windows10
[ブラウザ] 114.0.5735.110(Official Build) (64 ビット)
[カスタマイズの有無] ブロックに下記のコードをを入れて、全てのページのヘッダーに設置しています。
コード
{% if app.request.get('_route') == 'product_list' %}
{# 商品一覧 #}
<script>
dataLayer.push({ecommerce: null});
// GA4
dataLayer.push({
'event': 'view_item_list',
'ecommerce': {
'items': [
{% for Product in pagination %}
{
'item_name': '{{ Product.name }}',
'item_id': '{{ Product.getCodeMin ? Product.getCodeMin : Product.id }}',
'price': '{{ Product.getPrice02IncTaxMin }}',
}{% if not loop.last %},{% endif %}
{% endfor %}
]
}
});
// UA
dataLayer.push({
'ecommerce': {
'currencyCode': 'JPY',
'impressions': [
{% for Product in pagination %}
{
'name': '{{ Product.name }}',
'id': '{{ Product.getCodeMin ? Product.getCodeMin : Product.id }}',
'price': '{{ Product.getPrice02IncTaxMin }}',
}{% if not loop.last %},{% endif %}
{% endfor %}
]
}
});
</script>
{% elseif app.request.get('_route') == 'product_detail' %}
{# 商品詳細 #}
<script>
dataLayer.push({ecommerce: null});
// GA4
dataLayer.push({
'event': 'view_item',
'ecommerce': {
'items': [{
'item_name': '{{ Product.name }}',
'item_id': '{{ Product.getCodeMin ? Product.getCodeMin : Product.id }}',
'price': '{{ Product.getPrice02IncTaxMin }}',
'item_category': '{% for ProductCategory in Product.ProductCategories %}{% for Category in ProductCategory.Category.path %}{% if ( Category.parent is not null ) %}{{ Category.Parent.name }}:{{ Category.name }}{% endif %}{% endfor %}{% endfor %}',
'quantity': '1'
}]
}
});
// UA
dataLayer.push({
'ecommerce': {
'detail': {
'products': [{
'name': '{{ Product.name }}',
'id': '{{ Product.getCodeMin ? Product.getCodeMin : Product.id }}',
'price': '{{ Product.getPrice02IncTaxMin }}',
'category': '{% for ProductCategory in Product.ProductCategories %}{% for Category in ProductCategory.Category.path %}{% if ( Category.parent is not null ) %}{{ Category.Parent.name }}:{{ Category.name }}{% endif %}{% endfor %}{% endfor %}',
}]
}
}
});
</script>
{% elseif app.request.get('_route') == 'cart' %}
{# カートに追加 #}
<script>
dataLayer.push({ecommerce: null});
// GA4
dataLayer.push({
'event': 'add_to_cart',
'ecommerce': {
'items': [
{% for CartItem in Cart.CartItems %}
{% set ProductClass = CartItem.Object %}
{% set Product = ProductClass.Product %}
{
'item_name': '{{ Product.name }}',
'item_id': '{{ Product.getCodeMin ? Product.getCodeMin : Product.id }}',
'price': '{{ Product.getPrice02IncTaxMin }}'
}{% if not loop.last %},{% endif %}
{% endfor %}
]
}
});
// UA
dataLayer.push({
'event': 'addToCart',
'ecommerce': {
'currencyCode': 'JPY',
'add': {
'products': [
{% for CartItem in Cart.CartItems %}
{% set ProductClass = CartItem.Object %}
{% set Product = ProductClass.Product %}
{
'name': '{{ Product.name }}',
'id': '{{ Product.getCodeMin ? Product.getCodeMin : Product.id }}',
'price': '{{ Product.getPrice02IncTaxMin }}',
'quantity': {{ CartItem.quantity }}
}{% if not loop.last %},{% endif %}
{% endfor %}
]
}
}
});
</script>
{% elseif app.request.get('_route') == 'shopping_complete' %}
{# 購入完了 #}
{% if Order.id %}
<script>
dataLayer.push({ecommerce: null});
// GA4
dataLayer.push({
'event': 'purchase',
'ecommerce': {
'transaction_id': '{{ Order.id }}',
'affiliation': '{{ BaseInfo.shop_name }}',
'value': '{{ Order.subtotal }}',
'tax': '{{ Order.tax }}',
'shipping': '{{ Order.delivery_fee_total }}',
'currency': 'JPY',
'items': [
{% for OrderDetail in Order.OrderDetails %}
{
'item_name': '{{ OrderDetail.product_name }}',
'item_id': '{{ OrderDetail.product_code ? OrderDetail.product_code : OrderDetail.product.id }}',
'price': '{{ OrderDetail.price_inc_tax }}',
'item_category': '{% for ProductCategory in OrderDetail.Product.ProductCategories %}{% for Category in ProductCategory.Category.path %}{% if ( Category.parent is not null ) %}{{ Category.Parent.name }}:{{ Category.name }}{% endif %}{% endfor %}{% endfor %}',
'quantity': {{ OrderDetail.quantity }}
}{% if not loop.last %},{% endif %}
{% endfor %}
]
}
});
// UA
dataLayer.push({
'ecommerce': {
'purchase': {
'actionField': {
'id': '{{ Order.id }}',
'affiliation': '{{ BaseInfo.shop_name }}',
'revenue': '{{ Order.subtotal }}',
'tax': '{{ Order.tax }}',
'shipping': '{{ Order.delivery_fee_total }}'
},
'products': [
{% for OrderDetail in Order.OrderDetails %}
{
'name': '{{ OrderDetail.product_name }}',
'id': '{{ OrderDetail.product_code ? OrderDetail.product_code : OrderDetail.product.id }}',
'price': '{{ OrderDetail.price_inc_tax }}',
'category': '{% for ProductCategory in OrderDetail.Product.ProductCategories %}{% for Category in ProductCategory.Category.path %}{% if ( Category.parent is not null ) %}{{ Category.Parent.name }}:{{ Category.name }}{% endif %}{% endfor %}{% endfor %}',
'quantity': {{ OrderDetail.quantity }}
}{% if not loop.last %},{% endif %}
{% endfor %}
]
}
}
});
</script>
{% endif %}
{% endif %}
[現象] タグマネージャーでフィルタがEventが『add_to_cart』に等しい、というトリガーを作成。
新たなタグで、イベント名が{{Event}}で、トリガーは上記のトリガーを設定したタグを設置。
しかし、発火しません。
また、GA4のフォルダの中にある、e コマース購入数: アイテム名にも表示されません。
どのようにしたら、カートに追加された商品数をGA4で確認することができるようになるでしょうか?