【问题标题】:WooCommerce Conversion Tracking Script for two Pixel两个像素的 WooCommerce 转换跟踪脚本
【发布时间】:2017-10-14 18:20:27
【问题描述】:

我想通过一些联属网络推广我的产品。

你唯一需要做的就是进入function.php文件并添加这个带有像素的脚本。使用此脚本,金额值的跟踪工作正常。此脚本仅适用于一个网络并且如果您是唯一的供应商。

add_action( 'woocommerce_thankyou', 'my_custom_tracking' );
function my_custom_tracking( $order_id ) {
  $order = new WC_Order( $order_id );
  $total = $order->get_subtotal();
  $id = str_replace('#', '', $order->get_order_number());
  echo '<iframe src="https://network.com/track?offer_id=666&amount=' . $total . '&track_id=' . $id . '" scrolling="no" frameborder="0" width="1" height="1"></iframe>';
}

我的问题:我有多个供应商正在使用我的平台进行产品交付/购买处理。

如果已选择并购买了特定产品,我需要知道如何修改函数文件以便为第二个像素添加一个有效的第二个脚本。

我在 woocommerce 方面的 IT 技能有限,所以我想了解如何在不损害(一般)跟踪的情况下修改脚本。

  1. 如果有人购买了“普通”产品,那么上面的第 1 个像素就会触发。
  2. 如果有人购买产品 ID 为 2004 的特定产品 - 则需要触发第二个不同的像素并忽略第一个像素。

我需要添加第二个函数还是修改第一个函数?

谢谢

其他问题(2017 年 5 月 16 日更新)

将来我可能不得不安装第三个像素。结构如何?

add_action('woocommerce_thankyou', 'wh_custom_tracking');

function wh_custom_tracking($order_id)
{
    $product_ids = [2004, 2000]; //<-- list of product_id(s) for which 2nd pixels should fire
    $checkSecond = FALSE;
    $product_ids = [2003, 2001]; //<-- list of product_id(s) for which 3nd pixels should fire
 $checkThird = FALSE;
    $order = wc_get_order($order_id);
    $total = $order->get_subtotal();
    $id = str_replace('#', '', $order->get_order_number());

    $items = $order->get_items();

    foreach ($items as $item)
    {
        $item_id = $item['product_id']; // <= Here is your product ID
        if (in_array($item_id, $product_ids))

        {
            $checkSecond = TRUE;
            break;
        }

 {
            $checkThird = TRUE;
            break;
        }
    }

    if ($checkSecond)
    {
        //add your 2nd pixel here 2nd pixel
    }
    else

    if ($checkThird)
    {
        //add your 3nd pixel here 2nd pixel
    }
    else
    {
        echo '<iframe src="https://network.com/track?offer_id=666&amount=' . $total . '&track_id=' . $id . '" scrolling="no" frameborder="0" width="1" height="1"></iframe>';
    }
}

同样的结构是否也适用于变体 ID

在优惠内的附属软件中,可以使用“目标像素”和“最终像素”。

有些产品是“测试产品”,价值 0.00 欧元。如果主像素触发,则关联公司不会收到任何补偿,即使客户随后购买了产品。

在这种情况下,必须为特定产品的变体 ID 安装一种目标像素。如果客户在测试月份之后决定购买,那么“正确的像素”应该会触发。

【问题讨论】:

  • 什么是Product_Nr. 2004 是产品属性还是什么?
  • 感谢您的回复。产品 ID 2004 只是 WooCommerce 中的产品 ID。我会在我的帖子中更新这个。

标签: woocommerce tracking hook-woocommerce affiliate


【解决方案1】:

您可以通过Order ID获取产品ID列表,然后您可以应用您的条件并触发不同的像素。

这是一个可以解决您的查询的示例代码:

add_action('woocommerce_thankyou', 'wh_custom_tracking');

function wh_custom_tracking($order_id)
{
    $product_ids = [2004, 2000]; //<-- list of product_id(s) for which 2nd pixels should fire
    $checkSecond = FALSE;
    $order = wc_get_order($order_id);
    $total = $order->get_subtotal();
    $id = str_replace('#', '', $order->get_order_number());

    $items = $order->get_items();

    foreach ($items as $item)
    {
        $item_id = $item['product_id']; // <= Here is your product ID
        if (in_array($item_id, $product_ids))
        {
            $checkSecond = TRUE;
            break;
        }
    }

    if ($checkSecond)
    {
        //add your 2nd pixel here 2nd pixel
    }
    else
    {
        echo '<iframe src="https://network.com/track?offer_id=666&amount=' . $total . '&track_id=' . $id . '" scrolling="no" frameborder="0" width="1" height="1"></iframe>';
    }
}

代码进入您的活动子主题(或主题)的functions.php 文件中。或者也可以在任何插件 php 文件中。

相关问题:How to insert Google Merchant Review JS code in WooCommerce Order Complete page

希望这会有所帮助!

【讨论】:

  • 我在上面添加了更多问题。
猜你喜欢
  • 1970-01-01
  • 2021-03-25
  • 2014-09-12
  • 1970-01-01
  • 2013-10-16
  • 1970-01-01
  • 2011-02-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多