Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Heh, why can't you use any hook instead of regex and page source changing.
<!--[if lt IE 7 ]> <body id="homepage" class="ie ie6 html front not-logged-in one-sidebar sidebar-second page-node page-node- page-node-603 node-type-panel tao">
<!-- Google Tag Manager -->
......................
<!-- End Google Tag Manager --> <![endif]-->
<!--[if IE 7 ]> <body id="homepage" class="ie ie7 html front not-logged-in one-sidebar sidebar-second page-node page-node- page-node-603 node-type-panel tao"> <![endif]-->
<!--[if IE 8 ]> <body id="homepage" class="ie ie8 html front not-logged-in one-sidebar sidebar-second page-node page-node- page-node-603 node-type-panel tao"> <![endif]-->
<!--[if IE 9 ]> <body id="homepage" class="ie ie9 html front not-logged-in one-sidebar sidebar-second page-node page-node- page-node-603 node-type-panel tao"> <![endif]-->
<!--[if !IE]><!--> <body id="homepage" class="html front not-logged-in one-sidebar sidebar-second page-node page-node- page-node-603 node-type-panel tao"> <!--<![endif]-->
As you can see in that specific case HTML is not valid. GTM appears between HEAD and BODY and <!-- <!--
construction is not allowed.
We have
<!--[if IE 7 ]> <body id="homepage" class="ie ie7 html front not-logged-in one-sidebar sidebar-second page-node page-node- page-node-603 node-type-panel tao"> <![endif]-->
<!--[if IE 8 ]> <body id="homepage" class="ie ie8 html front not-logged-in one-sidebar sidebar-second page-node page-node- page-node-603 node-type-panel tao"> <![endif]-->
<!--[if IE 9 ]> <body id="homepage" class="ie ie9 html front not-logged-in one-sidebar sidebar-second page-node page-node- page-node-603 node-type-panel tao"> <![endif]-->
<!--[if !IE]><!--> <body id="homepage" class="html front not-logged-in one-sidebar sidebar-second page-node page-node- page-node-603 node-type-panel tao"> <!--<![endif]-->
In our page template and the first one conditional comment
<!--[if lt IE 7 ]> <body id="homepage" class="ie ie6 html front not-logged-in one-sidebar sidebar-second page-node page-node- page-node-603 node-type-panel tao"><!--<![endif]-->
outside our HTML, it seems it comes from parent theme. But that doesn't matter at all i think.
Comment | File | Size | Author |
---|---|---|---|
#3 | google_tag-2364013-3.patch | 434 bytes | Jody Lynn |
Comments
Comment #1
rantie86@gmail.com CreditAttribution: rantie86@gmail.com commentedComment #2
rantie86@gmail.com CreditAttribution: rantie86@gmail.com commentedThis fixe the issue:
Comment #3
Jody LynnThis is a patch of rantie86's solution.
I found this issue because I was having a bug that made me unable to upload or remove files using the core file ajax widget. I suppose a specific combination of HTML and/or js led to this invalid HTML wreaking havoc on my site. It was not easy to track it down to this module.
I can confirm that the patch fixes my issue, but I'm not good enough with regex to confirm if the solution is otherwise good. I can definitely agree it's critical. It's possible that users of this module are having bugs and do not know this is the source.
Comment #4
solotandem CreditAttribution: solotandem commentedThe
you two like is specific to your use cases. If the were arranged in a different order or included different tests, then your regex would fail. My questions to you (or anyone else reading this issue) are:@rantie86@gmail.com, if you know of a hook that can be used with certainty to accomplish this insertion (and without regex), then please indicate such.
A regular expression was used because of the uncertainty of what might be in the page and how it might come together. To my knowledge, it is not a trivial task to place some content first on the page without knowledge of the theme. Again, I am open to suggestions on how to accomplish this.
Comment #5
Jody LynnThanks solotandem. Looks like rantie's regex only served in my case to make sure I end up with no gtm script, rather than fixing it. Perhaps my issue is an unrelated bug with the gtm script.
My html around the beginning of body is:
Comment #6
Jody LynnI found the real source of my issue: #2424749: Page paths setting is ineffective.
Comment #7
bartramos CreditAttribution: bartramos at ezCompany commentedThis issue has been sleeping for more than a year now. There's another issue that might be a solution to this case: #2638752-2: add configurable regexp so I will close this issue. If someone has a valid reason to reopen it, please be my guest :-)