目前,我使用piwik在我的wordpress网站上设置了跟踪功能。但是,最重要的是,我需要能够跟踪电子商务转换和废弃的购物车。我已设法手动跟踪转换,但我不知道如何使用" woocommerce订购的产品替换硬编码值"值。
到目前为止,我完成了以下工作:
我创建了自定义的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!");
};
在我的Woocommerce上,结帐页面:
[woocommerce_checkout]
<script type="text/javascript" src="http://myServerIP/mySite/piwik.js"></script>
<script type="text/javascript">
addEcommerceItem();
trackEcommerceOrder();
</script>
同样,我的问题是如何替换addEcommerceItem()
和trackEcommerceOrder()
中的硬编码值以反映通过我的woocommerce网站动态购买的任何产品?
提前谢谢
答案 0 :(得分:1)
修改后的'piwik-woocommerce-integration'插件 - &gt; '类-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']);