针对WooCommerce订单的Pinterest转换跟踪代码

时间:2017-04-16 16:22:41

标签: javascript woocommerce pinterest event-tracking conversion-tracking

我需要安装Pinterest转换标记,以便从WooCommerce订单动态跟踪'value'和'order_quantity'。 Pinterest标签有两部分Javascript。第1部分是站点标题中的基本代码。第2部分是Checkout标题中的事件代码。

我认为第2部分是下面必须修改的内容(需要更改value和order_quantity以从WooCommerce订单中提取):

<script>
pintrk('track', ' checkout ', {
    value: {{Enhanced Transaction Revenue}},
    order_quantity: {{item.quantity}}
  });
</script>
<noscript>
<img height="1" width="1" style="display:none;" alt="" src=" https://ct.pinterest.com/v3/?tid= 123456789 &event= checkout &noscript=1" /> </noscript>

Pinterest转化标签指南:https://help.pinterest.com/sites/help/files/pinterest_tag_instructions.pdf

我在这一点上绝望,所以任何帮助都会受到高度赞赏......并获得奖励!

1 个答案:

答案 0 :(得分:0)

将它放在你的functions.php中,然后更改Your_Tag_ID以匹配你从Pinterest获得的标签ID。

add_action( 'woocommerce_thankyou', 'pinterest_tracking' );

function pinterest_tracking( $order_id ) {

// Lets grab the order
$order = wc_get_order( $order_id );

/**
 * Put your tracking code here
 * You can get the order total etc e.g. $order->get_total();
 */

// This is the order total
$order_total = $order->get_total();
$order_quantity = $order->get_item_count();

?>

<script>
    pintrk('track', 'checkout', {
        {
            value: '<?php echo $order_total ?>',
            order_quantity: '<?php echo $order_quantity ?>',
            currency: 'USD'
        }
    ]);
</script>
<noscript>
<img height="1" width="1" style="display:none;" alt="" src="https://ct.pinterest.com/v3/?tid=Your_Tag_ID&event=checkout&ed[value]=<?php echo $order_total ?>&ed[order_quantity]=<?php echo $order_quantity ?>&noscript=1"/>
</noscript>
<?php

}

这是帮助我的两个链接:

https://docs.woocommerce.com/document/custom-tracking-code-for-the-thanks-page/

https://developers.pinterest.com/docs/ad-tools/conversion-tag/