• 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

Anybody Successfully Implemented Google Tag Manager on Agency Pro or similar?

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 › Anybody Successfully Implemented Google Tag Manager on Agency Pro or similar?

This topic is: resolved

Tagged: google tag manager

  • This topic has 11 replies, 3 voices, and was last updated 10 years ago by mondefurr34.
Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • November 17, 2015 at 9:26 pm #171372
    TeeSchneider
    Participant

    I'm having a lot of trouble. There are no opening body tags in the header.php for standard implementation. If I add to functions.php as one post suggested it throws an error saying it cannot be contained in a div. Plugins seem to be outdated. I can get the code in an partially working using simple hooks but still...errors. Anybody have xp with this?

    http://bespokably.com/
    November 17, 2015 at 9:47 pm #171374
    carasmo
    Participant

    Isn't that just some javascript? If so, you would login to your Admin > Genesis > Theme Settings and paste the code in either the header or footer area.

    Read docs: http://my.studiopress.com/setup/modern-studio-pro-theme/customize-your-settings/genesis-theme-settings/

    Your theme settings page is similar on all themes and they all have the header and footer scripts area.


    Genesis Theme Customization and Help

    November 17, 2015 at 9:52 pm #171376
    TeeSchneider
    Participant

    Unfortunately the Google Tag Manager code has to be implemented right after the opening body tag. The theme setting allows for something right before the closing head or body tag but not the opening.

    I can get a non-standard implementation on another genesis child them working relatively well using a plugin and simple hooks but Agency Pro somehow place the code within a div tag which GTM doesn't like at all.

    November 17, 2015 at 10:04 pm #171377
    carasmo
    Participant

    In functions.php. Where GTM-XXXX in line 4 and 10 is your code. Follow the syntax exactly, don't remove escapes.

    add_action( 'genesis_before', 'cab_google_tag_manager', 5 );
    function cab_google_tag_manager() {
    print "<!-- Google Tag Manager -->\n";
    print "<noscript><iframe src=\"//www.googletagmanager.com/ns.html?id=GTM-XXXX\"\n";
    print "height=\"0\" width=\"0\" style=\"display:none;visibility:hidden\"></iframe></noscript>\n";
    print "<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':\n";
    print "new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],\n";
    print "j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=\n";
    print "'//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);\n";
    print "})(window,document,'script','dataLayer','GTM-XXXX');</script>\n";
    print "<!-- End Google Tag Manager -->";
    }
    

    Genesis Theme Customization and Help

    November 17, 2015 at 10:17 pm #171379
    TeeSchneider
    Participant

    Ok, did that. Google analytics implements fine but I get the same error with GTM which is:

    <script> tag must not be included in a <div>

    November 17, 2015 at 10:37 pm #171381
    carasmo
    Participant

    Change the priority to 1 instead of 5.

    add_action( 'genesis_before', 'cab_google_tag_manager', 1 );
    function cab_google_tag_manager() {
    print "<!-- Google Tag Manager -->\n";
    print "<noscript><iframe src=\"//www.googletagmanager.com/ns.html?id=GTM-XXXX\"\n";
    print "height=\"0\" width=\"0\" style=\"display:none;visibility:hidden\"></iframe></noscript>\n";
    print "<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':\n";
    print "new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],\n";
    print "j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=\n";
    print "'//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);\n";
    print "})(window,document,'script','dataLayer','GTM-XXXX');</script>\n";
    print "<!-- End Google Tag Manager -->";
    }

    Genesis Theme Customization and Help

    November 17, 2015 at 10:50 pm #171384
    TeeSchneider
    Participant

    Great! The only think I'm now getting is for GA which says:

    Non-standard implementation

    GTM is green.

    I'm assuming the non-standard implementation isn't the worst so long as the codes fire?

    November 18, 2015 at 7:50 am #171406
    carasmo
    Participant

    https://productforums.google.com/forum/#!topic/tag-manager/ynpG7Q1emZQ


    Genesis Theme Customization and Help

    November 18, 2015 at 9:00 am #171411
    TeeSchneider
    Participant

    Thanks so much for all your help! I was going crazy.

    November 18, 2015 at 2:17 pm #171463
    carasmo
    Participant

    Sure.

    I used this http://www.andrewdavidson.com/convert-html-to-php/ to convert the function. I just opened up the functions.php in your theme, it's using 5 for the before_genesis and so that was the blip.


    Genesis Theme Customization and Help

    November 18, 2015 at 2:18 pm #171464
    carasmo
    Participant

    Can you mark this resolved for others to see.


    Genesis Theme Customization and Help

    November 18, 2015 at 6:26 pm #171488
    mondefurr34
    Member

    This is outstanding!

  • Author
    Posts
Viewing 12 posts - 1 through 12 (of 12 total)
  • The topic ‘Anybody Successfully Implemented Google Tag Manager on Agency Pro or similar?’ is closed to new 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