DNN Tutorial – How To Enable Google Analytics on a DotNetNuke Website?
Google Analytics is one of those must-have tools when running a website. The tasks of tracking traffic sources, browser versions, search terms, etc. are all made easy. The developers of DotNetNuke have also made using Google Analytics on a DotNetNuke website simple.
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).
Step By Step
- 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
- Edit the text of the module to contain no text
- Enter the module settings from the SolPart Action Menu
- Expand the “Advanced Settings” section
- Check the box next to “Display Module On All Pages?”
- Insert your Javascript code in the “Header” box. This will ensure that the data is always retained
- Now under “Page Settings” -> “Basic Settings” un-check the following boxes
- Display Container
- Allow Print
- Allow Syndicate
- Ensure that the “Cache Time” is set to 0 (Caching appeared to cause issues with this implementation in my testing)
- 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.