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 12:30 PM

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 4:29 PM

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 4:51 PM

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 12:24 PM

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 12:31 PM

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 2:22 PM

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 3:07 PM

OK, thanks

By Ari on Tuesday, December 18, 2007 at 9: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 10: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 10: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 12:40 PM

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 11: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 12:30 PM

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 9: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 9: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 8: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 12:30 PM

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 3:10 PM

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 3:12 PM

I tried a number of processes to get google analytics functioning on my site but this is the only one I was able to get to work. I don't know if it's my lack of understanding/programming experience with the other processes or the fact that this was an easy and well explained way of doing it. (Or both)
Thanks

By Bob on Saturday, December 04, 2010 at 3:51 PM

HI,

i have added google analytics to my dnn site. Previous so other worked on the site and added google analytics. I have added the latest code using iinfinitygoogle analyitics module. But, im getting previous code on my page. i am not getting where that code is coding from. I have checked all pages and modules and checked with httpdocs also. Please help me out.

By Praveen on Tuesday, April 12, 2011 at 8:39 AM

HI,

i have added google analytics to my dnn site. Previous so other worked on the site and added google analytics. I have added the latest code using iinfinitygoogle analyitics module. But, im getting previous code on my page. i am not getting where that code is coding from. I have checked all pages and modules and checked with httpdocs also. Please help me out.

By Praveen on Tuesday, April 12, 2011 at 8:39 AM

I used this method to add google analytics to my dotnetnuke site, but it does not appear to be working.

I placed the code over a week ago. It shows 3 visitors in the last week but I've had 5+ people RSVP using a link on my site...so the analytics is not catching every visitor.

Anyone have any suggestions? I'm wondering if I need to place the code somewhere other than in a module on the main page?

By Annalisa on Monday, May 02, 2011 at 2:48 PM

You must have it on all pages as noted above. Otherwise, you can also use the out of the box DNN way of doing this, or adding it to your skin.

By mitchel.sellers@gmail.com on Monday, May 02, 2011 at 2:53 PM

This method works for me. Just make sure you follow the instructions laid out above!

By Pat on Tuesday, May 17, 2011 at 8:36 AM

Name (required)

Email (required)

Website

CAPTCHA image
Enter the code shown above:

Content provided in this blog is provided "AS-IS" and the information should be used at your own discretion.  The thoughts and opinions expressed are the personal thoughts of Mitchel Sellers and do not reflect the opinions of his employer.

Friend of RedGate

www.datasprings.com - DotNetNuke Modules ICG Hosting

Click here for advertising information.

Content in this blog is copyright protected.  Re-publishing on other websites is allowed as long as proper credit and backlink to the article is provided.  Any other re-publishing or distribution of this content is prohibited without written permission from Mitchel Sellers.