Facebook Pixel 无法在 iOS 移动设备 (Wordpress/Woocommerce) 上运行
Facebook Pixel not working on iOS mobile (Wordpress/Woocommerce)
我正在使用 Wordpress
(v 5.3
) 和 WooCommerce
(v 3.8.1
)。我的 Facebook Pixel 在桌面上注册事件 (ViewContent/InitiateCheckout/AddToCart/Purchase/etc.),但在移动设备上不注册事件 (iOS)。我所有的插件和主题都是最新的。对于我的主题,我使用 Youplay
(v 3.7.4
).
在寻找答案的过程中,我注意到一些人遇到了主题阻碍 Facebook Pixel
在移动设备上工作的问题 - 有些人报告说需要在 functions.php
中注释掉一行 -我包括了我的主题 functions.php
,以防有人注意到任何可能与 Facebook Pixel
在移动设备上工作的冲突(在我发现的帖子中,没有人使用与我相同的主题):
functions.php
<?php
/**
* Youplay functions and definitions
*
* @package Youplay
*/
add_action( 'after_setup_theme', 'yp_setup' );
if ( ! function_exists( 'yp_setup' ) ) :
/**
* Sets up theme defaults and registers support for various WordPress features.
*
* Note that this function is hooked into the after_setup_theme hook, which
* runs before the init hook. The init hook is too late for some features, such
* as indicating support for post thumbnails.
*/
function yp_setup() {
/*
* Make theme available for translation.
* Translations can be filed in the /languages/ directory.
* If you're building a theme based on Youplay, use a find and replace
* to change 'youplay' to the name of your theme in all the template files
*/
load_theme_textdomain( 'youplay', get_template_directory() . '/languages' );
// Add default posts and comments RSS feed links to head.
add_theme_support( 'automatic-feed-links' );
/*
* Let WordPress manage the document title.
* By adding theme support, we declare that this theme does not use a
* hard-coded <title> tag in the document head, and expect WordPress to
* provide it for us.
*/
add_theme_support( 'title-tag' );
// Add editor style support.
add_editor_style();
/*
* Enable support for Post Thumbnails on posts and pages.
*
* @link http://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails
*/
// This theme uses wp_nav_menu() in one location.
register_nav_menus( array(
'primary' => esc_html__( 'Primary Menu', 'youplay' ),
'primary-right' => esc_html__( 'Primary Right Menu', 'youplay' ),
) );
/*
* Switch default core markup for search form, comment form, and comments
* to output valid HTML5.
*/
add_theme_support( 'html5', array(
'search-form', 'comment-form', 'comment-list', 'gallery', 'caption',
) );
/*
* Enable support for WooCommerce
*/
add_theme_support( 'woocommerce' );
// Add default image sizes
add_theme_support('post-thumbnails');
add_image_size('500x375', 500);
add_image_size('500x375_crop', 500, 375, true);
add_image_size('200x200', 200, 200, true);
add_image_size('90x90', 90, 90, true);
add_image_size('1440x900', 1440);
add_image_size('1440x900_crop', 1440, 900, true);
add_image_size('1920x1080', 1920);
// Register the three useful image sizes for use in Add Media modal
add_filter( 'image_size_names_choose', 'yp_custom_sizes' );
if ( ! function_exists( 'yp_custom_sizes' ) ) :
function yp_custom_sizes( $sizes ) {
return array_merge( $sizes, array(
'500x375_crop' => esc_html__( 'Carousel Thumbnail (500x375 crop)', 'youplay' ),
'500x375' => esc_html__( 'Carousel Thumbnail (500x375)', 'youplay' ),
'200x200' => esc_html__( 'User Avatar (200x200 crop)', 'youplay' ),
'90x90' => esc_html__( 'User Small Avatar (90x90 crop)', 'youplay' ),
'1440x900_crop' => esc_html__( '1440x900 crop', 'youplay' ),
'1440x900' => esc_html__( '1440x900', 'youplay' ),
'1920x1080' => esc_html__( '1920x1080', 'youplay' ),
) );
}
endif;
}
endif; // yp_setup
/**
* Set the content width in pixels, based on the theme's design and stylesheet.
*/
if (!isset($content_width)) {
$content_width = 1400;
}
/**
* Register widget area.
*
* @link http://codex.wordpress.org/Function_Reference/register_sidebar
*/
add_action( 'widgets_init', 'yp_widgets_init' );
if ( ! function_exists( 'yp_widgets_init' ) ) :
function yp_widgets_init() {
register_sidebar( array(
'name' => esc_html__( 'Sidebar', 'youplay' ),
'id' => 'sidebar-1',
'description' => esc_html__( 'Default Sidebar', 'youplay' ),
'before_widget' => '<div id="%1$s" class="side-block widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h4 class="widget-title block-title">',
'after_title' => '</h4>',
) );
register_sidebar( array(
'name' => esc_html__( 'WooCommerce Sidebar', 'youplay' ),
'id' => 'woocommerce_sidebar',
'description' => esc_html__( 'Sidebar for WooCommerce Pages', 'youplay' ),
'before_widget' => '<div id="%1$s" class="side-block widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h4 class="widget-title block-title">',
'after_title' => '</h4>',
) );
register_sidebar( array(
'name' => esc_html__( 'BuddyPress Sidebar', 'youplay' ),
'id' => 'buddypress_sidebar',
'description' => esc_html__( 'Sidebar for BuddyPress Pages', 'youplay' ),
'before_widget' => '<div id="%1$s" class="side-block widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h4 class="widget-title block-title">',
'after_title' => '</h4>',
) );
register_sidebar( array(
'name' => esc_html__( 'bbPress Sidebar', 'youplay' ),
'id' => 'bbpress_sidebar',
'description' => esc_html__( 'Sidebar for bbPress Pages', 'youplay' ),
'before_widget' => '<div id="%1$s" class="side-block widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h4 class="widget-title block-title">',
'after_title' => '</h4>',
) );
register_sidebar( array(
'name' => esc_html__( 'Matches Sidebar', 'youplay' ),
'id' => 'matches_sidebar',
'description' => esc_html__( 'Sidebar for Matches Pages', 'youplay' ),
'before_widget' => '<div id="%1$s" class="side-block widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h4 class="widget-title block-title">',
'after_title' => '</h4>',
) );
register_sidebar( array(
'name' => esc_html__( 'Footer Widgets 1', 'youplay' ),
'id' => 'footer_widgets_1',
'description' => esc_html__( 'Footer Widgets 1 Column', 'youplay' ),
'before_widget' => '<div id="%1$s" class="side-block widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h4 class="widget-title block-title">',
'after_title' => '</h4>',
) );
register_sidebar( array(
'name' => esc_html__( 'Footer Widgets 2', 'youplay' ),
'id' => 'footer_widgets_2',
'description' => esc_html__( 'Footer Widgets 2 Column', 'youplay' ),
'before_widget' => '<div id="%1$s" class="side-block widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h4 class="widget-title block-title">',
'after_title' => '</h4>',
) );
register_sidebar( array(
'name' => esc_html__( 'Footer Widgets 3', 'youplay' ),
'id' => 'footer_widgets_3',
'description' => esc_html__( 'Footer Widgets 3 Column', 'youplay' ),
'before_widget' => '<div id="%1$s" class="side-block widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h4 class="widget-title block-title">',
'after_title' => '</h4>',
) );
register_sidebar( array(
'name' => esc_html__( 'Footer Widgets 4', 'youplay' ),
'id' => 'footer_widgets_4',
'description' => esc_html__( 'Footer Widgets 4 Column', 'youplay' ),
'before_widget' => '<div id="%1$s" class="side-block widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h4 class="widget-title block-title">',
'after_title' => '</h4>',
) );
}
endif;
/**
* Enqueue scripts and styles.
*/
add_action( 'wp_enqueue_scripts', 'yp_scripts' );
if ( ! function_exists( 'yp_scripts' ) ) :
function yp_scripts() {
wp_enqueue_style( 'youplay', get_template_directory_uri() . '/style.css', '', '3.7.4' );
wp_enqueue_style( 'bootstrap', get_template_directory_uri() . '/assets/vendor/bootstrap/dist/css/bootstrap.min.css', '', '3.3.7' );
wp_enqueue_style( 'magnific-popup', get_template_directory_uri() . '/assets/vendor/magnific-popup/dist/magnific-popup.css', '', '1.1.0' );
wp_enqueue_style( 'flickity', get_template_directory_uri() . '/assets/vendor/flickity/dist/flickity.min.css', '', '2.2.0' );
// deregister bbPress styles
wp_deregister_style( 'bbp-default' );
wp_register_style( 'bbp-default', get_template_directory_uri() . '/assets/css/bbpress-styles.css' );
// theme style
$theme_style = yp_opts('theme_style');
$youplay_style_file = '';
$youplay_style_version = '3.7.4';
if ($theme_style === 'custom') {
youplay_maybe_compile_scss();
if ( function_exists('nk_theme') ) {
$youplay_style_file = nk_theme()->get_compiled_css_url('youplay-custom.min.css');
$youplay_style_version = nk_theme()->get_compiled_css_version('youplay-custom.min.css');
}
if (!$youplay_style_file) {
$theme_style = 'dark';
}
}
if($theme_style !== 'custom') {
$youplay_style_file = get_template_directory_uri() . '/assets/css/youplay-' . $theme_style . '.min.css';
}
wp_enqueue_style('youplay-' . $theme_style, $youplay_style_file, array(), $youplay_style_version);
// rtl
if(yp_opts('general_rtl')) {
wp_enqueue_style( 'youplay-rtl', get_template_directory_uri() . '/assets/css/youplay-rtl.min.css', '', '3.7.4' );
}
wp_enqueue_script( 'bootstrap', get_template_directory_uri() . '/assets/vendor/bootstrap/dist/js/bootstrap.min.js', array('jquery'), '3.3.7', true );
wp_enqueue_script( 'font-awesome', get_template_directory_uri() . '/assets/vendor/fontawesome-free/js/all.js', array(), '5.9.0', true );
wp_enqueue_script( 'font-awesome-v4-shims', get_template_directory_uri() . '/assets/vendor/fontawesome-free/js/v4-shims.js', array('font-awesome'), '5.9.0', true );
wp_enqueue_script( 'isotope', get_template_directory_uri() . '/assets/vendor/isotope-layout/dist/isotope.pkgd.min.js', array('jquery', 'imagesloaded'), '3.0.6', true );
wp_enqueue_script( 'jquery-countdown', get_template_directory_uri() . '/assets/vendor/jquery-countdown/dist/jquery.countdown.min.js', array('jquery'), '2.2.0', true );
wp_enqueue_script( 'moment-timezone', get_template_directory_uri() . '/assets/vendor/moment-timezone/builds/moment-timezone-with-data.min.js', array('moment'), '0.5.14', true );
wp_enqueue_script( 'magnific-popup', get_template_directory_uri() . '/assets/vendor/magnific-popup/dist/jquery.magnific-popup.min.js', '', '1.1.0', true );
wp_enqueue_script( 'flickity', get_template_directory_uri() . '/assets/vendor/flickity/dist/flickity.pkgd.min.js', array('jquery', 'imagesloaded'), '2.2.0', true );
wp_enqueue_script( 'object-fit-images', get_template_directory_uri() . '/assets/vendor/object-fit-images/dist/ofi.min.js', '', '3.2.3', true );
wp_enqueue_script( 'jarallax', get_template_directory_uri() . '/assets/vendor/jarallax/dist/jarallax.min.js', '', '1.10.7', true );
wp_enqueue_script( 'skrollr', get_template_directory_uri() . '/assets/vendor/skrollr/dist/skrollr.min.js', '', '0.6.30', true );
wp_enqueue_script( 'hexagon-progress', get_template_directory_uri() . '/assets/vendor/HexagonProgress/jquery.hexagonprogress.min.js', '', '1.2.0', true );
wp_enqueue_script( 'youplay', get_template_directory_uri() . '/assets/js/youplay.min.js', array('jquery', 'bootstrap', 'isotope', 'imagesloaded', 'jquery-countdown', 'magnific-popup', 'flickity', 'object-fit-images', 'jarallax', 'hexagon-progress'), '3.7.4', true );
wp_enqueue_script( 'youplay-wp', get_template_directory_uri() . '/assets/js/youplay-wp.min.js', array('jquery', 'youplay'), '3.7.4', true );
wp_enqueue_script( 'youplay-cf7', get_template_directory_uri() . '/assets/js/youplay-cf7.min.js', array('jquery', 'youplay'), '3.7.4', true );
wp_enqueue_script( 'youplay-init', get_template_directory_uri() . '/assets/js/youplay-init.min.js', array('jquery', 'youplay'), '3.7.4', true );
$dataInit = array(
'enableParallax' => yp_opts('general_parallax'),
'enableFadeBetweenPages' => yp_opts('general_fade_between_pages') && yp_opts('general_preloader')
);
wp_localize_script('youplay-init', 'youplayInitOptions', $dataInit);
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
// Custom CSS
ob_start();
require get_template_directory() . '/inc/head_styles.php';
$custom_css = ob_get_clean();
$custom_css = wp_kses( $custom_css, array( '\'', '\"' ) );
$custom_css = str_replace( '>' , '>' , $custom_css );
wp_add_inline_style( 'youplay-' . $theme_style, $custom_css );
// Custom JS
wp_add_inline_script( 'youplay-init', yp_opts('general_custom_js') );
}
endif;
// Compile SCSS.
if (!function_exists('youplay_maybe_compile_scss')) :
function youplay_maybe_compile_scss() {
if ( yp_opts('theme_style') !== 'custom' || ! function_exists('nk_theme') ) {
return;
}
$theme_colors_from = yp_opts('theme_colors_from') == 'light' ? 'light' : 'dark';
$theme_main_color = yp_opts('theme_main_color');
$theme_back_color = yp_opts('theme_back_color');
$theme_back_grey_color = yp_opts('theme_back_grey_color');
$theme_text_color = yp_opts('theme_text_color');
$theme_primary_color = yp_opts('theme_primary_color');
$theme_success_color = yp_opts('theme_success_color');
$theme_info_color = yp_opts('theme_info_color');
$theme_warning_color = yp_opts('theme_warning_color');
$theme_danger_color = yp_opts('theme_danger_color');
$theme_skew_size = yp_opts('theme_skew_size');
$theme_navbar_height = yp_opts('theme_navbar_height');
$theme_navbar_small_height = yp_opts('theme_navbar_small_height');
$theme_banners_opacity = yp_opts('theme_banners_opacity') / 100;
$theme_images_opacity = yp_opts('theme_images_opacity') / 100;
$theme_images_hover_opacity = yp_opts('theme_images_hover_opacity') / 100;
$theme_data = wp_get_theme();
$theme_parent = $theme_data->parent();
if (!empty($theme_parent)) {
$theme_data = $theme_parent;
}
$theme_version = $theme_data['Version'];
$path = get_template_directory() . '/assets/css/';
$custom_vars = '
@import "_helpers.scss";
@import "_variables.scss";
$theme_version:"' . $theme_version . '";
$theme:' . $theme_colors_from . ';
$main_color:' . $theme_main_color . ';
$back_color:' . $theme_back_color . ';
$back_darken_color:' . ($theme_colors_from == 'light' ? '#FFFFFF' : 'darken($back_color, 13)' ) . ';
$back_grey_color:' . $theme_back_grey_color . ';
$back_darken_grey_color: ' . ($theme_colors_from == 'light' ? 'lighten' : 'darken') . '($back_grey_color, 10);
$text_color:' . $theme_text_color . ';
$text_mute_color: rgba($text_color, 0.5);
$color_primary:' . $theme_primary_color . ';
$color_success:' . $theme_success_color . ';
$color_info:' . $theme_info_color . ';
$color_warning:' . $theme_warning_color . ';
$color_danger:' . $theme_danger_color . ';
$skew_size:' . $theme_skew_size . 'deg;
$banners_opacity:' . $theme_banners_opacity . ';
$images_opacity:' . $theme_images_opacity . ';
$images_hover_opacity:' . $theme_images_hover_opacity . ';
$navbar-height:' . $theme_navbar_height . 'px;
$navbar-sm-height:' . $theme_navbar_small_height . 'px;
@import "_includes.scss"';
nk_theme()->scss('youplay-custom.min.css', $path, $custom_vars);
}
endif;
add_action('ot_after_theme_options_save', 'youplay_maybe_compile_scss');
/**
* Admin References
*/
require get_template_directory() . '/admin/admin.php';
/**
* Custom functions that act independently of the theme templates.
*/
require get_template_directory() . '/inc/extras.php';
/**
* Colors convert functions
*/
require get_template_directory() . '/inc/colors.php';
/**
* Custom template tags for this theme.
*/
require get_template_directory() . '/inc/template-tags.php';
/**
* Comments walker
*/
require get_template_directory() . '/inc/comments-walker.php';
/**
* Custom WooCommerce functions
*/
require get_template_directory() . '/woocommerce/functions.php';
/**
* Custom BuddyPress functions
*/
require get_template_directory() . '/buddypress/functions.php';
/**
* Custom bbPress functions
*/
require get_template_directory() . '/bbpress/functions.php';
/**
* Infinitie Scroll for Posts
*/
require get_template_directory() . '/inc/lib/nk-infinite-scroll/nk-infinitie-scroll.php';
我还发现有人说他们的主题正在删除一个 WooCommerce
挂钩(我相信它是 woocommerce_after_single_product
但我不再确切地读到它了) - 我不确定是否我的主题就是这样做的。
我已验证当我不在移动设备上时,所有 Facebook Pixel
事件都会显示:
您可以看到它正在显示 Receiving activity
并列出了事件。手机上试了一下,说不是Receiving activity
(有黄点),也不报事件。
我在 facebook-commerce-events-tracker.php
中找到了处理事件的源代码,也许其中的内容对移动设备不友好?我只展示我认为可能相关的内容,因为我在这个问题上没有更多的文字空间:
facebook-commerce-events-tracker.php
...
class WC_Facebookcommerce_EventsTracker {
private $pixel;
private static $isEnabled = true;
const FB_PRIORITY_HIGH = 2;
const FB_PRIORITY_LOW = 11;
public function __construct( $user_info ) {
$this->pixel = new WC_Facebookcommerce_Pixel( $user_info );
add_action( 'wp_head', array( $this, 'apply_filters' ) );
// Pixel Tracking Hooks
add_action(
'wp_head',
array( $this, 'inject_base_pixel' )
);
add_action(
'wp_footer',
array( $this, 'inject_base_pixel_noscript' )
);
add_action(
'woocommerce_after_single_product',
array( $this, 'inject_view_content_event' ),
self::FB_PRIORITY_HIGH
);
add_action(
'woocommerce_after_shop_loop',
array( $this, 'inject_view_category_event' )
);
add_action(
'pre_get_posts',
array( $this, 'inject_search_event' )
);
add_action(
'woocommerce_after_cart',
array( $this, 'inject_add_to_cart_redirect_event' )
);
add_action(
'woocommerce_add_to_cart',
array( $this, 'inject_add_to_cart_event' ),
self::FB_PRIORITY_HIGH
);
add_action(
'wc_ajax_fb_inject_add_to_cart_event',
array( $this, 'inject_ajax_add_to_cart_event' ),
self::FB_PRIORITY_HIGH
);
add_action(
'woocommerce_after_checkout_form',
array( $this, 'inject_initiate_checkout_event' )
);
add_action(
'woocommerce_thankyou',
array( $this, 'inject_gateway_purchase_event' ),
self::FB_PRIORITY_HIGH
);
add_action(
'woocommerce_payment_complete',
array( $this, 'inject_purchase_event' ),
self::FB_PRIORITY_HIGH
);
add_action(
'wpcf7_contact_form',
array( $this, 'inject_lead_event_hook' ),
self::FB_PRIORITY_LOW
);
}
...
/**
* Triggers ViewContent product pages
*/
public function inject_view_content_event() {
if ( ! self::$isEnabled ) {
return;
}
global $post;
$product = wc_get_product( $post->ID );
$content_type = 'product_group';
if ( ! $product ) {
return;
}
// if product is a variant, fire the pixel with content_type: product_group
if ( WC_Facebookcommerce_Utils::is_variation_type( $product->get_type() ) ) {
$content_type = 'product';
}
$content_ids = WC_Facebookcommerce_Utils::get_fb_content_ids( $product );
$this->pixel->inject_event(
'ViewContent',
array(
'content_name' => $product->get_title(),
'content_ids' => json_encode( $content_ids ),
'content_type' => $content_type,
'value' => $product->get_price(),
'currency' => get_woocommerce_currency(),
)
);
}
这是上面引用的 inject_event
函数:
/**
* Preferred method to inject events in a page, normally you should use this
* instead of WC_Facebookcommerce_Pixel::build_event()
*/
public function inject_event( $event_name, $params, $method = 'track' ) {
$code = self::build_event( $event_name, $params, $method );
$this->last_event = $event_name;
if ( WC_Facebookcommerce_Utils::isWoocommerceIntegration() ) {
WC_Facebookcommerce_Utils::wc_enqueue_js( $code );
} else {
printf(
'
<!-- Facebook Pixel Event Code -->
<script>
%s
</script>
<!-- End Facebook Pixel Event Code -->
',
$code
);
}
}
我在移动设备上注意到 - 本应包含 Facebook Pixel
代码的部分看起来很奇怪:
<!-- Facebook Pixel Code -->
<noscript>
<img height="1" width="1" style="display:none" alt="fbpx"
src="https://www.facebook.com/tr?id=549560325605747&ev=PageView&noscript=1"/>
</noscript>
<!-- End Facebook Pixel Code -->
上图:为什么 Facebook Pixel 代码应该有一个 img
元素?
编辑:对于上述问题,桌面似乎是一样的,所以我认为这不重要——尽管我不明白它是什么。
我在注入时发现实际事件代码在我的网站上的位置 - 看起来它正在注册为 PageView
,它应该是 ViewContent
- 也许分类是错误是以某种方式导致问题(冲突)?
<!-- WooCommerce Facebook Integration Begin -->
!function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod?
n.callMethod.apply(n,arguments):n.queue.push(arguments)};if(!f._fbq)f._fbq=n;
n.push=n;n.loaded=!0;n.version='2.0';n.queue=[];t=b.createElement(e);t.async=!0;
t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s)}(window,
document,'script','https://connect.facebook.net/en_US/fbevents.js');
<script>
fbq('init', 'xxxxx', {}, {
"agent": "woocommerce-3.8.1-1.9.15"
});
fbq('track', 'PageView', {
"source": "woocommerce",
"version": "3.8.1",
"pluginVersion": "1.9.15"
});
document.addEventListener('DOMContentLoaded', function() {
jQuery && jQuery(function($){
$('body').on('added_to_cart', function(event) {
// Ajax action.
$.get('?wc-ajax=fb_inject_add_to_cart_event', function(data) {
$('head').append(data);
});
});
});
}, false);
</script>
<!-- DO NOT MODIFY -->
<!-- WooCommerce Facebook Integration end -->
这是同一部分在桌面上的样子 - 我注意到它有一个 em
属性,这是我的电子邮件,但在移动版本上没有 - 也许这很重要,需要包括在内网站何时在移动设备上呈现?
fbq('init', 'xxxx', {
"em": "myemail7@gmail.com"
}, {
"agent": "woocommerce-3.8.1-1.9.15"
});
fbq('track', 'PageView', {
"source": "woocommerce",
"version": "3.8.1",
"pluginVersion": "1.9.15"
});
document.addEventListener('DOMContentLoaded', function() {
jQuery && jQuery(function($){
$('body').on('added_to_cart', function(event) {
// Ajax action.
$.get('?wc-ajax=fb_inject_add_to_cart_event', function(data) {
$('head').append(data);
});
});
});
}, false);
**编辑:**对于上面的内容,我了解到电子邮件在那里是因为我是我计算机上该网站的用户,但不是我的 phone - 所以我认为没关系我的电子邮件不适用于移动设备。这是在 Facebook/WooCommerce
源代码中创建上述代码的代码:
private function pixel_init_code() {
$version_info = self::get_version_info();
$agent_string = sprintf(
'%s-%s-%s',
$version_info['source'],
$version_info['version'],
$version_info['pluginVersion']
);
$params = array(
'agent' => $agent_string,
);
return apply_filters(
'facebook_woocommerce_pixel_init',
sprintf(
"fbq('init', '%s', %s, %s);\n",
esc_js( self::get_pixel_id() ),
json_encode( $this->user_info, JSON_PRETTY_PRINT | JSON_FORCE_OBJECT ),
json_encode( $params, JSON_PRETTY_PRINT | JSON_FORCE_OBJECT )
)
);
}
编辑:我找到了 ViewContent
Facebook Pixel
跟踪代码的位置 - 它位于移动和桌面页面的底部,看起来两者相同:
jQuery(function($) {
/* WooCommerce Facebook Integration Event Tracking */
fbq('track', 'ViewContent', {
"source": "woocommerce",
"version": "3.8.1",
"pluginVersion": "1.9.15",
"content_name": "Accessory Power ENHANCE ENGXH10100BKEW GX-H1 Gaming Headset - Black, Blue",
"content_ids": "[\"TFL-ENGXH10100BKEW-OPEN-BOX\"]",
"content_type": "product_group",
"value": "39.85",
"currency": "USD"
});
});
这两个事件都不会在移动设备上触发 - 都会在桌面设备上触发。
为什么我的 Facebook Pixel
无法在移动设备 (iOS) 上运行?在我的 phone 上,我尝试了 Safari
和 Chrome
。
编辑
根据我在整个源代码中看到的评论,我认为它应该将 Facebook Pixel
事件代码放在 <footer>
中,但它似乎将它放在 <head>
中,这对移动设备有影响吗?
我弄明白了,我的代码没有任何问题 - 显然要从我的 phone 接收测试事件,我需要在我的 [=18] 上登录到 facebook 业务管理器=] 否则它不会工作 - 这个问题并没有明确说明,在 Test Events
页面上它在顶部的 header 下说:
Only events you trigger will display in the Test Events tool, not the
activity of other website users.
所以你可以看到他们不是很清楚如何成为上面声明中的"you"(你必须在你正在测试的实际设备上登录业务管理器)。
我正在使用 Wordpress
(v 5.3
) 和 WooCommerce
(v 3.8.1
)。我的 Facebook Pixel 在桌面上注册事件 (ViewContent/InitiateCheckout/AddToCart/Purchase/etc.),但在移动设备上不注册事件 (iOS)。我所有的插件和主题都是最新的。对于我的主题,我使用 Youplay
(v 3.7.4
).
在寻找答案的过程中,我注意到一些人遇到了主题阻碍 Facebook Pixel
在移动设备上工作的问题 - 有些人报告说需要在 functions.php
中注释掉一行 -我包括了我的主题 functions.php
,以防有人注意到任何可能与 Facebook Pixel
在移动设备上工作的冲突(在我发现的帖子中,没有人使用与我相同的主题):
functions.php
<?php
/**
* Youplay functions and definitions
*
* @package Youplay
*/
add_action( 'after_setup_theme', 'yp_setup' );
if ( ! function_exists( 'yp_setup' ) ) :
/**
* Sets up theme defaults and registers support for various WordPress features.
*
* Note that this function is hooked into the after_setup_theme hook, which
* runs before the init hook. The init hook is too late for some features, such
* as indicating support for post thumbnails.
*/
function yp_setup() {
/*
* Make theme available for translation.
* Translations can be filed in the /languages/ directory.
* If you're building a theme based on Youplay, use a find and replace
* to change 'youplay' to the name of your theme in all the template files
*/
load_theme_textdomain( 'youplay', get_template_directory() . '/languages' );
// Add default posts and comments RSS feed links to head.
add_theme_support( 'automatic-feed-links' );
/*
* Let WordPress manage the document title.
* By adding theme support, we declare that this theme does not use a
* hard-coded <title> tag in the document head, and expect WordPress to
* provide it for us.
*/
add_theme_support( 'title-tag' );
// Add editor style support.
add_editor_style();
/*
* Enable support for Post Thumbnails on posts and pages.
*
* @link http://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails
*/
// This theme uses wp_nav_menu() in one location.
register_nav_menus( array(
'primary' => esc_html__( 'Primary Menu', 'youplay' ),
'primary-right' => esc_html__( 'Primary Right Menu', 'youplay' ),
) );
/*
* Switch default core markup for search form, comment form, and comments
* to output valid HTML5.
*/
add_theme_support( 'html5', array(
'search-form', 'comment-form', 'comment-list', 'gallery', 'caption',
) );
/*
* Enable support for WooCommerce
*/
add_theme_support( 'woocommerce' );
// Add default image sizes
add_theme_support('post-thumbnails');
add_image_size('500x375', 500);
add_image_size('500x375_crop', 500, 375, true);
add_image_size('200x200', 200, 200, true);
add_image_size('90x90', 90, 90, true);
add_image_size('1440x900', 1440);
add_image_size('1440x900_crop', 1440, 900, true);
add_image_size('1920x1080', 1920);
// Register the three useful image sizes for use in Add Media modal
add_filter( 'image_size_names_choose', 'yp_custom_sizes' );
if ( ! function_exists( 'yp_custom_sizes' ) ) :
function yp_custom_sizes( $sizes ) {
return array_merge( $sizes, array(
'500x375_crop' => esc_html__( 'Carousel Thumbnail (500x375 crop)', 'youplay' ),
'500x375' => esc_html__( 'Carousel Thumbnail (500x375)', 'youplay' ),
'200x200' => esc_html__( 'User Avatar (200x200 crop)', 'youplay' ),
'90x90' => esc_html__( 'User Small Avatar (90x90 crop)', 'youplay' ),
'1440x900_crop' => esc_html__( '1440x900 crop', 'youplay' ),
'1440x900' => esc_html__( '1440x900', 'youplay' ),
'1920x1080' => esc_html__( '1920x1080', 'youplay' ),
) );
}
endif;
}
endif; // yp_setup
/**
* Set the content width in pixels, based on the theme's design and stylesheet.
*/
if (!isset($content_width)) {
$content_width = 1400;
}
/**
* Register widget area.
*
* @link http://codex.wordpress.org/Function_Reference/register_sidebar
*/
add_action( 'widgets_init', 'yp_widgets_init' );
if ( ! function_exists( 'yp_widgets_init' ) ) :
function yp_widgets_init() {
register_sidebar( array(
'name' => esc_html__( 'Sidebar', 'youplay' ),
'id' => 'sidebar-1',
'description' => esc_html__( 'Default Sidebar', 'youplay' ),
'before_widget' => '<div id="%1$s" class="side-block widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h4 class="widget-title block-title">',
'after_title' => '</h4>',
) );
register_sidebar( array(
'name' => esc_html__( 'WooCommerce Sidebar', 'youplay' ),
'id' => 'woocommerce_sidebar',
'description' => esc_html__( 'Sidebar for WooCommerce Pages', 'youplay' ),
'before_widget' => '<div id="%1$s" class="side-block widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h4 class="widget-title block-title">',
'after_title' => '</h4>',
) );
register_sidebar( array(
'name' => esc_html__( 'BuddyPress Sidebar', 'youplay' ),
'id' => 'buddypress_sidebar',
'description' => esc_html__( 'Sidebar for BuddyPress Pages', 'youplay' ),
'before_widget' => '<div id="%1$s" class="side-block widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h4 class="widget-title block-title">',
'after_title' => '</h4>',
) );
register_sidebar( array(
'name' => esc_html__( 'bbPress Sidebar', 'youplay' ),
'id' => 'bbpress_sidebar',
'description' => esc_html__( 'Sidebar for bbPress Pages', 'youplay' ),
'before_widget' => '<div id="%1$s" class="side-block widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h4 class="widget-title block-title">',
'after_title' => '</h4>',
) );
register_sidebar( array(
'name' => esc_html__( 'Matches Sidebar', 'youplay' ),
'id' => 'matches_sidebar',
'description' => esc_html__( 'Sidebar for Matches Pages', 'youplay' ),
'before_widget' => '<div id="%1$s" class="side-block widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h4 class="widget-title block-title">',
'after_title' => '</h4>',
) );
register_sidebar( array(
'name' => esc_html__( 'Footer Widgets 1', 'youplay' ),
'id' => 'footer_widgets_1',
'description' => esc_html__( 'Footer Widgets 1 Column', 'youplay' ),
'before_widget' => '<div id="%1$s" class="side-block widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h4 class="widget-title block-title">',
'after_title' => '</h4>',
) );
register_sidebar( array(
'name' => esc_html__( 'Footer Widgets 2', 'youplay' ),
'id' => 'footer_widgets_2',
'description' => esc_html__( 'Footer Widgets 2 Column', 'youplay' ),
'before_widget' => '<div id="%1$s" class="side-block widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h4 class="widget-title block-title">',
'after_title' => '</h4>',
) );
register_sidebar( array(
'name' => esc_html__( 'Footer Widgets 3', 'youplay' ),
'id' => 'footer_widgets_3',
'description' => esc_html__( 'Footer Widgets 3 Column', 'youplay' ),
'before_widget' => '<div id="%1$s" class="side-block widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h4 class="widget-title block-title">',
'after_title' => '</h4>',
) );
register_sidebar( array(
'name' => esc_html__( 'Footer Widgets 4', 'youplay' ),
'id' => 'footer_widgets_4',
'description' => esc_html__( 'Footer Widgets 4 Column', 'youplay' ),
'before_widget' => '<div id="%1$s" class="side-block widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h4 class="widget-title block-title">',
'after_title' => '</h4>',
) );
}
endif;
/**
* Enqueue scripts and styles.
*/
add_action( 'wp_enqueue_scripts', 'yp_scripts' );
if ( ! function_exists( 'yp_scripts' ) ) :
function yp_scripts() {
wp_enqueue_style( 'youplay', get_template_directory_uri() . '/style.css', '', '3.7.4' );
wp_enqueue_style( 'bootstrap', get_template_directory_uri() . '/assets/vendor/bootstrap/dist/css/bootstrap.min.css', '', '3.3.7' );
wp_enqueue_style( 'magnific-popup', get_template_directory_uri() . '/assets/vendor/magnific-popup/dist/magnific-popup.css', '', '1.1.0' );
wp_enqueue_style( 'flickity', get_template_directory_uri() . '/assets/vendor/flickity/dist/flickity.min.css', '', '2.2.0' );
// deregister bbPress styles
wp_deregister_style( 'bbp-default' );
wp_register_style( 'bbp-default', get_template_directory_uri() . '/assets/css/bbpress-styles.css' );
// theme style
$theme_style = yp_opts('theme_style');
$youplay_style_file = '';
$youplay_style_version = '3.7.4';
if ($theme_style === 'custom') {
youplay_maybe_compile_scss();
if ( function_exists('nk_theme') ) {
$youplay_style_file = nk_theme()->get_compiled_css_url('youplay-custom.min.css');
$youplay_style_version = nk_theme()->get_compiled_css_version('youplay-custom.min.css');
}
if (!$youplay_style_file) {
$theme_style = 'dark';
}
}
if($theme_style !== 'custom') {
$youplay_style_file = get_template_directory_uri() . '/assets/css/youplay-' . $theme_style . '.min.css';
}
wp_enqueue_style('youplay-' . $theme_style, $youplay_style_file, array(), $youplay_style_version);
// rtl
if(yp_opts('general_rtl')) {
wp_enqueue_style( 'youplay-rtl', get_template_directory_uri() . '/assets/css/youplay-rtl.min.css', '', '3.7.4' );
}
wp_enqueue_script( 'bootstrap', get_template_directory_uri() . '/assets/vendor/bootstrap/dist/js/bootstrap.min.js', array('jquery'), '3.3.7', true );
wp_enqueue_script( 'font-awesome', get_template_directory_uri() . '/assets/vendor/fontawesome-free/js/all.js', array(), '5.9.0', true );
wp_enqueue_script( 'font-awesome-v4-shims', get_template_directory_uri() . '/assets/vendor/fontawesome-free/js/v4-shims.js', array('font-awesome'), '5.9.0', true );
wp_enqueue_script( 'isotope', get_template_directory_uri() . '/assets/vendor/isotope-layout/dist/isotope.pkgd.min.js', array('jquery', 'imagesloaded'), '3.0.6', true );
wp_enqueue_script( 'jquery-countdown', get_template_directory_uri() . '/assets/vendor/jquery-countdown/dist/jquery.countdown.min.js', array('jquery'), '2.2.0', true );
wp_enqueue_script( 'moment-timezone', get_template_directory_uri() . '/assets/vendor/moment-timezone/builds/moment-timezone-with-data.min.js', array('moment'), '0.5.14', true );
wp_enqueue_script( 'magnific-popup', get_template_directory_uri() . '/assets/vendor/magnific-popup/dist/jquery.magnific-popup.min.js', '', '1.1.0', true );
wp_enqueue_script( 'flickity', get_template_directory_uri() . '/assets/vendor/flickity/dist/flickity.pkgd.min.js', array('jquery', 'imagesloaded'), '2.2.0', true );
wp_enqueue_script( 'object-fit-images', get_template_directory_uri() . '/assets/vendor/object-fit-images/dist/ofi.min.js', '', '3.2.3', true );
wp_enqueue_script( 'jarallax', get_template_directory_uri() . '/assets/vendor/jarallax/dist/jarallax.min.js', '', '1.10.7', true );
wp_enqueue_script( 'skrollr', get_template_directory_uri() . '/assets/vendor/skrollr/dist/skrollr.min.js', '', '0.6.30', true );
wp_enqueue_script( 'hexagon-progress', get_template_directory_uri() . '/assets/vendor/HexagonProgress/jquery.hexagonprogress.min.js', '', '1.2.0', true );
wp_enqueue_script( 'youplay', get_template_directory_uri() . '/assets/js/youplay.min.js', array('jquery', 'bootstrap', 'isotope', 'imagesloaded', 'jquery-countdown', 'magnific-popup', 'flickity', 'object-fit-images', 'jarallax', 'hexagon-progress'), '3.7.4', true );
wp_enqueue_script( 'youplay-wp', get_template_directory_uri() . '/assets/js/youplay-wp.min.js', array('jquery', 'youplay'), '3.7.4', true );
wp_enqueue_script( 'youplay-cf7', get_template_directory_uri() . '/assets/js/youplay-cf7.min.js', array('jquery', 'youplay'), '3.7.4', true );
wp_enqueue_script( 'youplay-init', get_template_directory_uri() . '/assets/js/youplay-init.min.js', array('jquery', 'youplay'), '3.7.4', true );
$dataInit = array(
'enableParallax' => yp_opts('general_parallax'),
'enableFadeBetweenPages' => yp_opts('general_fade_between_pages') && yp_opts('general_preloader')
);
wp_localize_script('youplay-init', 'youplayInitOptions', $dataInit);
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
// Custom CSS
ob_start();
require get_template_directory() . '/inc/head_styles.php';
$custom_css = ob_get_clean();
$custom_css = wp_kses( $custom_css, array( '\'', '\"' ) );
$custom_css = str_replace( '>' , '>' , $custom_css );
wp_add_inline_style( 'youplay-' . $theme_style, $custom_css );
// Custom JS
wp_add_inline_script( 'youplay-init', yp_opts('general_custom_js') );
}
endif;
// Compile SCSS.
if (!function_exists('youplay_maybe_compile_scss')) :
function youplay_maybe_compile_scss() {
if ( yp_opts('theme_style') !== 'custom' || ! function_exists('nk_theme') ) {
return;
}
$theme_colors_from = yp_opts('theme_colors_from') == 'light' ? 'light' : 'dark';
$theme_main_color = yp_opts('theme_main_color');
$theme_back_color = yp_opts('theme_back_color');
$theme_back_grey_color = yp_opts('theme_back_grey_color');
$theme_text_color = yp_opts('theme_text_color');
$theme_primary_color = yp_opts('theme_primary_color');
$theme_success_color = yp_opts('theme_success_color');
$theme_info_color = yp_opts('theme_info_color');
$theme_warning_color = yp_opts('theme_warning_color');
$theme_danger_color = yp_opts('theme_danger_color');
$theme_skew_size = yp_opts('theme_skew_size');
$theme_navbar_height = yp_opts('theme_navbar_height');
$theme_navbar_small_height = yp_opts('theme_navbar_small_height');
$theme_banners_opacity = yp_opts('theme_banners_opacity') / 100;
$theme_images_opacity = yp_opts('theme_images_opacity') / 100;
$theme_images_hover_opacity = yp_opts('theme_images_hover_opacity') / 100;
$theme_data = wp_get_theme();
$theme_parent = $theme_data->parent();
if (!empty($theme_parent)) {
$theme_data = $theme_parent;
}
$theme_version = $theme_data['Version'];
$path = get_template_directory() . '/assets/css/';
$custom_vars = '
@import "_helpers.scss";
@import "_variables.scss";
$theme_version:"' . $theme_version . '";
$theme:' . $theme_colors_from . ';
$main_color:' . $theme_main_color . ';
$back_color:' . $theme_back_color . ';
$back_darken_color:' . ($theme_colors_from == 'light' ? '#FFFFFF' : 'darken($back_color, 13)' ) . ';
$back_grey_color:' . $theme_back_grey_color . ';
$back_darken_grey_color: ' . ($theme_colors_from == 'light' ? 'lighten' : 'darken') . '($back_grey_color, 10);
$text_color:' . $theme_text_color . ';
$text_mute_color: rgba($text_color, 0.5);
$color_primary:' . $theme_primary_color . ';
$color_success:' . $theme_success_color . ';
$color_info:' . $theme_info_color . ';
$color_warning:' . $theme_warning_color . ';
$color_danger:' . $theme_danger_color . ';
$skew_size:' . $theme_skew_size . 'deg;
$banners_opacity:' . $theme_banners_opacity . ';
$images_opacity:' . $theme_images_opacity . ';
$images_hover_opacity:' . $theme_images_hover_opacity . ';
$navbar-height:' . $theme_navbar_height . 'px;
$navbar-sm-height:' . $theme_navbar_small_height . 'px;
@import "_includes.scss"';
nk_theme()->scss('youplay-custom.min.css', $path, $custom_vars);
}
endif;
add_action('ot_after_theme_options_save', 'youplay_maybe_compile_scss');
/**
* Admin References
*/
require get_template_directory() . '/admin/admin.php';
/**
* Custom functions that act independently of the theme templates.
*/
require get_template_directory() . '/inc/extras.php';
/**
* Colors convert functions
*/
require get_template_directory() . '/inc/colors.php';
/**
* Custom template tags for this theme.
*/
require get_template_directory() . '/inc/template-tags.php';
/**
* Comments walker
*/
require get_template_directory() . '/inc/comments-walker.php';
/**
* Custom WooCommerce functions
*/
require get_template_directory() . '/woocommerce/functions.php';
/**
* Custom BuddyPress functions
*/
require get_template_directory() . '/buddypress/functions.php';
/**
* Custom bbPress functions
*/
require get_template_directory() . '/bbpress/functions.php';
/**
* Infinitie Scroll for Posts
*/
require get_template_directory() . '/inc/lib/nk-infinite-scroll/nk-infinitie-scroll.php';
我还发现有人说他们的主题正在删除一个 WooCommerce
挂钩(我相信它是 woocommerce_after_single_product
但我不再确切地读到它了) - 我不确定是否我的主题就是这样做的。
我已验证当我不在移动设备上时,所有 Facebook Pixel
事件都会显示:
您可以看到它正在显示 Receiving activity
并列出了事件。手机上试了一下,说不是Receiving activity
(有黄点),也不报事件。
我在 facebook-commerce-events-tracker.php
中找到了处理事件的源代码,也许其中的内容对移动设备不友好?我只展示我认为可能相关的内容,因为我在这个问题上没有更多的文字空间:
facebook-commerce-events-tracker.php
...
class WC_Facebookcommerce_EventsTracker {
private $pixel;
private static $isEnabled = true;
const FB_PRIORITY_HIGH = 2;
const FB_PRIORITY_LOW = 11;
public function __construct( $user_info ) {
$this->pixel = new WC_Facebookcommerce_Pixel( $user_info );
add_action( 'wp_head', array( $this, 'apply_filters' ) );
// Pixel Tracking Hooks
add_action(
'wp_head',
array( $this, 'inject_base_pixel' )
);
add_action(
'wp_footer',
array( $this, 'inject_base_pixel_noscript' )
);
add_action(
'woocommerce_after_single_product',
array( $this, 'inject_view_content_event' ),
self::FB_PRIORITY_HIGH
);
add_action(
'woocommerce_after_shop_loop',
array( $this, 'inject_view_category_event' )
);
add_action(
'pre_get_posts',
array( $this, 'inject_search_event' )
);
add_action(
'woocommerce_after_cart',
array( $this, 'inject_add_to_cart_redirect_event' )
);
add_action(
'woocommerce_add_to_cart',
array( $this, 'inject_add_to_cart_event' ),
self::FB_PRIORITY_HIGH
);
add_action(
'wc_ajax_fb_inject_add_to_cart_event',
array( $this, 'inject_ajax_add_to_cart_event' ),
self::FB_PRIORITY_HIGH
);
add_action(
'woocommerce_after_checkout_form',
array( $this, 'inject_initiate_checkout_event' )
);
add_action(
'woocommerce_thankyou',
array( $this, 'inject_gateway_purchase_event' ),
self::FB_PRIORITY_HIGH
);
add_action(
'woocommerce_payment_complete',
array( $this, 'inject_purchase_event' ),
self::FB_PRIORITY_HIGH
);
add_action(
'wpcf7_contact_form',
array( $this, 'inject_lead_event_hook' ),
self::FB_PRIORITY_LOW
);
}
...
/**
* Triggers ViewContent product pages
*/
public function inject_view_content_event() {
if ( ! self::$isEnabled ) {
return;
}
global $post;
$product = wc_get_product( $post->ID );
$content_type = 'product_group';
if ( ! $product ) {
return;
}
// if product is a variant, fire the pixel with content_type: product_group
if ( WC_Facebookcommerce_Utils::is_variation_type( $product->get_type() ) ) {
$content_type = 'product';
}
$content_ids = WC_Facebookcommerce_Utils::get_fb_content_ids( $product );
$this->pixel->inject_event(
'ViewContent',
array(
'content_name' => $product->get_title(),
'content_ids' => json_encode( $content_ids ),
'content_type' => $content_type,
'value' => $product->get_price(),
'currency' => get_woocommerce_currency(),
)
);
}
这是上面引用的 inject_event
函数:
/**
* Preferred method to inject events in a page, normally you should use this
* instead of WC_Facebookcommerce_Pixel::build_event()
*/
public function inject_event( $event_name, $params, $method = 'track' ) {
$code = self::build_event( $event_name, $params, $method );
$this->last_event = $event_name;
if ( WC_Facebookcommerce_Utils::isWoocommerceIntegration() ) {
WC_Facebookcommerce_Utils::wc_enqueue_js( $code );
} else {
printf(
'
<!-- Facebook Pixel Event Code -->
<script>
%s
</script>
<!-- End Facebook Pixel Event Code -->
',
$code
);
}
}
我在移动设备上注意到 - 本应包含 Facebook Pixel
代码的部分看起来很奇怪:
<!-- Facebook Pixel Code -->
<noscript>
<img height="1" width="1" style="display:none" alt="fbpx"
src="https://www.facebook.com/tr?id=549560325605747&ev=PageView&noscript=1"/>
</noscript>
<!-- End Facebook Pixel Code -->
上图:为什么 Facebook Pixel 代码应该有一个 img
元素?
编辑:对于上述问题,桌面似乎是一样的,所以我认为这不重要——尽管我不明白它是什么。
我在注入时发现实际事件代码在我的网站上的位置 - 看起来它正在注册为 PageView
,它应该是 ViewContent
- 也许分类是错误是以某种方式导致问题(冲突)?
<!-- WooCommerce Facebook Integration Begin -->
!function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod?
n.callMethod.apply(n,arguments):n.queue.push(arguments)};if(!f._fbq)f._fbq=n;
n.push=n;n.loaded=!0;n.version='2.0';n.queue=[];t=b.createElement(e);t.async=!0;
t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s)}(window,
document,'script','https://connect.facebook.net/en_US/fbevents.js');
<script>
fbq('init', 'xxxxx', {}, {
"agent": "woocommerce-3.8.1-1.9.15"
});
fbq('track', 'PageView', {
"source": "woocommerce",
"version": "3.8.1",
"pluginVersion": "1.9.15"
});
document.addEventListener('DOMContentLoaded', function() {
jQuery && jQuery(function($){
$('body').on('added_to_cart', function(event) {
// Ajax action.
$.get('?wc-ajax=fb_inject_add_to_cart_event', function(data) {
$('head').append(data);
});
});
});
}, false);
</script>
<!-- DO NOT MODIFY -->
<!-- WooCommerce Facebook Integration end -->
这是同一部分在桌面上的样子 - 我注意到它有一个 em
属性,这是我的电子邮件,但在移动版本上没有 - 也许这很重要,需要包括在内网站何时在移动设备上呈现?
fbq('init', 'xxxx', {
"em": "myemail7@gmail.com"
}, {
"agent": "woocommerce-3.8.1-1.9.15"
});
fbq('track', 'PageView', {
"source": "woocommerce",
"version": "3.8.1",
"pluginVersion": "1.9.15"
});
document.addEventListener('DOMContentLoaded', function() {
jQuery && jQuery(function($){
$('body').on('added_to_cart', function(event) {
// Ajax action.
$.get('?wc-ajax=fb_inject_add_to_cart_event', function(data) {
$('head').append(data);
});
});
});
}, false);
**编辑:**对于上面的内容,我了解到电子邮件在那里是因为我是我计算机上该网站的用户,但不是我的 phone - 所以我认为没关系我的电子邮件不适用于移动设备。这是在 Facebook/WooCommerce
源代码中创建上述代码的代码:
private function pixel_init_code() {
$version_info = self::get_version_info();
$agent_string = sprintf(
'%s-%s-%s',
$version_info['source'],
$version_info['version'],
$version_info['pluginVersion']
);
$params = array(
'agent' => $agent_string,
);
return apply_filters(
'facebook_woocommerce_pixel_init',
sprintf(
"fbq('init', '%s', %s, %s);\n",
esc_js( self::get_pixel_id() ),
json_encode( $this->user_info, JSON_PRETTY_PRINT | JSON_FORCE_OBJECT ),
json_encode( $params, JSON_PRETTY_PRINT | JSON_FORCE_OBJECT )
)
);
}
编辑:我找到了 ViewContent
Facebook Pixel
跟踪代码的位置 - 它位于移动和桌面页面的底部,看起来两者相同:
jQuery(function($) {
/* WooCommerce Facebook Integration Event Tracking */
fbq('track', 'ViewContent', {
"source": "woocommerce",
"version": "3.8.1",
"pluginVersion": "1.9.15",
"content_name": "Accessory Power ENHANCE ENGXH10100BKEW GX-H1 Gaming Headset - Black, Blue",
"content_ids": "[\"TFL-ENGXH10100BKEW-OPEN-BOX\"]",
"content_type": "product_group",
"value": "39.85",
"currency": "USD"
});
});
这两个事件都不会在移动设备上触发 - 都会在桌面设备上触发。
为什么我的 Facebook Pixel
无法在移动设备 (iOS) 上运行?在我的 phone 上,我尝试了 Safari
和 Chrome
。
编辑
根据我在整个源代码中看到的评论,我认为它应该将 Facebook Pixel
事件代码放在 <footer>
中,但它似乎将它放在 <head>
中,这对移动设备有影响吗?
我弄明白了,我的代码没有任何问题 - 显然要从我的 phone 接收测试事件,我需要在我的 [=18] 上登录到 facebook 业务管理器=] 否则它不会工作 - 这个问题并没有明确说明,在 Test Events
页面上它在顶部的 header 下说:
Only events you trigger will display in the Test Events tool, not the activity of other website users.
所以你可以看到他们不是很清楚如何成为上面声明中的"you"(你必须在你正在测试的实际设备上登录业务管理器)。