WordPress and Tracking Downloads via Google Analytics

One of the many items that Webmasters will always end of performing (whether they are Guru’s, SEO and Google Analytics Professionals, Web Developers, WordPress Professionals, etc.) is help their client track their website’s traffic.

One of the more ‘finer’ tools is Google Analytics. SEO Professionals make ‘GOOD’ money knowing the in’s/out’s of Google Analytics. The tools are not just top-notch… they are awesome! ๐Ÿ™‚ Now, that does NOT mean that GA Tools are perfect… far from it.

Example: I use StatCounter for my own personal use. Reason: I’ve been using StatCounter since its inception… before Google Analytics even existed. It’s FREE and meets my needs. So What? Well, the FREE version is limited to only the last 500 Page Views… which is fine for me, but does NOT meet the needs on a more professional scale.

So, why this post? StatCounter tracks downloads ‘out-of-the-box’, while Google Analytics does NOT. ๐Ÿ™ So, we have to perform other operations in order for your Google Analytics to track them… which are usually VERY important to the client.

Tracking the WP Website’s Downloads

NOTE: 1) I am assuming this is a WordPress site you own… 2) This ‘tutorial’ is going to assume you HAVE a Google Analytics Account as well. Need help with that? Check this out at Google.

    1. From Google Analytics, retrieve your tracking code: Admin > .JS Tracking Info > Tracking Code.
    2. Copy the Website Tracking code and paste it into the your WP Site’s Header file (header.php) before the PHP call to wp_head.
    3. For Steps 1 & 2… if you have done this already (or through a WP Google Analytics Plugin…) you can skip those first two steps. It will already be inserted by the Plugin.
    4. This missing piece to track the downloads is this:
    5. <script type="text/javascript">
      
      if (typeof jQuery != 'undefined') {
        jQuery(document).ready(function($) {
          var filetypes = /\.(zip|exe|dmg|pdf|doc.*|xls.*|ppt.*|mp3|txt|rar|wma|mov|avi|wmv|flv|wav)$/i;
      
          var baseHref = '';
      
          if (jQuery('base').attr('href') != undefined) baseHref = jQuery('base').attr('href');
      
          jQuery('a').on('click', function(event) {
            var el = jQuery(this);
            var track = true;
      
            var href = (typeof(el.attr('href')) != 'undefined' ) ? el.attr('href') :"";
      
            var isThisDomain = href.match(document.domain.split('.').reverse()[1] + '.' + document.domain.split('.').reverse()[0]);
      
            if (!href.match(/^javascript:/i)) {
              var elEv = []; elEv.value=0, elEv.non_i=false;
      
              if (href.match(/^mailto\:/i)) {
                elEv.category = "email";
                elEv.action = "click";
                elEv.label = href.replace(/^mailto\:/i, '');
                elEv.loc = href;
      
              }
      
              else if (href.match(filetypes)) {
      
                var extension = (/[.]/.exec(href)) ? /[^.]+$/.exec(href) : undefined;
      
                elEv.category = "download";
                elEv.action = "click-" + extension[0];
                elEv.label = href.replace(/ /g,"-");
                elEv.loc = baseHref + href;
              }
              else if (href.match(/^https?\:/i) && !isThisDomain) {
                elEv.category = "external";
                elEv.action = "click";
                elEv.label = href.replace(/^https?\:\/\//i, '');
                elEv.non_i = true;
                elEv.loc = href;
              }
              else if (href.match(/^tel\:/i)) {
                elEv.category = "telephone";
                elEv.action = "click";
                elEv.label = href.replace(/^tel\:/i, '');
                elEv.loc = href;
              }
              else track = false;
      
              if (track) {
                _gaq.push(['_trackEvent', elEv.category.toLowerCase(), elEv.action.toLowerCase(), elEv.label.toLowerCase(), elEv.value, elEv.non_i]);
      
                if ( el.attr('target') == undefined || el.attr('target').toLowerCase() != '_blank') {
                  setTimeout(function() { location.href = elEv.loc; }, 400);
                  return false;
            }
          }
            }
          });
        });
      }
      </script>
    6. Copy/Paste the previous code into the your WP Site’s Header file (header.php) before the PHP call to wp_head. Whether this needs to go BEFORE the Google Analytics code? For me, it has not made a difference. There may be additional JS calls that may hinder this, but as long as your additional JS calls are minimal… I don’t think you are going to have an issue.
    7. To pay due where credit is due, you should pull up the website, http://www.blastam.com/… which does a MUCH better tutorial than I.

So, if you have any further issues, please contact me… or, at the least contact http://www.blastam.com/. ๐Ÿ™‚

GoDaddy Webhosting and Other Such Nonsense

I really don’t understand the issue. I really don’t.

It feels as if everyone (and their mother) has an issue with GoDaddy’s services… to the point where it almost feels comical. What the Hell?

So, I spent a small part of my evening talking with GoDaddy’s Customer Service Department… and left feeling rather happy. All I needed to accomplish… was to simply pull a Domain Name (that I had initially setup as being independent) into my own Web Hosting services… and it went off without a hitch. Do You Hear Me? It Went Off With Out A Hitch!

Continue reading GoDaddy Webhosting and Other Such Nonsense

WordPress and Screencast.com

I had recently been working with a client whose Video Content had been uploaded to Screencast.com. Now, I had never worked with ScreenCast video content before… but, like most video “streamers”, there did not appear any real problems with working with such an organization… at least, within the WordPress construct. Unfortunately, I soon ran into a slew of strange behaviors. Behaviors that I STILL do not quite understand. But, fortunately, I was able to determine the best way of embedding “Screencast.com” video content… laying most of my troubles at rest. ๐Ÿ™‚ Continue reading WordPress and Screencast.com

Site5’s NEW Boldy Theme v2.0.2

Yes, Site5 has released a new-and-improved version (2.0.2) of the popular WordPress Boldy Theme. ๐Ÿ™‚

Site5 has now begun the honorable prospect of separating their Web Hosting tasks, from their WordPress Theme designing arm of the business… and this type of separation is a good thing. ๐Ÿ™‚ Let those that can “host”… host. For those that wish to “design”… then, design. It’s a win-win for many of us.

Continue reading Site5’s NEW Boldy Theme v2.0.2

WordPress Zen: Tweaking the SimpleFolio Theme is not that “Simple”

NOTE: (10/15/2012) There appears to be an update to Simplefolio (v1.6)on the original Slimmity site. However, the site appears to have been compromised. Until this is fixed, you’ll have to downgrade to v1.5. This is just a precaution.

Smashing Magazine did the WordPress world a real favor by making the Simplefolio Theme v1.5 free for-the-taking.

Continue reading WordPress Zen: Tweaking the SimpleFolio Theme is not that “Simple”