【发布时间】:2019-07-08 20:28:50
【问题描述】:
我正在尝试让 GTM 和数据层使用以下代码:
{if isset($page_name) && $page_name|escape:'html':'UTF-8' == "index"}
<script>
dataLayer.push({
'event': 'addToCart',
'ecommerce': {
'currencyCode': '{$currency->iso_code|escape:'html':'UTF-8'}',
'add': {
'products': [{
'name': '{$product->name|escape:'html':'UTF-8'}',
'id': ' {$product->id|escape:'html':'UTF-8'}',
'price': '{$product->getPrice(true, $smarty.const.NULL, 2)|round:'2'|escape:'html':'UTF-8'}'
'quantity': 1
}]
}
}
});
</script>
{/if}
问题是,该代码适用于产品页面,但不适用于索引或结帐页面。从所有这些中,我只在索引上获得“currencyCode”,而对于其他所有内容 - “未定义的索引:产品/试图获取非对象的属性”。 也许我在索引/结帐页面脚本中遗漏了一些东西?
【问题讨论】:
-
其他页面上是否存在 $product,包含相关的产品数据?
-
@kgrg 我如何检查它?在控制器中?
标签: prestashop google-tag-manager google-datalayer