XML包中的Google跟踪代码管理器脚本中的解析错误

时间:2015-10-02 06:25:57

标签: asp.net xml xml-parsing google-tag-manager aspdotnetstorefront

我有一个运行ASPDOTNETSTOREFRONT的网上商店。

我正在尝试将自定义跟踪脚本行添加到一组网页中。

为此,我正在为这些网页使用的XML包添加Google跟踪代码管理器脚本,因此它会显示在我要跟踪的所有网页上。

我只是将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

任何人都有任何建议如何解决这个问题?

2 个答案:

答案 0 :(得分:2)

尝试将脚本内容放在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 :(得分:0)

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中使用了al script标签,而不仅仅是JS代码。  将是GTM-XXXXXX之类的东西。 正如您所看到的,跟踪ID是由知识硬编码的,但这是另一个问题; D。