XML 程序包中 Google 跟踪代码管理器脚本的解析错误
Parse error in Google Tag Manager script in XML Package
我有一个网店,运行 ASPDOTNETSTOREFRONT。
我正在尝试将自定义的跟踪脚本行添加到一组网页中。
为此,我将 Google 标签管理器脚本添加到这些页面使用的 XML 包中,因此它会出现在我要跟踪的所有页面上。
我只是将 Google 跟踪代码管理器脚本复制并粘贴到我的 XML 包中。
`<!-- Google Tag Manager -->
<noscript><iframe src="//www.googletagmanager.com/ns.html?id=GTM-5HD6WH"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<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=
'//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-5HD6WH');</script>
<!-- End Google Tag Manager -->`
但是当我尝试使用这个包加载页面时,出现以下错误。
Exception=Error in XmlPackage(.Load), Package=[product.engineproduct.xml.config], Msg=[Exception=An error occurred while parsing EntityName. Line 246, position 42.
]
所以人们可以看到行号和位置,我可以显示 XML 包(源代码)的屏幕截图。
http://i.stack.imgur.com/mJ2Tb.jpg
有人对如何解决这个问题有任何建议吗?
尝试将脚本内容放入 CDATA 中:
<!-- Google Tag Manager -->
<noscript><iframe src="//www.googletagmanager.com/ns.html?id=GTM-5HD6WH"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<script>
<![CDATA[
(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-5HD6WH');
]]>
</script>
<!-- End Google Tag Manager -->
1 年后...我在 DNN 7.4.2 中遇到了同样的问题。
我在 httpdocs/SiteAnalytics.config
中有类似的东西
<?xml version="1.0" encoding="utf-8" ?>
<AnalyticsEngineConfig>
<Engines>
<AnalyticsEngine>
<EngineType>DotNetNuke.Services.Analytics.GoogleAnalyticsEngine, DotNetNuke</EngineType>
<ElementId>Head</ElementId>
<InjectTop>False</InjectTop>
<ScriptTemplate>
<!-- Google Tag Manager -->
<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=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','<Tracking ID>');
</script>
<!-- End Google Tag Manager -->
<!-- documented... we would like to disable it by now
<![CDATA[
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', '[TRACKING_ID]']);
_gaq.push(['_trackPageview']);
[PAGE_URL]
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'stats.g.doubleclick.net/dc.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
]]>
-->
</ScriptTemplate>
</AnalyticsEngine>
</Engines>
</AnalyticsEngineConfig>
看,我知道我将把它留作手动更改(但是,正如我现在看到的那样,我认为将新的 google 标签管理器与 DNN 功能和菜单集成将非常容易)。
@dubloons 提议的改变对我不起作用,所以我这样做了:
<?xml version="1.0" encoding="utf-8" ?>
<AnalyticsEngineConfig>
<Engines>
<AnalyticsEngine>
<EngineType>DotNetNuke.Services.Analytics.GoogleAnalyticsEngine, DotNetNuke</EngineType>
<ElementId>Head</ElementId>
<InjectTop>False</InjectTop>
<ScriptTemplate>
<!-- Google Tag Manager -->
<![CDATA[
<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=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','<Tracking ID>');
</script>
]]>
<!-- End Google Tag Manager -->
<!-- documented... we would like to disable it by now
<![CDATA[
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', '[TRACKING_ID]']);
_gaq.push(['_trackPageview']);
[PAGE_URL]
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'stats.g.doubleclick.net/dc.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
]]>
-->
</ScriptTemplate>
</AnalyticsEngine>
</Engines>
</AnalyticsEngineConfig>
如您所见,我在 CDATA 中包围了所有脚本标签,而不仅仅是 JS 代码。
将类似于 GTM-XXXXXX。
如您所见,Tracking ID 被 know 硬编码,但那是另一个问题;D.
我有一个网店,运行 ASPDOTNETSTOREFRONT。
我正在尝试将自定义的跟踪脚本行添加到一组网页中。
为此,我将 Google 标签管理器脚本添加到这些页面使用的 XML 包中,因此它会出现在我要跟踪的所有页面上。
我只是将 Google 跟踪代码管理器脚本复制并粘贴到我的 XML 包中。
`<!-- Google Tag Manager -->
<noscript><iframe src="//www.googletagmanager.com/ns.html?id=GTM-5HD6WH"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<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=
'//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-5HD6WH');</script>
<!-- End Google Tag Manager -->`
但是当我尝试使用这个包加载页面时,出现以下错误。
Exception=Error in XmlPackage(.Load), Package=[product.engineproduct.xml.config], Msg=[Exception=An error occurred while parsing EntityName. Line 246, position 42.
]
所以人们可以看到行号和位置,我可以显示 XML 包(源代码)的屏幕截图。
http://i.stack.imgur.com/mJ2Tb.jpg
有人对如何解决这个问题有任何建议吗?
尝试将脚本内容放入 CDATA 中:
<!-- Google Tag Manager -->
<noscript><iframe src="//www.googletagmanager.com/ns.html?id=GTM-5HD6WH"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<script>
<![CDATA[
(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-5HD6WH');
]]>
</script>
<!-- End Google Tag Manager -->
1 年后...我在 DNN 7.4.2 中遇到了同样的问题。
我在 httpdocs/SiteAnalytics.config
中有类似的东西<?xml version="1.0" encoding="utf-8" ?>
<AnalyticsEngineConfig>
<Engines>
<AnalyticsEngine>
<EngineType>DotNetNuke.Services.Analytics.GoogleAnalyticsEngine, DotNetNuke</EngineType>
<ElementId>Head</ElementId>
<InjectTop>False</InjectTop>
<ScriptTemplate>
<!-- Google Tag Manager -->
<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=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','<Tracking ID>');
</script>
<!-- End Google Tag Manager -->
<!-- documented... we would like to disable it by now
<![CDATA[
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', '[TRACKING_ID]']);
_gaq.push(['_trackPageview']);
[PAGE_URL]
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'stats.g.doubleclick.net/dc.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
]]>
-->
</ScriptTemplate>
</AnalyticsEngine>
</Engines>
</AnalyticsEngineConfig>
看,我知道我将把它留作手动更改(但是,正如我现在看到的那样,我认为将新的 google 标签管理器与 DNN 功能和菜单集成将非常容易)。
@dubloons 提议的改变对我不起作用,所以我这样做了:
<?xml version="1.0" encoding="utf-8" ?>
<AnalyticsEngineConfig>
<Engines>
<AnalyticsEngine>
<EngineType>DotNetNuke.Services.Analytics.GoogleAnalyticsEngine, DotNetNuke</EngineType>
<ElementId>Head</ElementId>
<InjectTop>False</InjectTop>
<ScriptTemplate>
<!-- Google Tag Manager -->
<![CDATA[
<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=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','<Tracking ID>');
</script>
]]>
<!-- End Google Tag Manager -->
<!-- documented... we would like to disable it by now
<![CDATA[
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', '[TRACKING_ID]']);
_gaq.push(['_trackPageview']);
[PAGE_URL]
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'stats.g.doubleclick.net/dc.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
]]>
-->
</ScriptTemplate>
</AnalyticsEngine>
</Engines>
</AnalyticsEngineConfig>
如您所见,我在 CDATA 中包围了所有脚本标签,而不仅仅是 JS 代码。 将类似于 GTM-XXXXXX。 如您所见,Tracking ID 被 know 硬编码,但那是另一个问题;D.