Tagged: x
-
AuthorPosts
-
January 27, 2017 at 10:39 am #1347922
aleadfreakParticipantHi,
I am having trouble installing the Google Tag Manager code on my functions.php page.
Code found on another thread has led me to enter this:
// Add Google Tag Manager Code // ============================================================================= function add_google_tag_manager_code(){ ?> <!-- Google Tag Manager --> <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); })(window,document,'script','dataLayer','GTM-T7LD9VH');</script> <!-- End Google Tag Manager --> <?php } add_action( 'x_before_site_begin', 'add_google_tag_manager_code' ); // End Add Google Tag Manager Code // =============================================================================But using Google Tag Manager Extension, this isn’t working.
Please help.
Thanks
Alex
January 27, 2017 at 10:40 am #1347926
aleadfreakParticipantThis reply has been marked as private.January 27, 2017 at 1:40 pm #1348125
RahulModeratorHi There,
Thanks for writing in!
As an alternative, you need to install a child theme and once your already have your child theme active and ready, please insert this following code in your child theme’s functions.php file.
// Add Google Tag Manager Code // ============================================================================= function add_google_tag_manager_code(){ ?> <!-- Insert Google Tag Code starts here --> <!-- Insert Google Tag Code ends here --> <?php } add_action( 'x_before_site_begin', 'add_google_tag_manager_code' ); // End Add Google Tag Manager Code // =============================================================================Hope this helps. Kindly let us know.
January 27, 2017 at 2:00 pm #1348154
aleadfreakParticipantHi,
Yes, that is what I have done. I already have a child’s theme. The code shown above is the same except it contains my Google tags code.
Thanks
Alex
January 28, 2017 at 12:24 am #1348617
FriechModeratorHi Alex,
Was it the Google Tag manager consist of two sets of code? The first one should go inside the
<head>tag/*THIS CODE WILL BE OUTPUT INSIDE THE <HEAD> tag*/ add_action('wp_head','my_tracking', 1); function my_tracking () { ?> <!-- Google Tag Manager --> <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); })(window,document,'script','dataLayer','GTM-T7LD9VH');</script> <!-- End Google Tag Manager --> <?php }And the other one is immediately after the opening
<body>tag. Which you’ll be using for this code.// Add Google Tag Manager Code // ============================================================================= function add_google_tag_manager_code(){ ?> <!-- Insert Google Tag Code starts here --> <!-- Insert Google Tag Code ends here --> <?php } add_action( 'x_before_site_begin', 'add_google_tag_manager_code' ); // End Add Google Tag Manager Code // =============================================================================Please refer here: https://developers.google.com/tag-manager/quickstart
Thanks.
January 28, 2017 at 9:25 am #1348893
aleadfreakParticipantOk, so where within the child theme files would I put the code in the head section? In the Header.php file? Or in the functions file?
To be clear, where do I put this:
/*THIS CODE WILL BE OUTPUT INSIDE THE <HEAD> tag*/ add_action('wp_head','my_tracking', 1); function my_tracking () { ?> <!-- Google Tag Manager --> <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); })(window,document,'script','dataLayer','GTM-T7LD9VH');</script> <!-- End Google Tag Manager --> <?php }January 28, 2017 at 11:25 am #1348964
ThaiModeratorHi There,
This code should be put under functions.php file locates in your child theme:
/*THIS CODE WILL BE OUTPUT INSIDE THE <HEAD> tag*/ add_action('wp_head','my_tracking', 1); function my_tracking () { ?> <!-- Google Tag Manager --> <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); })(window,document,'script','dataLayer','GTM-T7LD9VH');</script> <!-- End Google Tag Manager --> <?php }Regards!
February 4, 2017 at 11:57 am #1357968
aleadfreakParticipantOK,
Just so we’re clear…both bits of code (header code and body code) should be entered into the functions.php file.
Thanks
Alex
February 4, 2017 at 6:41 pm #1358178
Rue NelModeratorHello Alex,
You do not have to edit any file to add the header code or body. Just place both of the codes in your child theme’s functions.php file. The code itself will instruct WordPress to add the Google tag manager in the head/body section.
Hope this helps.
February 22, 2017 at 6:48 am #1381235
aleadfreakParticipantHi,
I’ve done exactly what was asked but I’m still getting an error.
Can you take a look please.
Thanks
Alex
February 22, 2017 at 9:59 am #1381535
DarshanaModeratorHi there,
Please provide us with your FTP credentials to check your issue.
Thanks!
March 9, 2017 at 5:48 am #1400425
aleadfreakParticipantThis reply has been marked as private.March 9, 2017 at 3:07 pm #1401061
RadModeratorHi there,
I checked and it’s added correctly, what error you’re currently getting?
Thanks!
-
AuthorPosts
- <script> jQuery(function($){ $("#no-reply-1347922 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>
