So it turns out that using the recommended google analytics script is penalised by PageSpeed Insights as it is a render blocking script to load. After doing a bit of research I came across the ga-lite script. Here’s the function to whack it in the footer of a wordpress site. Code goes in functions.php.
function google_analytics(){ ?> <script src="https://cdn.jsdelivr.net/ga-lite/latest/ga-lite.min.js" async></script> <script> var galite = galite || {}; galite.UA = 'insert publisher id here'; </script> <?php } add_action('wp_footer', 'google_analytics', 99);