转换跟踪添加到购物车按钮woocommerce
问题描述:
我想添加一个谷歌的AdWords标签,到广告购物车按钮来跟踪转换。 我需要把它放在哪里?转换跟踪添加到购物车按钮woocommerce
还是我完全在旁边,我必须以不同的方式解决它?如果有人能帮助我,将是非常好的:)
这是代码:
<script type="text/javascript">
/* <![CDATA[ */
goog_snippet_vars = function() {
var w = window;
w.google_conversion_id = ***************;
w.google_conversion_label = "************";
w.google_remarketing_only = false;
}
// DO NOT CHANGE THE CODE BELOW.
goog_report_conversion = function(url) {
goog_snippet_vars();
window.google_conversion_format = "3";
var opt = new Object();
opt.onload_callback = function() {
if (typeof(url) != 'undefined') {
window.location = url;
}
}
var conv_handler = window['google_trackConversion'];
if (typeof(conv_handler) == 'function') {
conv_handler(opt);
}
}
/* ]]> */
</script>
<script type="text/javascript"
src="//www.googleadservices.com/pagead/conversion_async.js">
</script>
这就是我想要把它:
/wp-content/plugins/woocommerce/templates /单品/ add-to-cart/simple.php
<?php
if (! defined('ABSPATH')) {
\t exit;
}
global $product;
if (! $product->is_purchasable()) {
\t return;
}
echo wc_get_stock_html($product);
if ($product->is_in_stock()) : ?>
\t <?php do_action('woocommerce_before_add_to_cart_form'); ?>
\t <form class="cart" method="post" enctype='multipart/form-data'>
\t \t <?php
\t \t \t /**
\t \t \t * @since 2.1.0.
\t \t \t */
\t \t \t do_action('woocommerce_before_add_to_cart_button');
\t \t \t /**
\t \t \t * @since 3.0.0.
\t \t \t */
\t \t \t do_action('woocommerce_before_add_to_cart_quantity');
\t \t \t woocommerce_quantity_input(array(
\t \t \t \t 'min_value' => apply_filters('woocommerce_quantity_input_min', $product->get_min_purchase_quantity(), $product),
\t \t \t \t 'max_value' => apply_filters('woocommerce_quantity_input_max', $product->get_max_purchase_quantity(), $product),
\t \t \t \t 'input_value' => isset($_POST['quantity']) ? wc_stock_amount($_POST['quantity']) : $product->get_min_purchase_quantity(),
\t \t \t));
\t \t \t /**
\t \t \t * @since 3.0.0.
\t \t \t */
\t \t \t do_action('woocommerce_after_add_to_cart_quantity');
\t \t ?>
\t \t <button type="submit" name="add-to-cart" value="<?php echo esc_attr($product->get_id()); ?>" class="single_add_to_cart_button button alt"><?php echo esc_html($product->single_add_to_cart_text()); ?></button>
\t \t <?php
\t \t \t /**
\t \t \t * @since 2.1.0.
\t \t \t */
\t \t \t do_action('woocommerce_after_add_to_cart_button');
\t \t ?>
\t </form>
\t <?php do_action('woocommerce_after_add_to_cart_form'); ?>
<?php endif; ?>
答
我会跟踪这个转换使用JavaScript jQueryon添加到购物车按钮点击:
$(".single_add_to_cart_button").click(function{
ga('send', 'event', {
eventCategory: 'category',
eventAction: 'action',
eventLabel: 'label',
eventValue: number
});
window.google_trackConversion({
google_conversion_id: xxxxxxxxx,
google_conversion_language: "en",
google_conversion_format: "3",
google_conversion_color: "ffffff",
google_conversion_label: "conversion label",
google_remarketing_only: false
});
});
确保添加异步谷歌分析。
<script type="text/javascript" src="http://www.googleadservices.com/pagead/conversion_async.js" charset="utf-8"></script>
对不起,第一个标记是检查页面是否被加载,第二个标记是检查什么时候被点击。 –
感谢您的帮助!!!!!!!我真的很感激它!,你可以请我的quastion与好标签? –
只需在您的分析中创建一个新的转换并使用我的代码,我不知道您使用的是什么类型的代码。我一直在使用我的例子:) –