Disable JetPack's Statistics

This post serves as a note to myself and I post it here in case I forget how I "solved" the issue. This blog does not run WordPress but I have a lot of other blogs which do run that software and I typically install Automattic's JetPack plugin[1] on most of them due to some of the convenient features offered by that plugin, but one feature is very inconvenient to me, as I have no need for it. I am referring to the statistics module; this is pointless for me as I run my own statistics -- Piwik[2] -- on a server dedicated just for that particular purpose.

I have found no good way of disabling the statistics module. There is no option to do it, as far as I can tell. So my solution was to simply hack away at it's core by editing jetpack/modules/stats.php.

The offending JavaScript added by this plugin can be seen below:

    $stats_footer = <<<END
<script type='text/javascript' src='{$script}' async defer></script>  
<script type='text/javascript'>  
    _stq = window._stq || [];
    _stq.push([ 'view', {{$data_stats_array}} ]);
    _stq.push([ 'clickTrackerInit', '{$data['blog']}', '{$data['post']}' ]);
</script>

END;  

Simply remove or replace that with whatever you want. In my case I just added the following:

    $stats_footer = <<<END
<!-- NEIN! -->

END;  

...but to cut down the bloat further, you could simply disable or modify the following calls in the same file (i.e stats.php):

add_action( 'wp_footer', 'stats_footer', 101 );  
add_action( 'wp_head', 'stats_add_shutdown_action' );  

I suppose that one could make use of the remove_filter(); function and put the corresponding entries in the functions.php file. I don't actively work on WordPress much these days, but if my memory serves me correctly, it should be possible to do it that way as well, which is probably less bloaty than what I have done above. I'm sure there is a much better way, but I haven't found it...

Whatever. My main concern was to just get rid of the junk since there was no simple way of deactivating this "feature" in the WordPress administration area itself, hence I had to resort to this hacky solution.

Notes:

[1] A powerful plugin to enhance a self-hosted WordPress site with powerful features previously only available to WordPress.com users. https://wordpress.org/plugins/jetpack/.

[2] Piwik is the leading open alternative to Google Analytics that gives you full control over your data. Piwik lets you easily collect data from websites, apps & the IoT and visualise this data and extract insights. Privacy is built-in. https://piwik.org/.

Comment: