Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't Google Tag Manager be installed within another HTML element under the body?

The instructions for Google Tag Manager insists installing Google Tag Manager code immediately after the opening body tag. However, this is not always possible for some websites (without a ton of modification).

Trouble is, you can install Google Tag Manager elsewhere within a page and the tags appear to fire. However, if you check the installation with Google Tag Assistant, it fires a critical issue:

"Error: tag must not be included in a <div>"

When you click on the error message, you're directed to Google's lean documentation :

Google Tag Manager Tag should be placed immediately after the opening tag and not inside any other HTML element. The Google Tag Manager snippet must be placed directly in the page that you intend on tracking. Placing it in a hidden iframe or deploying it within another tag management system will prevent certain tags from accurately tracking the parent page. Tags added via Google Tag Manager may not fire. Please make sure to place the GTM snippet immediately after the opening tag.

  • Which sorts of tags won't fire?
  • Is it only for certain browsers?
  • Will it cause other issues?
like image 492
Robert Kingston Avatar asked Dec 19 '13 00:12

Robert Kingston


1 Answers

This guideline is trying to help avoid some specific problems with using appendChild on unclosed ancestor elements in older versions of IE:

http://support.microsoft.com/kb/927917 (archive)

http://blogs.msdn.com/b/ie/archive/2008/04/23/what-happened-to-operation-aborted.aspx (archive)

You can avoid these problems by always placing your GTM snippet directly inside the body tag, not wrapped in any other elements (e.g. <div> or <td>).

like image 124
Brian Avatar answered Oct 24 '22 15:10

Brian