Wolf X Machina

Back to blog

Configure Google Analytics or Google Tag Manager in DNN 9+

Posted in DNN on May 22, 2019

The DNN interface for Google Analytics was removed in the earlier versions of DNN9. Luckily, it was re-added back into 9.3.1. I'm going to show you how to find the Google Analytics interface in DNN, but also show you how you can use Google Tag Manager instead of Google Analytics.

DNN 9.3.1+ Connectors Interface
DNN 9.3.1+ Connectors Interface

Here's how you can configure Google Analytics in DNN 9.3.1+

  1. Log in as the Admin or with a SuperUser account
  2. Hover over the "Settings" gear icon
  3. Click "Connectors"
  4. You will see "Google Analytics" and a "Connect" button if you haven't configured this yet. (If it's already configured, you will see an "Edit" button)
  5. Click the Connect (or Edit) button and the interface will slide down.
  6. Input your Tracking ID. It will probably look something like UA-XXXXX-Y. I leave the URL Parameter field blank and then uncheck "Track for Administrators" and then click Save.
  7. Once it saves, you can close the Connectors panel.
  8. Verify the code is working in your Google Analytics dashboard.

Note: If you deselected "Track for Administrators", the code won't appear in the source if you're logged in as a SuperUser or Admin. So check that the code is in the source by using a different browser or log out and check.

If you only wanted to use Google Analytics and you're using DNN 9.3.1+, then you can stop reading here. If you're interested in how it works, or you want to implement Google Tag Manager, then read on.


Here's how it works behind the scenes

There are two files at play: 

  1. /Root/Portals/<portal-folder>/GoogleAnalytics.config > This is where the Tracking Code lives. When you update the Tracking ID through the Connectors interface, this is the file that is created and then updated. If you're using a version of DNN9 that is pre-9.3.1, you have to create and edit this file directly through FTP as there is no Connectors interface in those versions of DNN9.
  2. /Root/SiteAnalytics.config > This is the instance-wide template for the tracking code. This template is applied to the entire instance so if you change it, it will affect ALL portals on your instance. You need FTP to access and edit this file. If you're using Google Analytics, you don't need to change anything. But if you're using Google Tag Manager, you need to update this file so that it uses the Google Tag Manager code. Just be mindful of the [TRACKING_ID] token as that token is replaced by the Tracking ID in the GoogleAnalytics.config file.

How to change your entire DNN instance to use Google Tag Manager

Please note! To use Google Tag Manager, you will need to edit the SiteAnalytics.config to update the template to handle the Tracking ID differently. However, please know that changing the SiteAnalytics.config template to use Google Tag Manager affects ALL portals on the instance. So if you a multi-portal instance, please be aware that you're affecting all portals. If all of your portals are using or going to use Google Tag Manager, then you should be fine. If you have a mix between Google Analytics and Google Tag Manager, it would be best to leave it as the default Google Analytics tracking code and then handle the Google Tag Manager templates differently.

Now that you know that, here's how you update your DNN instance to use Google Tag Manager code:

  1. Follow the steps above and go to Connectors > Google Analytics and input your Tracking ID and save it. If you're using pre-9.3.1, create and edit the portal file GoogleAnalytics.config.
  2. Then open the file /Root/SiteAnalytics.config using FTP, and edit it to use the Google Tag Manager code that you were provided by Google. Make sure to replace to the tracking ID with the token [TRACKING_ID] so that it references each portal's GoogleAnalytics.config file.

    Here's what it should look like: 
    <?xml version="1.0" encoding="utf-8" ?>
    <AnalyticsEngineConfig>
    	<Engines>
    		<AnalyticsEngine>
    			<EngineType>DotNetNuke.Services.Analytics.GoogleAnalyticsEngine, DotNetNuke</EngineType>
    			<ElementId>Head</ElementId>
    			<InjectTop>False</InjectTop>
    			<ScriptTemplate>
    				<![CDATA[     
            
    
    <!-- Global site tag (gtag.js) - Google Analytics -->
    
    <script async src="https://www.googletagmanager.com/gtag/js?id=[TRACKING_ID]"></script>
    <script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());
    
      gtag('config', '[TRACKING_ID]');
    </script>
    
            
    		  ]]>
    			</ScriptTemplate>
    		</AnalyticsEngine>
    	</Engines>
    </AnalyticsEngineConfig>
    
    
  3. Save and upload the file.

I hope that provide insight into Google Analytics and Google Tag Manager in DNN 9.3.1+. If you're looking for more help with getting the most out of your DNN website, please check out my page for Expert DNN Development. I'm always looking to help businesses with DNN websites to improve their DNN experience.

Aaron Lopez

Aaron Lopez

Founder & Lead Developer at Wolf X Machina

Wolf X Machina

Next Level Interface Development for the DNN CMS

DNN themes, module design, and more from Wolf X Machina.

Learn More