/tagmanager/community?hl=en
This content is likely not relevant anymore. Try searching or browse recent questions.
-
1/24/20
Google Tag Manager Code disappears when publishing 0 Recommended Answers 1 Reply 0 Upvotes
1 Recommended Answer
$0 Recommended Answers
Hi! 

So I'm trying to add Google Tag Manager to a Wordpress site using My Studio Press theme in Genesis framework. 

I have added the code code both through insert headers and footers and directly on the functions.php of the theme, and both times, after publishing, when I check it in the code, the code change to this (please see attached)

<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-KCQ3SHM');</script>

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

Instead of having the typical: 

<!-- 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','data

When I check it with Google Tag Assistant I see that the GTM is installed correctly and Analytics tag says non-standard implementation:





When I click on the question mark for that it sends me to this page: https://support.google.com/tagassistant/answer/3207128?ref_topic=2947092#nonstandard

Where it says that if the sample snippet doesn't look like this:

<!-- 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 -->

Then something is wrong.

Is there something wrong? Why would the code change if I'm pasting exactly what's provided by GTM 

This is what I pasted in the functions.php 

  1. //* Add Google Tag Manager code in <head>
  2. add_action( 'wp_head', 'dy_google_tag_manager_js' );
  3. function dy_google_tag_manager_js() { ?>
  4. <!-- Google Tag Manager -->
  5. <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
  6. new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
  7. j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
  8. 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
  9. })(window,document,'script','dataLayer','GTM-KCQ3SHM');</script>
  10. <!-- End Google Tag Manager -->
  11. <?php }
  12. //* Add Google Tag Manager code immediately after opening <body> tag
  13. add_action( 'genesis_before', 'dy_google_tag_manager_no_js' );
  14. function dy_google_tag_manager_no_js() { ?>
  15. <!-- Google Tag Manager (noscript) -->
  16. <noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-KCQ3SHM"
  17. height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
  18. <!-- End Google Tag Manager (noscript) -->
  19. <?php }

I hope someone can help me, in the mean time I'll leave as is. 

Thank you! 

Melissa
Details
All Replies (1)
1/26/20
Hm? What's the problem? GTM is green (loaded correctly), and you can ignore "Non-standard implementation" messages if GA is firing and collecting data on the site just fine.

When you copy-paste code to a page template, the CMS can modify / optimize it by e.g. removing unnecessary HTML comments and so forth.
marked this as an answer
Helpful?
This question is locked and replying has been disabled.
Discard post? You will lose what you have written so far.
Write a reply
10 characters required
Failed to attach file, click here to try again.
Discard post?
You will lose what you have written so far.
Personal information found

We found the following personal information in your message:

This information will be visible to anyone who visits or subscribes to notifications for this post. Are you sure you want to continue?

A problem occurred. Please try again.
Create Reply
Edit Reply
Delete post?
This will remove the reply from the Answers section.
Notifications are off
Your notifications are currently off and you won't receive subscription updates. To turn them on, go to Notifications preferences on your Profile page.
Report abuse
Google takes abuse of its services very seriously. We're committed to dealing with such abuse according to the laws in your country of residence. When you submit a report, we'll investigate it and take the appropriate action. We'll get back to you only if we require additional details or have more information to share.

Go to the Legal Help page to request content changes for legal reasons.

Reported post for abuse
Unable to send report.
Report post
What type of post are you reporting?
Google takes abuse of its services very seriously. We're committed to dealing with such abuse according to the laws in your country of residence. When you submit a report, we'll investigate it and take the appropriate action. We'll get back to you only if we require additional details or have more information to share.

Go to the Legal Help page to request content changes for legal reasons.

Reported post for abuse
Unable to send report.
This reply is no longer available.
/tagmanager/threads
//accounts.google.com/ServiceLogin
You'll receive email notifications for new posts at
Unable to delete question.
Unable to update vote.
Unable to update subscription.
You have been unsubscribed
Deleted
Unable to delete reply.
Removed from Answers
Marked as Recommended Answer
Removed recommendation
Undo
Unable to update reply.
Unable to update vote.
Thank you. Your response was recorded.
Unable to undo vote.
Thank you. This reply will now display in the answers section.
Link copied
Locked
Unlocked
Unable to lock
Unable to unlock
Pinned
Unpinned
Unable to pin
Unable to unpin
Marked
Unmarked
Unable to mark
Reported as off topic
/tagmanager/profile/0?hl=en