Adding Google Analytics to a DNN site manually

Overview

Because the Google Analytics microservice needs an outbound internet connection to be established and work properly, customers who have internal only connections may run into issues setting it up. In these cases, it's advisable to insert the DNN Google Analytics script directly into the site header.

NOTE: Many of the issues surrounding the inability to connect to Google Analytics have been resolved in DNN version 9.2 so it's advisable to consider an upgrade if you're facing issues. 

Requirements: Access to core site code, admin access to DNN. 

 

Script

<AnalyticsEngineConfig>
  <Engines>
    <AnalyticsEngine>
      <EngineType>
        DotNetNuke.Professional.Services.Analytics.GoogleAnalyticsEngine, DotNetNuke.Professional
      </EngineType>
      <ElementId>Head</ElementId>
      <InjectTop>False</InjectTop>
      <ScriptTemplate><![CDATA[

          <script type="text/javascript">
            (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', '[TRACKING_ID]', 'auto', {'legacyCookieDomain': '[DOMAIN_NAME]'});
            [CUSTOM_SCRIPT]
            ga('send', 'pageview');
          </script>

        ]]></ScriptTemplate>
    </AnalyticsEngine>
  </Engines>


The customer can then validate that the script is working by logging into the DNN portal and going to Persona Bar > Dashboard > Site Analytics where, if successful, they will see the data displayed. 

siteanalytics.jpg

Comments

0 comments

Please sign in to leave a comment.