Question

the question I have is similar to This SO question. I know where to find the SiteAnalytics.config files and what they do. But I want to know how to use the new universal analytics code that google provides.

The current DNN anayltics code is as follows:

            <script type="text/javascript">
              var _gaq = _gaq || [];
              _gaq.push(['_setAccount', '[TRACKING_ID]']);
              _gaq.push(['_trackPageview']);

              (function() {
                var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
                ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
                var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
              })();
            </script>

Notice the [TRACKING_ID] - this gets replaced by the tracking ID for the specific portal (which is stored in the GoogleAnalytics.config within the portals folder)

Here is the new google tracking code:

<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','//www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-11111111-1', 'fooWebsite.com');
  ga('send', 'pageview');

</script>

I assume I can just replace UA-11111111-1 with [TRACKING_ID].

Notice that in addition to the Tracking id there is now a website name. The old Tracking code only replaced a tracking ID (AFAIK).

Question:

Where does the tracking ID get replaced in the code and how Can I replace the website name as well? I can't seem to find where this happens in the core code.

Was it helpful?

Solution

The domain setting is actually optional. But it does control what domain the cookie is created under. Controlling this is useful when you want your tracking to work properly with multiple subdomains.

With the old code you would have done something like this:

_gaq.push(['_setDomainName', 'example.com']);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top