Viewing 27 posts - 1 through 27 (of 27 total)
  • Author
    Posts
  • #372558

    A.
    We need to add the “Google Tag Manger» http://www.google.com/tagmanager/ code to our Enfold site at http://KundeKontroll.no

    B.
    We would like to add the code as a «hook» or in some other way so the Google Tag manger code does not get overwritten / deleted every time there is a new version of WordPress or the Enfold theme. If I add the code to the /enfold/functions.php or header.php file then it’s being overwritten when upgrading to the next version of Enfold or WordPress. How can I add the code so there is no need to re-enter the GTM code every time there is a new version of WordPress or Enfold?

    C.
    This is the code that needs to be placed just after the opening / start <body> tag.

    <!– Google Tag Manager –>
    <noscript><iframe src=”//www.googletagmanager.com/ns.html?id=GTM-MN3P7B”
    height=”0″ width=”0″ style=”display:none;visibility:hidden”></iframe></noscript>
    <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=
    ‘//www.googletagmanager.com/gtm.js?id=’+i+dl;f.parentNode.insertBefore(j,f);
    })(window,document,’script’,’dataLayer’,’GTM-MN3P7B’);</script>
    <!– End Google Tag Manager –>

    #372577

    Hi limedrop!

    You can use a child theme to avoid making the changes each time you update the theme – http://kriesi.at/documentation/enfold/using-a-child-theme/
    You can download pre-built Enfold Child theme here – http://kriesi.at/documentation/enfold/downloads/

    Cheers!
    Yigit

    #372756

    Should the GTM code be added to the file:

    /enfold/functions.php

    or

    header.php

    #373011

    Hey!

    Please try adding following code to Functions.php file of your child theme

    function add_custom_gtm(){
    ?>
    <noscript><iframe src="//www.googletagmanager.com/ns.html?id=GTM-MN3P7B"
    height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
    <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=
    '//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
    })(window,document,'script','dataLayer','GTM-MN3P7B');</script>
    <?php
    }
    add_action('wp_head', 'add_custom_gtm');

    Best regards,
    Yigit

    • This reply was modified 9 years, 4 months ago by Yigit.
    #375698
    #376804

    Hey!

    Please try adding the code you posted in your first post C, to header.php file of your child theme.

    Cheers!
    Yigit

    #463771

    Hey!

    add_action(‘wp_header’, ‘add_custom_gtm’);

    should be

    add_action(‘wp_head’, ‘add_custom_gtm’);

    Please change it and it will work – I add it here for feature references, from search engine results.

    Regards,
    Basilis

    • This reply was modified 9 years, 4 months ago by Basilis.
    #675082

    Hi Team, picking up on this issue – the solution proposed here places the GTM code near the </head> since we’re using wp_head(). Is there a hook we can right after <body>?

    #676728

    Hi,

    Use the “ava_after_main_container” action hook.

    add_action( 'ava_after_main_container', 'ava_after_main_container_mod', 10);
    function ava_after_main_container_mod() {
         // do something here
    }

    Best regards,
    Ismael

    #680426

    Thanks. I will call you “Ismael.”

    Just FYI, I had a very bad experience last weekend. I was using a GTM WordPress plugin that totally hosed our site. It had been working fine, for about a year, until I got a call that the client’s web site was down. I checked and sure enough…At first I had no idea what it was then I looked at the error log and traced it to this plugin (I prefer not to say it’s name). I have limited time to debug such arcane things but I suspect it was related to the most recent WP update or the most recent Theme update. Not pointing fingers, just saying it was VERY painful. <panic>I could not login as the Admin to delete the plugin</panic>Eventually I uninstalled the plugin and contacted the developer who gave me a long workaround. But I can’t have that kind of thing happening on a client site.

    I think I will try Ismael’s suggestion above.

    #681145

    Hi @Frank,

    Great, let us know how you get on with it. We’ll leave the thread open in case you should need any further help.

    Regards,
    Rikard

    #714371

    Hi guys,

    Whenever I try to use Ismael’s code and add the Tag Manager to the <body> it gives me the following error:

    Parse error: syntax error, unexpected ‘<‘ in /wp-content/themes/enfold-child/functions.php on line 10

    What am I missing?
    The code in question is below.

    Cheers,
    Chip

    #714432

    Hi Chip,

    Please try this instead.

    add_action( 'ava_after_main_container', 'ava_after_main_container_mod', 10);
    
    function ava_after_main_container_mod() { ?>
    <noscript><iframe src=”https://www.googletagmanager.com/ns.html?id=GTM-5BLRX8S”
    height=”0″ width=”0″ style=”display:none;visibility:hidden”></iframe></noscript>
    <?php }

    Best regards,
    Rikard

    #722625

    I am unclear of the steps to make this happen yet reluctant to start new thread. Please help with google tag manager code placement-
    To sum, Google tag manager requires
    1) code high in the <head> of the page
    and
    2) Code immediately after the <body> tag

    Can you provide a solution for both? I am using a child theme and would love it if you could say
    “Do this “xyz [PASTE YOUR GOOGLE HEAD CODE HERE] in child theme (xyz) file
    and
    then do
    “Do this ”abc code then [PASTE YOUR GOOGLE BODY CODE HERE] in chil theme xyz file

    like many who buy themes that promise no custom coding, I am code illiterate so please bear that in mind :) thanks in advance

    #723370

    Bump

    #723467

    Hi thanp73,

    Since you are using child theme, you can copy header.php of the parent theme (Enfold) and paste it in your child theme. Edit header.php in your child theme.

    1. Find this line of code (line 48):
    </head>
    and place the googletagmanager script above it, the code should look something like this:

    <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=
    ‘//www.googletagmanager.com/gtm.js?id=’+i+dl;f.parentNode.insertBefore(j,f);
    })(window,document,’script’,’dataLayer’,’GTM-XXXXXX’);</script>

    2. Find this line of code:
    <body id="top" <?php body_class($style." ".$avia_config['font_stack']." ".$blank." ".$sidebar_styling); avia_markup_helper(array('context' => 'body')); ?>>
    it should just below the head tag. And place the code that looks like this:

    <noscript><iframe src=”//www.googletagmanager.com/ns.html?id=GTM-XXXXXX”
    height=”0″ width=”0″ style=”display:none;visibility:hidden”></iframe></noscript>

    Hope this helps.

    Regards,
    Nikko

    #723471

    If I copy the header.php into the child theme, wont I have to copy it again and re-insert this code once Enfold has a new update?

    The ideal solution here is a HOOK added by the Kriesi team to the parent theme. We could then add some code to the functions.php to inject the GTM pixel. Is that something we can request from the Dev team?

    #723476

    Hi,

    Yes, you can request it here: https://kriesi.at/support/enfold-feature-requests/

    If I copy the header.php into the child theme, wont I have to copy it again and re-insert this code once Enfold has a new update?

    No, the purpose of child theme is to override the parent theme and if there’s a theme update it won’t be lost, the only time you need to re-insert this is when there’s a change in header.php and you need update the header.php of your child theme. Though I would agree that the best solution is to use hooks especially if your not using a child theme.

    Regards,
    Nikko

    #723477

    makes sense to me- My guy added header php to the child theme and manually put in my GTM code there. it’s working, now, but there is also a pending enfold theme update that I’m not sure what it’ll do.

    For some reason, too, the GTM script check routine shows all my tags being fired twice per page load.

    so, still an open issue here.

    #723481

    Nikko- thanks for the clear instructions, that’s just what a layman needs and what we did.

    incidentally,the file reads like this:

    /* Always have wp_head() just before the closing </head>
     * tag of your theme, or you will break many plugins, which
     * generally use this hook to add elements to <head> such
     * as styles, scripts, and meta tags.
     */
    
    wp_head();
    
    ?>
    
    </head>

    So I read that to mean, don’t put your GTM code between the last ?> and the </head>

    Instead, my guy put it higher up, just after the <head>.. but that said, we are still getting double fires of pixels. maybe it’s OK to put the GTM code right before the </head>?

    #723797

    Hi thanp73,

    It’s okay if you put it after the
    <head>
    or before
    </head>
    as long as it’s in the head. Just to clarify you’re statement above, do you mean it executes the gtm code twice? try to deactivate all plugins and check if it still does that, if yes, can you give us a link to your site, a temporary admin access and ftp access? so we can check it further.

    Cheers!
    Nikko

    #723929

    the issues with double firing tags were on my end, there was another coder’s attempt to make this work buried in code somewhere I did not see so all is cleared up. the solution you had outlined works perfectly-

    in short, copy header to child theme, insert in the places as shown, and good to go.

    Question- how would we know when an update to Enfold would require an update to our child theme’s header file? Is there a reason why you don’t make the header.php automatically part of child themes?

    • This reply was modified 7 years, 10 months ago by thanp73.
    #725962

    Hey!

    Question- how would we know when an update to Enfold would require an update to our child theme’s header file? Is there a reason why you don’t make the header.php automatically part of child themes?

    There will be no indication for that, unfortunately. You will know if there are changes in the file if you encounter an error or something is off in the frontend. You don’t have to worry about this because the header.php file is not updated frequently.

    The child theme only requires a functions.php and a style.css file in order to work.

    // https://codex.wordpress.org/Child_Themes

    Regards,
    Ismael

    #775159

    I added Google Tag Manager (GTM) code as suggested by Ismael inside <head> and <body> tag.
    Chrome Tag Manager extension can find GTM, but Google Search Console says GTM is on wrong place and will not confirm my website.
    Anybody had the same problem? Trying now for more than one hour but always get this error message in Google Search Console.

    #778580

    Hi Ilvy,

    Sorry for the late response, can you post a link to your site? so we can check the code’s location, just put it in Private Content, if you want to keep the link private.

    Best regards,
    Nikko

    #911795

    Hi,

    For everyone still coming to this page… The code is fine and works from functions.php but I had the issue that my adblocker was actually blocking the tags inside of the tag manager.

    So I could see with Ghostly that the tag manager was running but got errors on the scripts (tags) I was trying to run. You can see this with the Chrome extension: https://chrome.google.com/webstore/detail/tag-assistant-by-google/kejbdjndbnbjgmefkgdddjlbokphdefk?hl=en-US

    It will show this error: “ERR_BLOCKED_BY_CLIENT

    Cheers

    • This reply was modified 6 years, 8 months ago by Liv.
    #912071

    Hi,


    @liv2day_com
    : Thanks for the info.

    Please create a new thread or ticket if you’re still having this issue. We’ll check it there.

    Best regards,
    Ismael

Viewing 27 posts - 1 through 27 (of 27 total)
  • The topic ‘Adding the Google Tag Manager code permanently’ is closed to new replies.