Hello,
Indeed there is a problem with the “async src=’…’ ” part that can’t be loaded properly.
In my theme functions.php I came up with this loader:
add_action( 'wp_footer', 'my_footer_scripts' );
function my_footer_scripts(){
echo '<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXXX-1"></script>';
}
Then, in your snippet, just add the :
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-XXXXXXXX-1');
Modify your track code as needed. If you want to load the java script in the header use wp_head instead of wp_footer.
As a suggestion for the developer, in the Google Analytics Snippet, a field with the track code can be added, so one can put his track code and then the snippet generate all the stuff needed.
-
This reply was modified 8 years ago by
rivmanbx.
-
This reply was modified 8 years ago by
rivmanbx.
Thanks a lot,
I took the top part and made a functional plugin with the top add_action, and then put the rest in the snippet window and all is working well.
The tracking is on and off as per the settings.
Thanks a lot for you help.
Gruff
-
This reply was modified 8 years ago by
gruff578.
@rivmanbx; Thanks for the temporary fix. I’ll make sure you’ll be able to add your <script> tags when necessary, for example for Google Analytics.
The nice thing with this GA script is that you can really easily anonymise the IP addresses as well, by adding one tiny bit in the very last line of the snippet, and I checked it with your plugin and it is all working.
– so if people want to use the GA global gtag and anonymise the IP addresses they just have to do this script in the snippet window
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag(‘js’, new Date());
gtag(‘config’, ‘UA-XXXXXXXXX-X’, { ‘anonymize_ip’: true });
and the bit you gave me for the functions.php –
add_action( ‘wp_footer’, ‘my_footer_scripts’ );
function my_footer_scripts(){
echo ‘<script async src=”https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXXX-1″></script>’;
}
For beginners it’s easier than learning general tag manager and anonymising from the filters.
Maybe you could get people to send you the scripts they have that function well, and you could just have a list on your support page where people could come and find the scripts they need.
Anyhow it is working really well, so well done with all the great work.
Gruff
-
This reply was modified 8 years ago by
gruff578.
-
This reply was modified 8 years ago by
gruff578.
-
This reply was modified 8 years ago by
gruff578.