为Woocommerce实现增强型电子商务(无插件)

时间:2016-10-04 08:01:18

标签: php wordpress google-analytics woocommerce enhanced-ecommerce

我正在尝试为WooCommerce管理的电子商务网站实施增强型电子商务(目前使用版本2.4.11 ,无需更新),而不使用WooCommerce增强型电子商务插件

我该怎么做?到目前为止,我有这个:

<script>

(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
    m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-68273318-1', 'auto');
ga('require','ec');
ga('ec:addProduct', {                 // Provide product details in an productFieldObject.
  'id': '<?php the_ID(); ?>',                     // Product ID (string).
  'name': '<?php do_action( 'htb_woocommerce_shop_loop_item_title' );?>',  // Product name (string).
});
ga('ec:setAction', 'detail');       // Detail action.
ga('send', 'pageview');

</script>

它正在输出正确的ID和名称,但这是我需要做的吗?如何获得产品列表中的productImpressions和点击次数?

0 个答案:

没有答案