Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
有没有其他方法可以从Prestashop获取数据层?_Prestashop_Google Tag Manager_Google Datalayer - Fatal编程技术网

有没有其他方法可以从Prestashop获取数据层?

有没有其他方法可以从Prestashop获取数据层?,prestashop,google-tag-manager,google-datalayer,Prestashop,Google Tag Manager,Google Datalayer,我试图让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'}',

我试图让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}
{if-isset($page_name)&&$page_name |转义:'html':'UTF-8'=='index'}
数据层推送({
“事件”:“addToCart”,
“电子商务”:{
“currencyCode”:“{$currency->iso|U代码|转义:'html':'UTF-8'}”,
“添加”:{
“产品”:[{
“名称”:“{$product->name |转义:'html':'UTF-8'}”,
“id”:“{$product->id |转义:'html':'UTF-8'}”,
'price':'{$product->getPrice(true,$smarty.const.NULL,2)| round:'2'| escape:'html':'UTF-8'}'
“数量”:1
}]
}
}
});
{/if}
问题是,代码在产品页面上工作,但在索引或签出页面上不工作。从所有这些中,我只得到索引上的“currencyCode”,而对于其他所有内容——“未定义的索引:product in/试图获取in中非对象的属性”。
也许我在索引/签出页面脚本中遗漏了什么?

我想这是因为$product仅在产品页面上可用

在索引中使用$product,您希望得到什么?
对于结帐,您应该使用基于购物车的东西。直接使用$product无法获得任何结果。

其他页面上是否存在包含相关产品数据的$product?@kgrg如何检查?在控制器中?我正在尝试在GTM增强型电子商务的索引和分类页面上获取产品名称、价格和ID。是否要获取畅销书/折扣/家庭特色标签的这些信息?