部署(非Google Analytics)电子商务跟踪代码 - Woocommerce

时间:2016-04-29 21:02:06

标签: javascript google-analytics transactions woocommerce analytics

希望你能帮忙......

我们有一个Wordpress / Woocommerce商店 - 所有商店都通过插件设置和配置Google Analytics电子商务。我们有第三方CRM /营销工具,它还要求电子商务跟踪脚本将交易记录为已关闭的机会。

与Google Analytics非常相似,有三种方法  1.创建一个事务对象  2.将项目添加到事务中  3.告诉CRM交易完成

我通过将示例部署为插件来测试这一切。我正在获取一些数据到CRM,如总价和客户名称。

我无法解决的问题是; a)获取产品名称信息 b)获取产品类别信息 c)通过一个以上的产品通过,即拆分订单,以便显示篮子中的每个产品

  <?php
    /**
    * Plugin Name: eCommerce Tracking
    * Plugin URI: 
    * Description: Send shopping data to CRM
     * Version: 1.0
    * Author: fly
* Author URI: 
* License: GPL2
*/

add_action( 'woocommerce_thankyou', 'my_custom_tracking' );
function my_custom_tracking( $order_id ) {



// Lets grab the order
$order = new WC_Order( $order_id );

// Order ID
$order_id = $order->get_order_number();

// Order total
$order_total = $order->get_total();

// Order e-mail
$order_email = $order->billing_email;

// Order Billing First Name
$order_fname = $order->billing_first_name;

// Order Billing Last Name
$order_lname = $order->billing_last_name;

// Order Billing Address 1
$order_bill1 = $order->billing_address_1;

// Order Billing Address 2
$order_bill2 = $order->billing_address_2;

// Billing City
$order_billcity = $order->billing_city;

// Billing State
$order_billstate = $order->billing_state;

// Billing Postcode
$order_billpostcode = $order->billing_postcode;

// Billing Country
$order_billcountry = $order->billing_country;

// Billing Phone
$order_billphone = $order->billing_phone;

// Order Tax Cost
$order_tax = $order->order_tax;

// Order Shipping Cost
$order_shippingcost = $order->order_shipping;

// Order Currency
$order_currency = $order->order_currency;

// Product Category
$order_category = $order->term_id;

// Product Name
$order_product = $order->item_id;

// Product Quantity
$order_quantity = $order->quantity;

// Product SKU
$order_sku = $order->sku;

// Product Price
$order_price = $order->price;


?>



<!-- Start Tracking code -->
<script type="text/javascript">
var _ss = _ss || [];
_ss.push(['_setDomain', 'xxxxxxxx']);
_ss.push(['_setAccount', 'xxxxxxx']);
_ss.push(['_trackPageView']);
(function() {
var ss = document.createElement('script');
ss.type = 'text/javascript'; ss.async = true;

ss.src = ('https:' == document.location.protocol ? 'https://' :     
'http://') + 'koi-3Q40EJNC5K.marketingautomation.services/client/ss.js?  
ver=1.1.1';
var scr = document.getElementsByTagName('script')[0];
scr.parentNode.insertBefore(ss, scr);
})();
</script>



<script type='text/javascript'>

_ss.push(['_setTransaction', {
    'transactionID': '<?php echo $order_id; ?>',
    'storeName': 'Reco Surfaces',
    'total': '<?php echo $order_total; ?>',
    'tax': '<?php echo $order_tax; ?>',
    'shipping': '<?php echo $order_shippingcost; ?>',
    'city': '<?php echo $order_billcity; ?>',
    'state': '<?php echo $order_billstate; ?>',
    'zipcode': '<?php echo $order_billpostcode; ?>',
    'country': 'UK',
    'firstName' : '<?php echo $order_fname; ?>', 
    'lastName' : '<?php echo $order_lname; ?>', 
    'emailAddress' : '<?php echo $order_email ?>' 
}, function() {

    _ss.push(['_addTransactionItem', {
        'transactionID': '<?php echo $order_id; ?>',
        'itemCode': '<?php echo $order_sku; ?>',
        'productName': '<?php echo $order_product; ?>',
        'category': '<?php echo $order_category; ?>',
        'price': '<?php echo $order_price; ?>',
        'quantity': '<?php echo $order_quantity; ?>'
    }]);

    _ss.push(['_completeTransaction', {
        'transactionID': '<?php echo $order_id; ?>'
    }]);

}]);

</script>


 <!-- End Tracking code -->
 <?php
 }

0 个答案:

没有答案