我試著把 Google Tag Manager 的 trace code 整合在 Blogger 內,但出現了 XML error: The reference to entity "l" must end with the ';' delimiter.。
以下是 Google Tag Manager 提供的 trace code
<!-- 20141223 Trace for Google Tag Manager -->
<noscript><iframe src="//www.googletagmanager.com/ns.html?id=GTM-KJ4PG3"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript><script type='text/javascript'>
(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=
'//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-XXXXXX');</script>
<!-- End Google Tag Manager -->
Solution 解決方法
After Google, I found an ampersand "&l" which hasn't been escaped properly from trace code. From the DTD (Document Type Definition), it suggests that we might use an entity as 3 parts: "&", "entity name", and ";", namely &l;.
在 Google 後,我發現原來 Google Tag Manager 的 trace code 內的 &l 寫法並未正確的逃脫,以 DTD 的要求來說,一個實體是由三個部份組成:一個和號 (&)、一個實體名稱、以及一個分號 (;),所以 &l 必須寫成 &l;。
But even I used the $l; which comply the regular of DTD, the XML error message still happen. After I change to use "&l", it works.
但我發現即使改用了 DTD 建議的寫法:$l;,還是出現了相同的錯誤。後來我改用了畸型的寫法 &l 竟然就正常了。
Frankly, I really don't know why. It just works.
老實說,我還是不知道為什麼,但它就是有用!
- coderanch -ERROR: 'The reference to entity L must end with the ';' delimiter.' (Java API forum at JavaRanch)
- w3school -DTD
- Google 產品論壇 -Google Tag manager to blogger?