1

我试图在后面的代码中从ASP.NET 用户控件/DotNetNuke Skin中添加 HTML(特别是Google 跟踪代码管理器片段),就在开始的 body 标记之后。

我尝试了以下代码:

protected override void OnInit(EventArgs e)
{
    base.OnInit(e);
    this.Page.PreLoad += new EventHandler(Page_PreLoad);
}

protected void Page_PreLoad(object sender, EventArgs e)
{
    HtmlGenericControl body = (HtmlGenericControl) Page.FindControl("ctl00$body");
    body.Controls.AddAt(0, new Literal() {ID = "GoogleTagManager", Text = "(...)" };
}

到目前为止,这很有效;HTML 出现在所需的位置。但我注意到,每当执行代码时,似乎没有处理后面的PostBacks 。

我无法将 HTML 放入 .aspx 页面,因为我们有多个 DotNetNuke 门户,我们不想在其中拥有相同的片段。

有谁知道如何在保持回发工作的同时实现这一目标的解决方案?

__

谢谢你和来自瑞士的问候

拉斐尔

4

4 回答 4

2

You might be able to use the client resource manager placeholders for this.

http://www.dnnsoftware.com/wiki/Page/Client-Resource-Management-API

Specifically, in the default.aspx file of your site you'll see a BodySCRIPTS placeholder.

That or if you want, you might be able to target the Body ID element by getting to the Page base, I do something like that for controlling the Title of a page in https://dnnsimplearticle.codeplex.com/SourceControl/latest#cs/Controls/ArticleView.ascx.cs

var tp = (CDefault)Page;
tp.Title = curArticle.Title;
于 2013-09-09T15:07:38.400 回答
2

您可以修改httpdocs 下的SiteAnalytics.config文件并适配:

身体真

这将应用于在 Admin > Google Analytics 下具有 Google 控制权的门户

但我不知道为什么,发不适用于此解决方案。

您对此有解决方案吗?DNN 与 GTM 不兼容吗?

于 2014-03-13T13:02:30.883 回答
0

刚刚发现可以在body标签之后添加Google Tag Manager脚本,这可以在default.ascx中找到

    <%@ Page Language="vb" AutoEventWireup="false" Explicit="True" Inherits="DotNetNuke.Framework.DefaultPage" CodeFile="Default.aspx.vb" %>
<%@ Register TagPrefix="dnn" Namespace="DotNetNuke.Common.Controls" Assembly="DotNetNuke" %>
<asp:literal id="skinDocType" runat="server"></asp:literal>
<html<%= HtmlAttributeList %>>
<head id="Head" runat="server">
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type"/>
    <meta content="text/javascript" http-equiv="Content-Script-Type"/>
    <meta content="text/css" http-equiv="Content-Style-Type"/>
    <meta id="MetaRefresh" runat="Server" http-equiv="Refresh" name="Refresh" />
    <meta id="MetaDescription" runat="Server" name="DESCRIPTION" />
    <meta id="MetaKeywords" runat="Server" name="KEYWORDS" />
    <meta id="MetaCopyright" runat="Server" name="COPYRIGHT" />
    <meta id="MetaGenerator" runat="Server" name="GENERATOR" />
    <meta id="MetaAuthor" runat="Server" name="AUTHOR" />
    <meta name="RESOURCE-TYPE" content="DOCUMENT" />
    <meta name="DISTRIBUTION" content="GLOBAL" />
    <meta id="MetaRobots" runat="server" name="ROBOTS" />
    <meta name="REVISIT-AFTER" content="1 DAYS" />
    <meta name="RATING" content="GENERAL" />
    <meta http-equiv="PAGE-ENTER" content="RevealTrans(Duration=0,Transition=1)" />

    <link href="StyleSheets/LPStyles.css" type="text/css" rel="stylesheet">

    <style type="text/css" id="StylePlaceholder" runat="server"></style>
    <asp:placeholder id="CSS" runat="server" />
</head>
<body id="Body" runat="server" >
<!-- Google Tag Manager -->
<noscript><iframe src="//www.googletagmanager.com/ns.html?id=XXX-XXXXXX"
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-TK4KKM');</script>
<!-- End Google Tag Manager -->
<!-- Google Tag Manager -->
<noscript><iframe src="//www.googletagmanager.com/ns.html?id=XXX-XXXXXX"
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','XXX-XXXXXX');</script>
<!-- End Google Tag Manager -->

    <dnn:Form id="Form" runat="server" ENCTYPE="multipart/form-data" >
        <asp:Label ID="SkinError" runat="server" CssClass="NormalRed" Visible="False"></asp:Label>
        <asp:PlaceHolder ID="SkinPlaceHolder" runat="server" />
        <input id="ScrollTop" runat="server" name="ScrollTop" type="hidden" />
        <input id="__dnnVariable" runat="server" name="__dnnVariable" type="hidden" />
    </dnn:Form>
</body>
</html>
于 2013-12-11T17:26:38.723 回答
0

我正在尝试将 GTM 添加到 DNN 门户。我已经阅读了一些关于此的帖子,但无法提出解决方案。我知道您可以添加到 default.aspx 页面,但在我的情况下,它必须通过皮肤包添加。

我尝试过使用 cs 或 VB 页面,但无法将控件添加到 Body 标记。

我可以向 body 标记添加属性,但尝试添加控制器总是失败。@rapael 你提到“var tp = (CDefault)Page; tp.FindControl("Body").Controls.AddAt(0, new Literal() { Text = "" }); "

你能提供更多关于你如何实施的细节吗?谢谢

于 2015-02-26T04:57:26.640 回答