Click here to Skip to main content
15,357,464 members
Articles / Web Development / ASP.NET
Posted 26 Aug 2007


43 bookmarked

A simple DotNetNuke Google Analytics Module

Rate me:
Please Sign up or sign in to vote.
4.78/5 (12 votes)
26 Aug 2007CPOL6 min read
Adding Google Analytics tracking to your DotNetNuke website the easy way.


Google Analytics is great. A free, fully featured website tracking and reporting system. It's even better if you use Google Adwords and want to test out how different ads work with getting visitors. DotNetNuke is great. A free, fully featured web platform in which the sky is the limit for developing websites quickly and easily. What I found, though, was that putting the two together, while not difficult, is quite clunky. So, I set out to create a much better way.


Google Analytics works by you (the webmaster or developer) inserting a piece of JavaScript into each page you want tracked by Google. As visitors view your website pages, Google records all of the page views. You then go to the Analytics website and view your reports.

Entering JavaScript into pages is tough with DotNetNuke as you don't want to modify the base code. You can put the script into a skin, but if you've downloaded a skin for your site, you mightn't want to fiddle with it. There's no easy way to control where to put some JavaScript code on a DotNetNuke page.

Enter the DotNetNuke Google Analytics module - a free and easy way to integrate the two together.

The DotNetNuke Google Analytics module

The Google Analytics module is a 'normal' DotNetNuke module, so if you have admin permissions on your DotNetNuke website to install modules, then you can install this one. It doesn't use any database tables or web.config modifications, so should be OK for anyone on shared hosting to use. It is a lightweight module, and is designed not to place extra load onto the website.

How to hook up Google Analytics to your DotNetNuke website

Step 0: Create and/or locate your login details for your Google Analytics account. If you haven't already got an account, follow the instructions on the Analytics site to create an account and website profile (

Step 1: Download the Module install Zip file from this page.

Step 2: Install the module by using the 'Module Install' functionality in your DotNetNuke portal. To check that the module installed correctly, it should appear in the 'Module' drop down list in your Control Panel, under the name "iFinity Google Analytics".

Step 3: Go to the home page of your DotNetNuke portal, and use the 'Add New Module' functionality to add an instance of the iFinity Google Analytics module to the page. I normally use the bottom pane to keep it out of the way of other modules. Don't be worried that you can see the module in 'Edit' mode. The module will disappear when you log out as Administrator.

Step 4: Click on the 'Settings' control for the Google Analytics module you just created. Then, scroll the Settings page until you get to the 'Advanced Settings' section, and check the 'Display Module on All Pages'. This ensures that all pages on your website are tracked by Google Analytics.

See the red highlighted area:

Screenshot - gaexample2.jpg

Advanced Settings section of the DotNetNuke module

If for any reason, you didn't want all pages on your site to be tracked, you can just copy the module from the home page onto the pages you want tracked. Scroll further down the page, expand the 'Page Settings' section until you get to the 'Basic Settings' section, and select Visibility: None, and make Display Container unchecked. This hides the Google Analytics module from visitors.

See the red highlighted area:

Screenshot - gaexample1.jpg

Basic Settings section of the DotNetNuke module

Step 5: Scroll down the page further until you reach the 'Analytics Script Generator Settings' section. Under here is the specific settings for your site. Leave this page for a minute and open up a new browser window to go to Google Analytics.

Step 6: Go to Google Analytics at (make sure you sign in with your account), and click on 'Edit' next to the website profile you have set up. This will bring up the details of the website profile. Then, find the 'Check Status' link on the page and click that. You should see a box containing some JavaScript. Instead of copying out all the JavaScript as directed, you only need the account number, or the 'UA' number. Copy the UA number from the Google page into your DotNetNuke site, in the 'Google Analytics Tracking ID' field. You do not need the inverted commas around the number.

See the following example:

Screenshot - gaexample3.jpg

Analytics Settings section of the DotNetNuke Module

Step 7: (optional) If you'd like to restrict tracking so that it doesn't show on the reports for certain visitors, you can select a DotNetNuke security group in the next drop down list. For example, you don't want the administrative editing to show up as page hits on Google Analytics. In that case, you would select 'Administrators' as the group to exclude from tracking.

