• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Google Tag Manager

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › General Discussion › Google Tag Manager

This topic is: not resolved

Tagged: google tag manager

  • This topic has 6 replies, 2 voices, and was last updated 8 years, 3 months ago by jeffbogaczyk.
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • February 13, 2017 at 11:14 am #201049
    jeffbogaczyk
    Participant

    I'm trying to add Google Tag Manager to my Lifestyle Pro Genesis Child theme. There are two parts to this. Part one is:

    Paste this code as high in the <head> of the page as possible:
    <!-- 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 -->

    I can place this no problem in multiple ways - editing Genesis header.php and placing the code there, or by putting it in the box in the Genesis Theme settings, or even with simple hooks. I'm wondering what is the best method and second where do I put the second part of the code.

    Additionally, paste this code immediately after the opening <body> tag:

    <!-- Google Tag Manager (noscript) -->
    <noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-W6VGNHX"
    height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
    <!-- End Google Tag Manager (noscript) -->

    I have tried many ways to get this in there but none have been successful and I'm still getting an error that no matter what way I try to get it in there (code added to function.php, similar attempts in simple hooks) , it is outside the <body> tag. Any help would be greatly appreciated.

    http://www.mindforlife.org/
    February 13, 2017 at 12:31 pm #201055
    Victor Font
    Moderator

    The genesis_before hook executes immediately after the body tag. You can use the Genesis Simple Hooks plugin or create a function to add your code:

    add_action( 'genesis_before', 'my_google_tag_manager_code');
    function my_google_tag_manager_code() {
        echo "<!-- Google Tag Manager (noscript) -->";
        echo '<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-W6VGNHX" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>';
        echo "<!-- End Google Tag Manager (noscript) -->";
    }

    I tested this in my local environment using the Genesis Sample theme.


    Regards,

    Victor
    https://victorfont.com/
    Call us toll free: 844-VIC-FONT (842-3668)
    Have you requested your free website audit yet?

    February 13, 2017 at 2:05 pm #201071
    jeffbogaczyk
    Participant

    Victor,

    I tried posting the code into the genesis_before hook but am getting the error that the code is outside of the <body> tag. I also pasted your code into the functions.php file and still no luck. I'm not sure what I'm doing wrong on this.

    February 13, 2017 at 3:27 pm #201081
    Victor Font
    Moderator

    That code works fine in functions.php. I tested it. I just looked at your site source code and you are inserting it twice directly after the body tag and once in the site header. My code dosen't touch the site header. The error is coming from something you did prior to adding my code.


    Regards,

    Victor
    https://victorfont.com/
    Call us toll free: 844-VIC-FONT (842-3668)
    Have you requested your free website audit yet?

    February 13, 2017 at 8:59 pm #201105
    jeffbogaczyk
    Participant

    Victor,

    I must be doing something wrong. I'm sorry I'm not a coder and I can't figure it out. I put your code in the functions.php of the child theme, but when I put the other Google tag code in after the <head> tag, I get an error with Google tag assistant saying the code is found outside the <body> tag. The Google Tag Manager says that there's supposed to be two sections of code so I'm not sure how to get it to work. When you tested it with the Genesis sample, were you running the Google Tag assistant to verify the tag manager was working on the site and everything was good?

    February 14, 2017 at 10:13 am #201142
    Victor Font
    Moderator

    No. I wasn't using Google tag assistant. I simply tested it to make sure the code appeared where you asked. If you're having trouble getting it to work, I suggest hiring someone to help you. I gave you want you asked for, beyond that, helping will require access to the backend of your site and testing that goes beyond what I can do as a community volunteer.


    Regards,

    Victor
    https://victorfont.com/
    Call us toll free: 844-VIC-FONT (842-3668)
    Have you requested your free website audit yet?

    February 14, 2017 at 11:40 am #201148
    jeffbogaczyk
    Participant

    Sure. Thanks for all your help.

  • Author
    Posts
Viewing 7 posts - 1 through 7 (of 7 total)
  • The forum ‘General Discussion’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2025 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble