Community Forums › Forums › Archived Forums › General Discussion › Anybody Successfully Implemented Google Tag Manager on Agency Pro or similar?
Tagged: google tag manager
- This topic has 11 replies, 3 voices, and was last updated 9 years, 4 months ago by
mondefurr34.
-
AuthorPosts
-
November 17, 2015 at 9:26 pm #171372
TeeSchneider
ParticipantI'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 #171374carasmo
ParticipantIsn'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.
Your theme settings page is similar on all themes and they all have the header and footer scripts area.
November 17, 2015 at 9:52 pm #171376TeeSchneider
ParticipantUnfortunately 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 #171377carasmo
ParticipantIn 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 -->"; }
November 17, 2015 at 10:17 pm #171379TeeSchneider
ParticipantOk, 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 #171381carasmo
ParticipantChange 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 -->"; }
November 17, 2015 at 10:50 pm #171384TeeSchneider
ParticipantGreat! 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 #171406carasmo
ParticipantNovember 18, 2015 at 9:00 am #171411TeeSchneider
ParticipantThanks so much for all your help! I was going crazy.
November 18, 2015 at 2:17 pm #171463carasmo
ParticipantSure.
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.
November 18, 2015 at 2:18 pm #171464carasmo
ParticipantNovember 18, 2015 at 6:26 pm #171488mondefurr34
MemberThis is outstanding!
-
AuthorPosts
- The topic ‘Anybody Successfully Implemented Google Tag Manager on Agency Pro or similar?’ is closed to new replies.