Step 8: Click on Update. The page should refresh and return to the home page of your site. If you do a "View Source" on your browser and scroll to the bottom of the HTML, just before the body tag, you should see the generated script. (Note: if you selected the Adminstrator group, you'll have to sign out first).

Step 9: Go back to your Google Analytics account. It should still be on the page showing the tracking code to be added. Click on the 'Finish' button at the bottom. When it returns to the website profile page, you should see a green tick and the words 'Receiving Data'. If you do see this, your site is providing statistics to Analytics and you are all set.

Advanced options

The security group option is there so that any editing and other administrative activity doesn't show up on the Analytics reports. However, if you wanted to separate out usage for, say, registered vs. non-registered users, you can set up two profiles in Analytics and create two Analytics modules in your DotNetNuke site. You can then set one to track unregistered users by excluding registered users. and vice versa. The other box on the settings page is the 'Do not generate tracking script for calls to this host'. This option allows you to interrupt calls to Google when the site is called using a specific host-name. I normally use this so that when running tests on localhost, I'm not bothering the Google server. However, instead of totally hiding the code, all that happens is that the urchinTracker() JavaScript call is commented out, so you can still check that it is working.

So how does it work?

If you want to see the code, it is included with the module install. For a high level intro, all that happens in the module is the collection of the module settings (UA-ID, security groups, and host name). The code determines if tracking should be done for the incoming requests and checked against those variables. If the answer is yes, some JavaScript is inserted using the 'RegisterClientScript' ASP.NET call. And, that's it.

About the only tricky bit is the use of a created BasePage property, a trick I learnt from Scott McCulloch of By creating this property inside a class which is derived from PortalModuleBase, you can get access to all sorts of goodies like the meta tags, headers, and the base ClientScript object for the page.

//now register the script
              "analytics", script);

//end snip
//expose the base page
public DotNetNuke.Framework.CDefault BasePage
      return (DotNetNuke.Framework.CDefault)this.Page;


  • First version : 27th August 2007.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Bruce Chapman DNN
Product Manager DNN Corp
Australia Australia
Bruce Chapman is the Product Manager for Cloud Services at DNN. He’s been an active member of the DNN Community since 2006 as a contributor, vendor and now employee of DNN Corp.

You can read his blog at or follow him on Twitter @brucerchapman

Comments and Discussions

GeneralCan't install on 05.01.04 Pin
edesigner26-Oct-10 11:14
Memberedesigner26-Oct-10 11:14 
GeneralRe: Can't install on 05.01.04 Pin
Bruce Chapman DNN26-Oct-10 21:42
professionalBruce Chapman DNN26-Oct-10 21:42 
GeneralSupporting Module to Display Analytics Report Data in your DNN Websites Pin
interactivewebs24-Sep-09 16:40
Memberinteractivewebs24-Sep-09 16:40 
GeneralError when creating GA module in DNN Pin
mvangils27-Jan-09 9:57
Membermvangils27-Jan-09 9:57 
GeneralRe: Error when creating GA module in DNN Pin
javierobcn10-Jun-09 4:38
Memberjavierobcn10-Jun-09 4:38 
GeneralNEW VERSION 1.01.00 Pin
Gibros16-Sep-08 19:58
MemberGibros16-Sep-08 19:58 
GeneralRe: NEW VERSION 1.01.00 Pin
Intelligent Netware20-Nov-08 18:54
MemberIntelligent Netware20-Nov-08 18:54 
GeneralRe: NEW VERSION 1.01.00 Pin
Bruce Chapman DNN20-Nov-08 19:01
professionalBruce Chapman DNN20-Nov-08 19:01 
QuestionScript is not rendered immediate before tab Pin
maxcom1-Sep-08 3:49
Membermaxcom1-Sep-08 3:49 
AnswerRe: Script is not rendered immediate before tab Pin
Bruce Chapman DNN1-Sep-08 14:39
professionalBruce Chapman DNN1-Sep-08 14:39 
GeneralDotNetNuke 4.8.4 Pin
Steve Karpik13-Jun-08 5:18
MemberSteve Karpik13-Jun-08 5:18 
GeneralRe: DotNetNuke 4.8.4 Pin
Bruce Chapman DNN13-Jun-08 16:02
professionalBruce Chapman DNN13-Jun-08 16:02 
QuestionScript appears too far up ? Pin
Matt Comb25-Nov-07 22:28
professionalMatt Comb25-Nov-07 22:28 
AnswerRe: Script appears too far up ? Pin
Bruce Chapman DNN26-Nov-07 1:34
professionalBruce Chapman DNN26-Nov-07 1:34 
GeneralRe: Script appears too far up ? Pin
Matt Comb26-Nov-07 20:46
professionalMatt Comb26-Nov-07 20:46 
GeneralThanks for the module Pin
Daniel Vaughan29-Sep-07 16:36
MemberDaniel Vaughan29-Sep-07 16:36 
QuestionSupport DotNetNuke 4.5? Pin
Mackz12-Sep-07 3:55
MemberMackz12-Sep-07 3:55 
AnswerRe: Support DotNetNuke 4.5? Pin
Bruce Chapman DNN12-Sep-07 12:35
professionalBruce Chapman DNN12-Sep-07 12:35 
GeneralGroup exclude from tracking. Pin
Chris Richner27-Aug-07 21:35
MemberChris Richner27-Aug-07 21:35 
GeneralRe: Group exclude from tracking. Pin
Bruce Chapman DNN27-Aug-07 22:00
professionalBruce Chapman DNN27-Aug-07 22:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.