/** * Generate the stats pixel. * * Looks something like: * https://pixel.wp.com/g.gif?v=ext&j=1%3A3.9.1&blog=1234&post=5678&tz=-4&srv=example.com&host=example.com&ref=&rand=0.4107963021218808 */ function jetpack_amp_build_stats_pixel_url() { global $wp_the_query; if (function_exists('stats_build_view_data')) { // added in https://github.com/Automattic/jetpack/pull/3445 $data = stats_build_view_data(); } else { $blog = Jetpack_Options::get_option('id'); $tz = get_option('gmt_offset'); $v = 'ext'; $blog_url = parse_url(site_url()); $srv = $blog_url['host']; $j = sprintf('%s:%s', JETPACK__API_VERSION, JETPACK__VERSION); $post = $wp_the_query->get_queried_object_id(); $data = compact('v', 'j', 'blog', 'post', 'tz', 'srv'); } $data['host'] = rawurlencode($_SERVER['HTTP_HOST']); $data['rand'] = 'RANDOM'; // amp placeholder $data['ref'] = 'DOCUMENT_REFERRER'; // amp placeholder $data = array_map('rawurlencode', $data); return add_query_arg($data, 'https://pixel.wp.com/g.gif'); }
function stats_template_redirect() { global $current_user, $stats_footer; if (is_feed() || is_robots() || is_trackback() || is_preview()) { return; } // Should we be counting this user's views? if (!empty($current_user->ID)) { $count_roles = stats_get_option('count_roles'); if (!array_intersect($current_user->roles, $count_roles)) { return; } } add_action('wp_footer', 'stats_footer', 101); add_action('wp_head', 'stats_add_shutdown_action'); $script = set_url_scheme('//stats.wp.com/e-' . gmdate('YW') . '.js'); $data = stats_build_view_data(); $data_stats_array = stats_array($data); $stats_footer = <<<END <script type='text/javascript' src='{$script}' async defer></script> <script type='text/javascript'> \t_stq = window._stq || []; \t_stq.push([ 'view', {{$data_stats_array}} ]); \t_stq.push([ 'clickTrackerInit', '{$data['blog']}', '{$data['post']}' ]); </script> END; }