示例#1
0
function jetpack_amp_add_stats_pixel($amp_template)
{
    ?>
	<amp-pixel src="<?php 
    echo esc_url(wpcom_amp_get_pageview_url());
    ?>
"></amp-pixel>
	<amp-pixel src="<?php 
    echo esc_url(wpcom_amp_get_mc_url());
    ?>
"></amp-pixel>
	<amp-pixel src="<?php 
    echo esc_url(wpcom_amp_get_stats_extras_url());
    ?>
"></amp-pixel>
	<?php 
}
示例#2
0
<?php

// WPCOM-specific things
define('AMP_DEV_MODE', defined('WPCOM_SANDBOXED') && WPCOM_SANDBOXED);
// Add stats pixel
add_filter('amp_post_content', function ($content, $post) {
    $urls = array(wpcom_amp_get_pageview_url(), wpcom_amp_get_mc_url(), wpcom_amp_get_stats_extras_url());
    foreach ($urls as $url) {
        if (!$url) {
            continue;
        }
        $content .= sprintf('<amp-pixel src="%s">', esc_url($url));
    }
    return $content;
}, 10, 2);
function wpcom_amp_get_pageview_url()
{
    $stats_info = stats_collect_info();
    $a = $stats_info['st_go_args'];
    $url = add_query_arg(array('rand' => '$RANDOM', 'host' => rawurlencode($_SERVER['HTTP_HOST'])), 'https://pixel.wp.com/b.gif');
    $url .= '&' . stats_array_string($a);
    return $url;
}
function wpcom_amp_get_mc_url()
{
    return add_query_arg(array('rand' => '$RANDOM', 'v' => 'wpcom-no-pv', 'x_amp-views' => 'view'), 'https://pixel.wp.com/b.gif');
}
function wpcom_amp_get_stats_extras_url()
{
    $stats_extras = stats_extras();
    if (!$stats_extras) {