Adding Google Analytics to DotNetNuke 

Installing Google Analytics in DotNetNuke is a fairly common request from many individuals and I know it can be a quite troubling question for most. The primary questions are how and where can I put the javascript code provided by Google. Well you have a few options. First you could put the code directly in the skin for the site, the advantages to that would be that you will automatically have the code on all pages, however, the disadvantage is that you cannot use that skin as is on another portal due to the site specific Google information. I personally go the route of adding a text/html module to my site and set it to show on every page and insert the script in a very specific location which I will discuss below. There are a few drawbacks to this method. First you will not get any statistics information on traffic to "edit pages" where other modules are not displayed and you also will not receive information regarding administration modules. However, in most circumstances this shouldn't be an issue.

The best way to include this information is to include the information in the Module header of the text/html module. This is to prevent the accidental removal of the script code if you happen to click inside the module as an admin to enter in-line edit mode. Below I will walk you through the steps needed to implement Google Analytics using this method. (NOTE: you can extend this for other javascript integrations if needed).

  1. Add a new Text/HTML module to a page of your site, you can position it anywhere, but I recommend the bottom of the page as administrative users will still see the module when they are logged in
  2. Edit the text of the module to contain no text
  3. Enter the module settings from the SolPart Action Menu
  4. Expand the "Advanced Settings" section
  5. Check the box next to "Display Module On All Pages?"
  6. Insert your Javascript code in the "Header" box. This will ensure that the data is always retained
  7. Now under "Page Settings" -> "Basic Settings" un-check the following boxes
    • Display Container
    • Allow Print
    • Allow Syndicate
  8. Ensure that the "Cache Time" is set to 0 (Caching appeared to cause issues with this implementation in my testing)
  9. Click "Update" to save your changes

This should complete the setup. You may now test to ensure everything is functioning correctly. You can log out as an administrator and view your site and no extra content should be displayed however if you look at the generated source you should see your javacript listed. Google Analytics should update within about 15 minutes to show that they are receiving your data.

Posted by Mitchel on Tuesday, April 10, 2007
 

Comments

Nice tutorial, i'm using this method for my subportals, also you can use this method to have tracking scripts like ExtremeTracking (example can be seen at my site)

By Ismet Dumlupinar on Monday, April 16, 2007 at 7:30 AM

For some reason this method does not work for me. I have two portals running under the same DotNetNuke install and cannot get google Analytics to work on either. (Keeps stating Tracking Unknown under the analytics account for both domains) Any Thoughts?

By Joe on Friday, June 01, 2007 at 11:29 AM

Joe,

Yes I have a few ideas. First of all has google indexed your site yet? Secondly, have you given it at least 3 hours? It does take them time to get it the first time.

By mitchel.sellers@gmail.com on Friday, June 01, 2007 at 11:51 AM

Well.. I've seen another tutorial on integrating DNN & Analytics. I just wanted to ask.. will this work ? I mean when I load up his website... his website is connecting to the analytics server.. so I assume it does. But I think you are a better person to comment on this.

Thanks

By Gagan on Tuesday, November 20, 2007 at 7:24 AM

I assume you were trying to link to something, shoot me an e-mail at mitchel.sellers@gmail.com and I'll look into it for you!

By mitchel.sellers@gmail.com on Tuesday, November 20, 2007 at 7:31 AM

I've used this to put Google Analytics into a DNN site. Sometimes, I notice that the pages laod slower. They pause and wait for Google, sometimes Google doesn't respond as quickly...
Is there some way to add the Analytics to the page but not have the page wait for it?

By adoucette on Tuesday, December 18, 2007 at 9:22 AM

Ari,

Not as far as I know. The browser must wait for external JS to load and with Google it is pretty much a requirement to use their available JS externally.

By mitchel.sellers@gmail.com on Tuesday, December 18, 2007 at 10:07 AM

OK, thanks

By Ari on Tuesday, December 18, 2007 at 4:52 PM

Mitch,
In the root DNN folder(not the portal root) is default.aspx. I put my analytics code in there and it works to log everything.

I thought about the fact that it will log for all portals, and figured that, for me, it's probably actually a benifit as I should be able to see traffic from any and all portals to compare to other usage logs.

Do you see any reason why this is a bad idea?

By Josh on Wednesday, February 20, 2008 at 5:35 PM

Josh,

The only reason that it would be a bad thing is if you wanted to entirely track the stats for the different portals in a separate Google Analytics collection.

In my case, I need to track them individually....but it depends on your needs

By mitchel.sellers@gmail.com on Wednesday, February 20, 2008 at 5:40 PM

EGI Consulting Google Analytics

EGI Consulting Google Analytics module enables you to include the Google Analytics script necessary to communicate with Google’s servers.

By Eric Garza on Thursday, July 24, 2008 at 7:40 AM

ifinity.com.au has a free Google Analytics module, http://www.ifinity.com.au/Products/Google_Analytics_Script_Module, that works great. It comes with all sorts of bells and whistles that make it a great addition as opposed to using a text/html module.

By Scott Allender on Tuesday, August 12, 2008 at 6:46 AM

Great instructions! It works like a charm, thank you very much for posting these!

By Rafael Marquez on Friday, January 30, 2009 at 7:30 AM

IF you go with pageblaster (prof edition), this is really easy too. Plus the script is moved to the bottom of the page, before the closing body tag.

By erik on Wednesday, February 18, 2009 at 4:04 AM

We have created a module to support Google Analytics reporting in your DNN website.

See some details here: http://www.interactivewebs.com/analyticsreport

By David Finley on Thursday, September 24, 2009 at 4:34 PM

Mitchel,
Quick question - in DNN 5 there is a google analytics in the drop down. Does it work?
In my DNN 4 websites currently install a google analytics module on the page and put in the U code and then set to display on all pages.

Does this option in the drop down menu in DNN 5 do the same thing?

thanks,
Crysta

By Crysta Hammond on Monday, November 02, 2009 at 3:29 AM

Just FYI on the Google Analytics module from iFinity mentioned by Scott Allender in 2008: I tried to look at that this morning, and the entire iFinity site appears to be dead.

By hedera on Tuesday, February 23, 2010 at 7:30 AM

I install the java script code as you said in the module header of a text/html module and it doesn't work... Need help...

By Depaz Daniel on Monday, March 01, 2010 at 10:10 AM

Thanks Mitchel,

This tutorial is easy to understand and implement - which is such a rarity on the web. I really appreciate you sharing your knowledge.

By Monika Whitfield on Thursday, July 08, 2010 at 10:12 AM
Click here to post a comment

Disclaimer