Google Analytics - add script to functions.php
I want to connect google analytics to my site. I don't want to do it through the MonsterInsights plug-in. I added this script to functions.php. Will it work?
?php
/**
* Add functions files
*
* @package Virtue Theme
*/
/**
* Language setup
*/
function virtue_lang_setup() {
load_theme_textdomain( 'virtue', get_template_directory() . '/languages' );
}
add_action('wp_head', 'my_analytics', 20);
function my_analytics() {
?
!-- Global site tag (gtag.js) - Google Analytics --
script async src=https://www.googletagmanager.com/gtag/js?id=UA-00000000-1/script
script
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-00000000-1');
/script
?php
}
Topic functions google-analytics Wordpress
Category Web