如何将Woocommerce与Piwik集成

时间:2014-04-01 02:56:49

标签: javascript php wordpress woocommerce matomo

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

到目前为止,我完成了以下工作:

  1. 安装WP-Piwik
  2. 已安装WooCommerce Piwik集成
  3. 我创建了自定义的javascript,名为" piwik.js",我对这些值进行了硬编码以跟踪电子商务购买情况。

    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. 在我的Woocommerce上,结帐页面:

       [woocommerce_checkout]
       <script type="text/javascript" src="http://myServerIP/mySite/piwik.js"></script>
       <script type="text/javascript">
          addEcommerceItem(); 
          trackEcommerceOrder(); 
       </script>
    
  5. 同样,我的问题是如何替换addEcommerceItem()trackEcommerceOrder()中的硬编码值以反映通过我的woocommerce网站动态购买的任何产品?

  6. 提前谢谢

1 个答案:

答案 0 :(得分:1)

修改后的'piwik-woocommerce-integration'插件 - &gt; '类-WC-piwik-tracker.php'

  1. 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'] ); ?>]);
    
  2. 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']);