-
AuthorPosts
-
November 10, 2020 at 11:34 pm #1259700
Gday Enfold users and support,
I have added the new GA4 tracking code to the Google Services area, but is not collecting data.
Are there any known issues with this, or special integration methods?
Thanks for any help you can provide, much appreciated.
My login details provided for Enfold support.
cheers
DarrylNovember 11, 2020 at 9:47 am #1259798Hey Darryl,
It’s not working on a local installation either when I try to reproduce the problem, so there’s likely an issue with how we handle that type of code. I’ve reported this to our developers, but I don’t have a solution for you right now though.
Until we have a solution then you can try adding it using a function in functions.php instead:
function new_google_analytics(){ ?> //Your code goes here <?php } add_action('wp_head', 'new_google_analytics');
Best regards,
RikardNovember 11, 2020 at 10:11 am #1259799Gday Rikard, thank you for your investigation, and your suggestion, very much appreciated. I’ll try that and will write back with the results.
cheers
DarrylNovember 11, 2020 at 12:34 pm #1259851Gday Rikard
Thanks again for your help with this. I added to my child functions file and the code is coming through in the head, but still not collecting at Analytics. The advice in the Google admin is to add the code as the very first item in the head. I’m not a coder, so I searched on how to do that but no luck. Do you know how to modify that function code to make the script first in the head?
Thanks Rikard, I understand this is moving out of Enfold support per se, so any help at all is much appreciated.
cheers
DarrylNovember 12, 2020 at 10:15 am #1260062Hi Darryl,
Please try this instead, it should give it the highest priority:
function new_google_analytics(){ ?> //Your code goes here <?php } add_action('wp_head', 'new_google_analytics', 1);
Documentation can be found here: https://developer.wordpress.org/reference/hooks/wp_head/
Best regards,
Rikard- This reply was modified 4 years, 1 month ago by Rikard.
December 16, 2020 at 12:10 pm #1267747Hi Darryl,
After integrating the give code into the functions.php file the website does not work correctly.
A while line above the menu has appeared with the tracking code in it. Could you please take a look at it if possible?
Alexander
December 16, 2020 at 12:38 pm #1267775Hi Darryl,
Please disregard my previous message. The functions.php code did not work completely. So I have removed it from the website.
Alex
December 16, 2020 at 12:40 pm #1267777Hi AT_VALENS,
Can you please share the code that you were adding?
Best regards,
VictoriaDecember 16, 2020 at 12:48 pm #1267790Ok,
For the very smart people like myself:
This is how the complete version of the code inserted into the functions.php should look like. Hope this saves times to someone new to this too.
/*
* Google Analytics GA4 tracking
*/
function new_google_analytics(){
?>
<!– Global site tag (gtag.js) – Google Analytics –>
<script async src=”https://www.googletagmanager.com/gtag/js?id=G-00XXX0X0XX”></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag(‘js’, new Date());gtag(‘config’, ‘G-00XXX0X0XX’);
</script>
<?php
}
add_action(‘wp_head’, ‘new_google_analytics’, 1);Alex
December 16, 2020 at 12:50 pm #1267793Apologies for bothering you for nothing really
December 16, 2020 at 1:06 pm #1267806Hi AT_VALENS,
I’m glad you got it working for you and thank you for sharing :)
You did not bother us for nothing as we are here to help.
If you need further assistance please let us know.
Best regards,
Victoria -
AuthorPosts
- The topic ‘Integrating new GA4 Analytics code’ is closed to new replies.