forked from Automattic/fb-instant-articles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wpcom-helper.php
43 lines (31 loc) · 1.07 KB
/
wpcom-helper.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
// Wrap the wpcom tracking pixel to comply with the FBIA spec
// https://developers.facebook.com/docs/instant-articles/reference/analytics
function wpcom_fbia_stats_pixel() {
global $post;
if ( ! defined( 'INSTANT_ARTICLES_SLUG' ) ) {
return;
}
if ( ! is_feed( INSTANT_ARTICLES_SLUG ) ) {
return;
}
// Stop wpcom adding the tracking pixel
remove_filter( 'the_content', 'add_bug_to_feed', 100 );
add_filter( 'the_content', '_wpcom_fbia_stats_pixel', 100 );
}
add_action( 'template_redirect', 'wpcom_fbia_stats_pixel' );
function _wpcom_fbia_stats_pixel( $content ) {
global $post, $current_blog;
if( ! is_feed() )
return $content;
$url = 'https://pixel.wp.com/b.gif?host=' . $_SERVER[ 'HTTP_HOST' ] . '&blog=' . $current_blog->blog_id . '&post=' . $post->ID . '&subd=' . str_replace( '.wordpress.com', '', $current_blog->domain ) . '&ref=&feed=1';
$fbia_pixel = '
<figure class="op-tracker">
<iframe>
<script>
var x = new Image(); x.src = "' . esc_js( $url ) . '&rand=" +Math.random();
</script>
</iframe>
</figure>';
return $content . $fbia_pixel;
}