GTM doesn't recognize my dataLayer but console does?

我的梦境 提交于 2019-12-25 08:00:50

问题


So I have a dataLayer created that works just fine when using the console in Chrome:

In Google Tag Manager, this dataLayer doesn't exist. Why?

The code I've used is below:

<script>

<?php
    global $woocommerce;
    $items = $woocommerce->cart->get_cart();
    $dataLayer = [];
    foreach($items as $item => $values) { 
         $_product = $values['data']->post;
?>

<?php
         $dataLayer[] = [
    'itemUnitID' => $_product->ID,
              'itemUnitPrice' => get_post_meta($values['product_id'] , '_price', true),
              'itemQuantity' => $values[quantity]


         ];

     }; 

?>
window.dataLayer = window.dataLayer || [];
window.dataLayer.push(<?php echo json_encode($dataLayer); ?>);

</script>

So basically the code is shooting a dataLayer, but I can't use any of those values in Google Tag Manager as GTM doesn't even recognize the dataLayer in the first place. Why is that?

来源:https://stackoverflow.com/questions/40137320/gtm-doesnt-recognize-my-datalayer-but-console-does

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!