Help!

Or search support forum

What's Global Moxie?

Global Moxie is the hypertext laboratory of Josh Clark, a designer, developer, and author who offers workshops and consulting for iPhone app design. He’s also creator of Big Medium, a web content management system. Josh spins words and code from multimedia studios in Providence, RI, and Paris, France.

What's Big Medium?

Big Medium is flexible, easy-to-use server software for creating and editing websites directly from your browser. Check out the features or download now.

On Shelves

Books by Josh Clark

Tap Happy: Designing Great iPhone Apps

Best iPhone Apps: The Guide for Discriminating Downloaders

iWork ’09: The Mising Manual

Moxiemail

Enter your e-mail to receive occasional updates:

Can Google Analytics track Big Medium file downloads?

Question

I use Google Analytics to track visitor activity on my Big Medium-powered site. How can I configure it to track file downloads in addition to regular HTML pages?

Answer

The default HTML that Google tells you to insert into your pages will track only those pages that include that code. This means that it can’t track file downloads (because they are not HTML pages, downloads cannot include JavaScript code).

Google offers a workaround for this. The solution involves adding an onclick attribute to every link to files you would like to track. However, there’s another way to attach an onclick event to all Big Medium download files, which does not require this kind of intervention in the code. Here’s how.

Google’s recommended script looks like this (where UA-xxxxxx-x is replaced by your Google Analytics account number):

<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">
var pageTracker = _gat._getTracker("UA-xxxxxx-x");
pageTracker._initData();
pageTracker._trackPageview();
</script>

To track Big Medium document files, update the code like so (be sure to change UA-xxxxxx-x to your actual Google Analytics account number):

<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">
  var pageTracker = _gat._getTracker("UA-xxxxxx-x");
  pageTracker._initData();
  pageTracker._trackPageview();
  (function(){ //track BM document files
    var logDoc = function(evt) {
      var e = Event.element(evt);
      if(e.nodeType == 3) { e = e.parentNode; } //Safari bug
      if (e.tagName=='A') {
          var match = e.href.match(/(\/bm~doc\/.*)/);
          if (match) { pageTracker._trackPageview(match[1]); }
      }
    };
    BM.onDOM.addEvent(function(){
      Event.observe(document.body,'click',logDoc);
    });
  })();
</script>

Limitations

This code change makes Google Analytics track links only to files loaded via Big Medium's control panel. It will not track downloads of files that are linked directly from other sites, and it will not track downloads to files that were not loaded via Big Medium's control panel.

Download Big Medium
Try it free for 30 days, or buy to unlock.

Beautiful

"Beautiful interface. Installed with absolutely no problem. I AM IMPRESSED."
—Tom Marks

"This CMS has proven to be great and adaptable to the designer's vision, making my life easier."
—Scott Jordison

"Big Medium is everything I hoped for and more, and we're receiving a lot of compliments on the site's functionality. Moreso, I'd like to thank you for your exemplary customer service. You truly made me feel that you had a personal stake in our implementation, and gave me the confidence that when we went live, everything would be perfect. If only every tech-related experience was like this one."
—Andrew McKay

More praise for Big Medium