Products » Support Forums 

Support Forums

HomeHomeDotNetNuke Modu...DotNetNuke Modu...Google Analytic...Google Analytic...Possible to add async GA script inside <head> ?Possible to add async GA script inside <head> ?
Previous
 
Next
New Post
8/28/2010 2:47 PM
 

The GA Help says:

One of the main advantages of the asynchronous snippet is that you can position it at the top of the HTML document. This increases the likelihood that the tracking beacon will be sent before the user leaves the page. We've determined that on most pages, the optimal location for the asynchronous snippet is at the bottom of the <head> section, just before the closing </head> tag.

Currently the module adds the script to the <body>. Would it be possible (in a future version) to put it inside the <head> element?

Thx

 
New Post
8/31/2010 11:05 AM
 

I've had a look at this. It is possible but requires a bit of rewriting in the module to implement it. I'll put this on the roadmap but no promises on if or when.

If you know what you're doing the code is open source so you can change it yourself. But it requires changing the way the script is currently generated and replacing that with a different method. It's not difficult but just takes time to do and test and make sure all is OK.

 
New Post
8/31/2010 1:46 PM
 

OK thanks. I thought about modifying the source, but the ASP.NET script registering functions only seem to be able to (at best) add the script to the top of the <body>. Is there a simple function for adding a script to <head>?

 
New Post
8/31/2010 2:01 PM
 

Yes, it's simple.

First, declare an override for the PageBase in the module:

public DotNetNuke.Framework.CDefault BasePage
{
get
{
return (DotNetNuke.Framework.CDefault)this.Page;
}
}

Once you've got that, you've got access to the <head> section, through BasePage.Header.

Then you can add whatever controls you like to the header.

HtmlGenericControl scriptContainer = new HtmlGenericControl("script");
scriptContainer.ID = "analytics-script";
scriptContainer.InnerText = "Your script here";
this.BasePage.Header.Controls.Add(scriptContainer);

You may need to set a couple of other properties/attributes to get the script tags right, but this is the general gist of it.

 
New Post
8/31/2010 2:06 PM
 

Ah ha! Thanks very much. I will try this out.

 
Previous
 
Next
HomeHomeDotNetNuke Modu...DotNetNuke Modu...Google Analytic...Google Analytic...Possible to add async GA script inside <head> ?Possible to add async GA script inside <head> ?


Support Guidelines.. Please read before posting

To get support on iFinity products and services, please search the forums for the the answer to the problem you are seeking. If you cannot find a solution, post a question in the relevant forum.   Ensure that you specify the relevant versions of the problem, and the actual error message or a detailed description of the problem.    You will need to register with this site to post on the forum.  If you have a Microsoft Live (Hotmail/Passport) account you can use that.  If you have a Open Id account you can use that.  If you neither of these, you will need to register a user Id and password.