WP-InstantClick icon indicating copy to clipboard operation
WP-InstantClick copied to clipboard

on first view only jetpack wpstats smiley face shows

Open kalligator opened this issue 10 years ago • 3 comments

On 2/3 sites I tested the plugin it shows just the smiley face http://stats.wordpress.com/g.gif of jetpack wpstats (a stats tracking image) upon first view. On reload it shows the page correctly. The third site that didn't have jetpack wpstats activated played nice.

kalligator avatar May 16 '14 15:05 kalligator

Hi @kalligator, I just tried the plugin with JetPack stats enabled and didn't have the same problem. What theme are you using? Do you have a link where I can see the problem?

mgmartel avatar May 16 '14 15:05 mgmartel

Did you try in private/incognito browser mode? Because I think by default jetpack excludes connected users from stasts collecting.

I'm ~~99%~~ 100% sure it's jetpack's fault. I reverted the theme to twenty fourteen and it was still there. I disabled all plugins except WP-InstantClick & Jetpack and I was getting the same behaviour. With all pluugins active except Jetpack, no problem.

kalligator avatar May 16 '14 23:05 kalligator

Gotcha. I gave up to early giving this a try yesterday. Of course JetPack stats itself is not loaded through WP's own scripts API. But the hack below adds the data-no-instant attribute to the JetPack script:

add_action( 'template_redirect', function(){
    global $stats_footer;

    if ( !$stats_footer ) 
        return;

    $stats_footer = str_replace( 'type="text/javascript">', 'type="text/javascript" data-no-instant>', $stats_footer );
}, 2 );

Unfortunately, this does mean that pageviews after the initial load won't be tracked. It's the inline tracking script itself that's the culprit, so I think we'd need to dive into the JetPack stats JS to figure out how to make it compatible with InstantClick.

mgmartel avatar May 17 '14 09:05 mgmartel