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/. 🙂

2016 Rocky Horror Picture Show

Comics in Action (in collaboration with The Englert Theatre) is gearing up for what will be the 8th Anniversary of the “Rocky Horror Picture Show” in the most iconic theater in downtown Iowa City, IA… The Englert Theatre. 🙂

Give yourself over to absolute pleasure!

Let’s do the Time Warp again at this 8th Annual return of The Rocky Horror Picture Show screening and LIVE show, presented by The Englert and Comics in Action on Saturday, October 29th at midnight.

Come out at midnight (or earlier at 11:30pm when The Engert opens their doors) for the only film that brings together costumes, screaming, laughs, and the occasional thrown object! The Englert will provide the props (included with your ticket purchase), and you, our Transylvanians, will bring your best voice and every single-one of your virgin friends. 🙂

Don’t dream it, be it.

Come as your best Rocky Horror character (or something else… we don’t care), and enter to win for a first place prize! And dammit, Janet… oversized costume props are NOT allowed in the theater… as The Englert staff may very well ask you to check those oversized items at the Box Office. So, please be warned. 🙂

We look forward to you being there, and yelling your lungs out… at the film screeen… not us. OK, FINE. You can yell at us as well, as long as you do not mind a spritz of water in your face if we decide to do so.

Who is in This Year’s show?

The 2016 Rocky Horror cast will contain (as usual): Ken Van Egdon (Dr. Frank), Dave Atwater (Dr. Scott), Dennis Lambing (Brad), Noelle McVey (Columbia #1), Shaina Lacina (Columbia #2), Liz Goranson (Janet), Brian Tanner (Riff Raff), and (New-This-Year and acclaimed University of Iowa Stage Actor) Sage Spiker (Rocky).

As well, this show will include the supporting personnel of: Libby Nachtrieb (make-up artist), Wal J. Replicant (photographer), Tymon Peak (backstage hand), and Sandy Linders Goodson (designated ‘Virgin’ marker).

See you there…

My Most Quotable Movies

Watching “Aliens” tonight on the SiFi channel, I am again internally debating the world’s most quotable movies. To be honest, I’ve had this conversation with my friends, Chris Hanel (of “The Formula” and Daily Blink fame), (Dave Atwater, Brian Bodensteiner, and Todd Gutknecht) of the improv troupe, “Comics In Action,” and Angie Toomsen (a woman who really loves movies).

Continue reading My Most Quotable Movies

Wow! I Got Nominated in Dreamwell’s 2014 Night of Stars!

Found out I was nominated for two categories: Best Actor (Becky’s New Car) and Best Tech (Fictional Murders). 🙂

The winners will receive their trophies at the Night of Stars event, which is Thursday June 5th at the North Ridge Pavilion, 2250 Holiday Rd, in Coralville, at 7:00pm. Because space in this venue is limited we encourage you to make a reservation. To make a reservation please e-mail elisabeth@dreamwell.com with your name and number of guests. We hope to see you there! Nominees, please also make a reservation so we know you’re coming! In addition to the awards ceremony, there will be entertainment, wine and hors d’oeuvres…

Continue reading Wow! I Got Nominated in Dreamwell’s 2014 Night of Stars!

Becky’s New Car – Another Fantastic Dreamwell Theater Production

Holy Mackerel, I don’t do a lot of “on-stage” acting… mostly, I do a lot of back-end stuff… lighting, sound-design and such… However, this time-around I offered my services as an actor and auditioned for Dreamwell’s “Becky’s New Car”. I was not all that familiar with the material, yet I placed my foot forward and rattled-off a bunch of stuff from the script that To This Day… I’m not entirely sure what I read. 🙂 However, the small part I DID remember was the part of “Steve”, a forlorn employee of Buckley’s “Super Car Dealership”…. the monologue was “To Die For”!

Continue reading Becky’s New Car – Another Fantastic Dreamwell Theater Production