Adding Google Analytics Tracking code in DNN 9.*

Adding Google Analytics Tracking code in DNN 9.*

Update: This can now be handled through DNN's persona bar under the Connectors option. Choose Google 4 and add your tracking id there, just the number, instead of the full javascript mentioned below.

If you’ve setup a new DNN site running on version 9.0 or 9.1, you’ll notice that you don’t have the ability to setup the Google Analytics module/code anymore. For some reason, DNN Corp in its infinite wisdom decided to remove the core, critical functionality from the Platform version of DNN and only leave it in the paid versions.

Well fear not, you can easily add Google Analytics code to your pages, follow these steps.

  1. First step is to go to https://analytics.google.com/ and sign up, register your site, you’ll be given Tracking code that looks similar to
     

    <script>
       (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
       (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
       m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
       })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

      ga('create', 'UA-######-##', 'auto');
       ga('send', 'pageview');

    </script>

  2. Copy that code, yours will be slightly different, without the #### in place.
  3. Navigate to your Site Settings page within the DNN Persona Bar.
  4. Navigate to the Site Behavior tab
  5. Scroll down to the Page Output Settings section.
  6. Paste the tracking code into the text box there.
  7. Click save at the bottom of the page.

Boom, you’ve now got your tracking code included on all the pages on your site.

Recent Comments

Comment Avatar

I want to thank you for this post - there is little advice for people getting started with DNN 9X i'm fairly new to DNN and your information is always helpful... a very simple fix....thanks again, allen Much appreciated,,

Posted By: allen Hunsucker on May 2017
Comment Avatar
hello Chris Hammond, i have upgraded my test site to dnn evoq 9.1.0 version. and i want to add google Analytics Tracking Code. but i can not find "Page Output Settings section" under Site Behavior tab of Site Settings page. please help
Posted By: Mitesh Patel on Jun 2017
Comment Avatar
The Page Output Settings is at the bottom of the Site Behavior Tab, Default Settings, very bottom...
Posted By: Rob Hunter on Jun 2017
Comment Avatar

Thank you - and thank you again for this elegant solution.

Posted By: Lizzy Johnson on Jul 2017
Comment Avatar

Google suggests putting the code after the body tag "Add the following line to each template page immediately after the opening

tag", your method (while technically "ok", isn't the recommended method - just to let everyone know) is inputting the code into the head.

Posted By: Phillip Quinlan on Aug 2017
Comment Avatar

Phillip - incorrect. Correction for your statement here: https://analytics.google.com/analytics/web/ (Google verbatim) This is the Global Site Tag (gtag.js) tracking code for this property. Copy and paste this code as the first item into the

of every webpage you want to track. If you already have a Global Site Tag on your page, simply add the config line from the snippet below to your existing Global Site Tag. I know there are vendors releasing google analytics modules at a premium for DNN, but this works. More reasons to irk DNN for trying to squeeze profits and shun a good user-experience.

Posted By: Mark Peterson on Feb 2018
Comment Avatar

Chris....this is an absolutely brilliant post. It is something we all are going to need now that the powers that be decided to take it away from us.

Posted By: Ibrahim Malluf on Aug 2018
Comment Avatar

Hi - Thanks for this. I know some time has passed since this article was posted. I am currently running DNN 9.6.1 , about to upgrade to DNN 9.9.1. At some point, Google analytics stopped working on my sites, so I found your article and used this method and the tracking started to work again. Thanks! However, I noticed that I'm getting a ton of Admin Alerts in my logs, which look like this: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Analytics.AnalyticsConfiguration:GetConfig Failed FilePath:D:\Inetpub\SCCInternet_90100\Portals\7\\GoogleAnalytics.config ExceptionMessage:Object reference not set to an instance of an object. Server Name: SCZAS167 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Do you know how I can get rid of this issue? Maybe I no longer need the Google Analytics.config file now that I'm using the method you shared? Any insight is greatly appreciated. Thanks! Tom Melkonian ([email protected])

Posted By: Tom Melkonian on Sep 2021
Comment Avatar

Hi - Thanks for this. I know some time has passed since this article was posted. I am currently running DNN 9.6.1 , about to upgrade to DNN 9.9.1. At some point, Google analytics stopped working on my sites, so I found your article and used this method and the tracking started to work again. Thanks! However, I noticed that I'm getting a ton of Admin Alerts in my logs, which look like this: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Analytics.AnalyticsConfiguration:GetConfig Failed FilePath:D:\Inetpub\SCCInternet_90100\Portals\7\\GoogleAnalytics.config ExceptionMessage:Object reference not set to an instance of an object. Server Name: SCZAS167 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Do you know how I can get rid of this issue? Maybe I no longer need the Google Analytics.config file now that I'm using the method you shared? Any insight is greatly appreciated. Thanks! Tom Melkonian ([email protected])

Posted By: Tom Melkonian on Sep 2021

Add Comment

Please add your comment by filling out the field(s) below. Your comment may need to be approved before it becomes visible.
Enter your first name for display with the comment
Enter your last name for display with the comment.
Enter your comment here.
If you can't type DNNRocks in, you can't post, plain and simple.
Submit Comment Cancel

Chris Hammond

Chris Hammond is a father, husband, leader, software developer, photographer and car guy. Chris focuses on the latest in technology including artificial intelligence (AI) and has spent decades becoming an expert in ASP.NET and DotNetNuke (DNN) development. You will find a variety of posts relating to those topics here on the website. For more information check out the about Chris Hammond page.

Find me on Twitter, GitHub and LinkedIn.