目前,我已经使用piwik在我的wordpress网站上进行了设置跟踪。但是,最重要的是,我需要能够跟踪电子商务转换和废弃的购物车。我设法手动跟踪了转换,但是我不知道如何用“ woocommerce订购的产品”值替换硬编码的值。

到目前为止,我已完成以下操作:


已安装的WP-Piwik
已安装WooCommerce Piwik集成
我创建了名为“ piwik.js”的自定义JavaScript,并对值进行了硬编码以跟踪电子商务购买。

function addEcommerceItem() {
// add the first product to the order
    _paq.push(['addEcommerceItem',
    "sku01", // (required) SKU: Product unique identifier
    "sku01Name", // (optional) Product name
    "productCategory", // (optional) Product category. You can also specify an array of up to 5 categories eg. ["Books", "New releases", "Biography"]
    60, // (recommended) Product price
    1 // (optional, default to 1) Product quantity
    ]);
    alert("e-Commerce item added!");
 };

 function trackEcommerceOrder() {
    _paq.push(['trackEcommerceOrder',
    "A10000127", // (required) Unique Order ID
    35, // (required) Order Revenue grand total (includes tax, shipping, and subtracted discount)
    30, // (optional) Order sub total (excludes shipping)
    5.5, // (optional) Tax amount
    4.5, // (optional) Shipping amount
    false // (optional) Discount offered (set to false for unspecified parameter)
    ]);
  alert("item tracked!");
  };

在我的Woocommerce上,结帐页面:

   [woocommerce_checkout]
   <script type="text/javascript" src="http://myServerIP/mySite/piwik.js"></script>
   <script type="text/javascript">
      addEcommerceItem();
      trackEcommerceOrder();
   </script>

同样,我的问题是我如何替换addEcommerceItem()trackEcommerceOrder()中的硬编码值以动态反映通过woocommerce网站购买的任何产品?


先感谢您

最佳答案

修改后的“ piwik-woocommerce-integration”插件->“ class-wc-piwik-tracker.php”


piwikTracker.addEcommerceItem()及其实现替换为:

//add order
_paq.push(['addEcommerceItem',
   "<?php echo esc_js( $_product->get_sku() ); ?>",
   "<?php echo esc_js( $item['name'] ); ?>",
   "<?php
      if ( isset( $_product->variation_data ) )
         echo esc_js( woocommerce_get_formatted_variation( $_product->variation_data, true ) );
            ?>",
    <?php echo esc_js( $order->get_item_total( $item ) ); ?>,
    <?php echo esc_js( $item['qty'] ); ?>]);

piwikTracker.trackEcommerceOrder()及其实现替换为:

// Track order
_paq.push(['trackEcommerceOrder',
   "<?php echo esc_js( $order->get_order_number() ); ?>",
    <?php echo esc_js( $order->get_total() ); ?>,
    false,
    <?php echo esc_js( $order->get_total_tax() ); ?>,
    <?php echo esc_js( $order->get_shipping() ); ?>,
    false
    ]);
    _paq.push(['trackPageView']);

关于javascript - 如何将Woocommerce与Piwik集成,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22775972/

10-10 18:14