两个像素的WooCommerce转换跟踪脚本 [英] WooCommerce Conversion Tracking Script for two Pixel

查看:133
本文介绍了两个像素的WooCommerce转换跟踪脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过一些会员网络推广我的产品。

I want to promote my products by some affiliate networks.

唯一要做的就是进入function.php文件并添加此脚本与像素。使用此脚本,可以很好地跟踪金额值。此脚本仅适用于一个网络,并且如果您是唯一的供应商。

Do only thing you have to do, is to go into the function.php file and add this script with the pixel. With this script the tracking of the amount value works fine. This script works only for one network and if you are the only vendor.

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>';
}

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

My problem: I have multiple Vendors who are using my plattform for Product delivery / purchase processing.

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

I need to know how i can modify the function file in order to add a working second script for a 2nd pixel if a specific product has been selected and bought.

我在woocommerce中的技能有限,因此我想了解如何在不损害(常规)跟踪的情况下修改脚本。

My it skills in woocommerce are limited, so i would like to understand how to modify the script without harming the (general) tracking.


  1. 如果有人购买了正常产品,则高于上面第一个像素的像素应该触发。

  2. 如果有人购买了产品ID为2004的特定产品-则第二个不同的像素需要触发并忽略第一个像素。

我需要添加第二个功能或修改第一个功能?

Do i need to add a second function or modify the first one?

谢谢

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

将来我可能必须在拖延第三个像素。结构如何?

In the future I will probably have to install a third pixel. How would the structure be?

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

在报价中的会员软件中,可以使用目标像素 和最终像素。

In the affiliate software within the offer a "Target pixel" and the "final pixel" can be used.

某些产品是测试产品,价值€0.00。如果主像素被触发,则即使客户随后购买了该产品,会员也不会获得任何补偿。

Some products are "test products" and have a value of € 0.00. If the main pixel fires, then the affiliate receives no compensation, even if the customer afterwards purchases the product.

在这种情况下,一种目标像素必须为特定产品的版本ID 安装。如果客户决定在购买的测试月份后决定,则应该触发正确的像素。

In this case, a kind of target pixel would have to be installed for the variation ID of a particular product. If the customer decides after the test month for the purchase, then the "right pixel" should fire.

推荐答案

您可以按订单ID列出产品ID,然后您可以应用条件并触发其他像素。

You can get the list of product ID(s) by Order ID, and then you can apply your conditioning and trigger different pixel.

以下是示例代码,可以解决您的查询:

Here is a sample code which should solve your query:

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 文件。

相关问题:如何在WooCommerce订单完成页面中插入Google Merchant Review JS代码

希望这会有所帮助!

这篇关于两个像素的WooCommerce转换跟踪脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