Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #1160823

    Hi,

    I am trying to add google tag manager, but it seems like I can only add the <head> script in the “google analytics tracking code” box.
    Where do I add/paste the <body> script? I.e this script:

    <!– Google Tag Manager (noscript) –>
    <noscript><iframe src=”https://www.googletagmanager.com/ns.html?id=GTM-M9R8TKM&#8221;
    height=”0″ width=”0″ style=”display:none;visibility:hidden”></iframe></noscript>
    <!– End Google Tag Manager (noscript) –>

    Thank you in advance!

    BR,
    Emma

    #1161402

    Hey Emmasfm,

    You will need to do this with code, as we do not have an option to add code inside body through our Theme Options.

    Best regards,
    Basilis

    #1184108

    I have the same problem with Emmasfm.
    Here are GTM script:
    GTM script
    – 1st Script: I copy a header.php from the Enfold into the child theme. And then, I paste the 1st script into between the <head>…..</head>
    – 2nd script: I paste after the <body> tag

    But when I check the status of Google Assistant Extension, the yellow color before the Google Tag Manager.
    The yellow color means that at least one Google Tag has a minor issue and the issue should be addressed, otherwise you might face some tracking discrepancies.
    How can I fix it? (You can see more detail in the private content)

    Enfold should have an article guide everyone about Google Tag Manager, I search any available can’t solve the problem.

    #1184319

    Hi ezvisa,

    Please have a look at the following thread:
    https://kriesi.at/support/topic/google-tag-manager-6/

    If you need further assistance please let us know.

    Best regards,
    Victoria

    #1184372

    Victoria, Ismael mention about using “wp_header” for put script into header and “wp_footer” for footer.
    But can you write full code for me? Because I have lacked the skill in coding.
    I very much appreciate that!

    #1184677

    Hi ezvisa,

    Please post the full code you are looking to add to your site and where it should go and, we’ll give you some functions to use.

    Best regards,
    Rikard

    #1413830

    Enfold Child > functions.php
    add these lines and change the GTM-Code to your Code.
    /**
    * Google Tag Manager Head Script
    */
    function add_custom_gtm(){
    ?>
    <!– 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-XXXXXXX’);</script>
    <!– End Google Tag Manager –>
    <?php
    }
    add_action(‘wp_head’, ‘add_custom_gtm’);
    /**
    * Google Tag Manager Body Script
    */
    function google_tag_manager_body_code() { ?>
    <!– Google Tag Manager (noscript) –>
    <noscript><iframe src=”https://www.googletagmanager.com/ns.html?id=GTM-XXXXXXX&#8221;
    height=”0″ width=”0″ style=”display:none;visibility:hidden”></iframe></noscript>
    <!– End Google Tag Manager (noscript) –>
    <?php }
    add_action( ‘ava_after_body_opening_tag’, ‘google_tag_manager_body_code’, 1);

    #1413902

    Hi xxtita,

    Thanks for sharing the code.
    For further information you can check our documentation: https://kriesi.at/documentation/enfold/google-analytics/

    Best regards,
    Nikko

    #1473582

    Dear support, @NIKKO @rikard
    I’ve been trying to implement the Google Tag Code from Google Ads for hours.
    But i get every the error:
    Uncaught Error: Undefined constant “‘wp_head’” in wp-content/themes/enfold-child/functions.php:24
    Stack trace:
    #0 wp-settings.php(672): include()
    #1 wp-config.php(104): require_once(‘/var/www/vhosts…’)
    #2 wp-load.php(50): require_once(‘/var/www/vhosts…’)
    #3 wp-admin/admin.php(34): require_once(‘/var/www/vhosts…’)
    #4 wp-admin/theme-editor.php(10): require_once(‘/var/www/vhosts…’)
    #5 {main}
    thrown
    What its wrong???

    Here is my script
    /**
    * Google Tag Manager Head Script
    */
    function add_custom_gtm(){
    ?>
    <!– 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-ABCDEFGH’);</script>
    <!– End Google Tag Manager –>
    <?php
    }

    add_action(‘wp_head’, ‘add_custom_gtm’);
    /**
    * Google Tag Manager Body Script
    */
    function google_tag_manager_body_code() { ?>
    <!– Google Tag Manager (noscript) –>
    <noscript><iframe src=”https://www.googletagmanager.com/ns.html?id=GTM-ABCDEFGH&#8221;
    height=”0″ width=”0″ style=”display:none;visibility:hidden”></iframe></noscript>
    <!– End Google Tag Manager (noscript) –>
    <?php }
    add_action( ‘ava_after_body_opening_tag’, ‘google_tag_manager_body_code’, 1);

    Can anybody help?

    #1473584

    it is very hard to check your codes – if you do not use here the code tag

    easiest way is to click once the code tag button – enter your code – click again the /code button
    because sometimes it is only the use of uncorrect quotation marks. etc.

    #1473587

    or try this ( replacing your GTM-IDs ) with copy&paste:

    i think it is ok to have both in head section

    function ava_g_tag_custom_script() { 
    ?>
    <!-- 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-XXXXX');
    </script>
    <!-- End Google Tag Manager -->  
    
    <!-- Google Tag Manager (noscript) -->
    <noscript>
      <iframe src="https://www.googletagmanager.com/ns.html?id=GTM-XXXXX"
      height="0" width="0" style="display:none;visibility:hidden"></iframe>
    </noscript>
    <!-- End Google Tag Manager (noscript) --> 
    <?php
    }
    add_action('wp_head', 'ava_g_tag_custom_script');

    but if you like to have the noscript in body tag:

    function ava_g_tag_custom_script() { 
    ?>
    <!-- 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-XXXXX');
    </script>
    <!-- End Google Tag Manager -->  
    
    <!-- Google Tag Manager (noscript) -->
    <noscript>
      <iframe src="https://www.googletagmanager.com/ns.html?id=GTM-XXXXX"
      height="0" width="0" style="display:none;visibility:hidden"></iframe>
    </noscript>
    <!-- End Google Tag Manager (noscript) --> 
    <?php
    }
    add_action('wp_head', 'ava_g_tag_custom_script');
    #1473588

    the signs of <!-- Google Tag Manager --> are not right – and you used instead of two single quotes on one place one double Quote
    (here after that part : …'dataLayer'?'&l='+l: )

    #1473596

    Guenni007 so great for your fast help!

    Arrr … i don’t usede the code tag …. :(
    Sorry total!
    Bist Du Deutscher?

    #1473597

    Guenni007,

    Yeahhhh!!! Your Code is great. That works great!!!!

    function ava_g_tag_custom_script() { 
    ?>
    <!-- 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-XXXXXXXXX');
    </script>
    <!-- End Google Tag Manager -->  
    
    <!-- Google Tag Manager (noscript) -->
    <noscript>
      <iframe src="https://www.googletagmanager.com/ns.html?id=GTM-XXXXXXXXX"
      height="0" width="0" style="display:none;visibility:hidden"></iframe>
    </noscript>
    <!-- End Google Tag Manager (noscript) --> 
    <?php
    }
    add_action('wp_head', 'ava_g_tag_custom_script');

    So many thanks for your great help!

    I am so happy!

    Thanks and regards strumpel

    #1473600

    Hi,
    Glad Guenni007 could help, thank you Guenni007, if you have any further questions please create a new thread and we will gladly try to help you. Thank you for using Enfold.

    Best regards,
    Mike

Viewing 15 posts - 1 through 15 (of 15 total)
  • The topic ‘Adding google tag manager in Enfold’ is closed to new replies.