We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 20297
    • 2 Posts
    I inserted GA code into the templates for my website a while ago, but have been getting really strange data numbers in the profile. Is there a conflict with Modx and GA, and how do I solve it? I have had problems with inserting iframes and have had to resort to dumping all the code for a page in the module box just so the iframe would run. What should I do with the GA code so it will work with this CMS? Thanks.
    • No conflict I’m aware of; we use Google Analytics code with a majority of our MODx sites with no issues. Have you looked at/tried any of the Add-Ons for GA in the Extras repository?
        • 20297
        • 2 Posts
        Hi Jason, Thanks for your response. When you add the GA code to your templates, do you just copy and paste the GA code or is it in the form of a chunk or snippet?
        • Quote from: Mountain at Feb 23, 2010, 04:13 PM

          Hi Jason, Thanks for your response. When you add the GA code to your templates, do you just copy and paste the GA code or is it in the form of a chunk or snippet?
          Generally just copy and paste the GA code (usually in a Template Variable), though in some cases we want to not count access by manager users, in which case we use one of the Add-Ons that has this feature. I do not recall off-hand which GA Add-Ons I’ve used, but you should be able to find them in the repository.
            • 18940
            • 152 Posts
            Hi there, I’m using Google Analytics and modx 1.0.0, this is my code, right above </body> tag (user account number set to UA-00000000-0, you need to put your own number here):

            <!-- Google Analytics Code -->
            <script type="text/javascript">
            var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
            document.write(unescape("%3Cscript src=’" + gaJsHost + "google-analytics.com/ga.js’ type=’text/javascript’%3E%3C/script%3E"));
            </script>
            <script type="text/javascript">
            try {
            var pageTracker = _gat._getTracker("UA-00000000-0");
            pageTracker._trackPageview();
            } catch(err) {}</script>

              Quality doesn&#39;t need a big signature.
              • 35834
              • 2 Posts
              Quote from: Mountain at Feb 23, 2010, 04:13 PM

              Hi Jason, Thanks for your response. When you add the GA code to your templates, do you just copy and paste the GA code or is it in the form of a chunk or snippet?

              how to create a snippet for GA?
              • The GA code is just normal javascript, there is nothing special about it, there should be no conflict. I use GA and it works fine -- I put the code (asynchronous version, of course) in a chunk and then include that chunk in my templates above the </head> tag. Works fine. It should also work to put it directly in the template, or put it in a TV and put that in the template (but why do it that way, Jason, do you want to have different GA code on different resources for some reason?).

                I bet your anomalies arise from your use of iframes, not from MODx per se. Iframes break Google’s basic model of the internet, which can have unexpected results both in GA and in search. Google wants everything to have a unique URL. Using an iframe sort of combines two URLs into one "page". For purposes of search, Google regards an iframe as similar to a link. GA treats an iframe as a separate "pageview" because when you load the new URL into the iframe, it calls the JS tracking code for that URL.

                I’m not clear on what you mean by "strange data numbers" but I would have a look at exactly how the data is being reported, decide whether you want the iframe "pageviews" to count as a separate pageview in GA, and remove the GA code from the iframed content if you don’t want that.