dsapkqaduj6718493 2014-04-01 02:56 采纳率: 100%
浏览 15
已采纳

如何将Woocommerce与Piwik集成

Currently, I have setup tracking on my wordpress website using piwik. However, on top of that, I need to be able to track the e-commerce conversion and abandoned cart. I have managed to track the conversion manually but I have no idea on how do I replace the hardcoded values with the "woocommerce ordered products" values.

Here are what have I done so far:

  1. Installed WP-Piwik
  2. Installed WooCommerce Piwik integration
  3. I created my custom javascript, called "piwik.js", and I hardcoded the values to track e-commerce purchases.

    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!");
      };
    
  4. On my Woocommerce, checkout page:

       [woocommerce_checkout]
       <script type="text/javascript" src="http://myServerIP/mySite/piwik.js"></script>
       <script type="text/javascript">
          addEcommerceItem(); 
          trackEcommerceOrder(); 
       </script>
    
  5. And again, my question was how do I replace hardcoded values in addEcommerceItem() and trackEcommerceOrder() to reflect whatever products being purchased through my woocommerce site dynamically?

Thank you in advance

  • 写回答

1条回答 默认 最新

  • dsvjw20866 2014-04-02 09:19
    关注

    Modified 'piwik-woocommerce-integration' plugin -> 'class-wc-piwik-tracker.php'

    1. Replaced piwikTracker.addEcommerceItem() and its implementation with:

      //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'] ); ?>]);
      
    2. Replaced piwikTracker.trackEcommerceOrder() and its implementation with:

      // 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']);
      
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值