Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I am declaring:

 var title = (typeof(el.attr('title')) != 'undefined' ) ? el.attr('title') :"";   

and then have the following:

else if (title.match(/^"Matching Content"\:/i)) {          
      elEv.category = "Matching Content Click"; 
      elEv.action = "click-Matching-Content"; 
      elEv.label = href.replace(/^https?\:\/\//i, '');   
      elEv.non_i = true; 
      elEv.loc = href; 
    }   

However, using Google Analytics debugger this is not being recorded.

Any suggestions?

The complete function is:

if (typeof jQuery != 'undefined') {
  jQuery(document).ready(function gLinkTracking($) {
    var filetypes = /\.(avi|csv|dat|dmg|doc.*|exe|flv|gif|jpg|mov|mp3|mp4|msi|pdf|png|ppt.*|rar|swf|txt|wav|wma|wmv|xls.*|zip)$/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 title = (typeof(el.attr('title')) != 'undefined' ) ? el.attr('title') :"";      
      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 link";
          elEv.action = "click-email";
          elEv.label = href.replace(/^mailto\:/i, '');
          elEv.loc = href;
        }
        else if (title.match(/^"Matching Content"\:/i)) {          
          elEv.category = "Matching Content Click"; 
          elEv.action = "click-Matching-Content"; 
          elEv.label = href.replace(/^https?\:\/\//i, '');   
          elEv.non_i = true; 
          elEv.loc = href; 
        }       
        else if (href.match(filetypes)) {
          var extension = (/[.]/.exec(href)) ? /[^.]+$/.exec(href) : undefined;
          elEv.category = "File Downloaded";
          elEv.action = "click-" + extension[0];
          elEv.label = href.replace(/ /g,"-");
          elEv.loc = baseHref + href;
        }           
        else if (href.match(/^https?\:/i) && !isThisDomain) {
          elEv.category = "External link";
          elEv.action = "click-external";
          elEv.label = href.replace(/^https?\:\/\//i, '');
          elEv.non_i = true;
          elEv.loc = href;
        }   
        else if (href.match(/^tel\:/i)) {
          elEv.category = "Telephone link";
          elEv.action = "click-telephone";
          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;
      }
    }
      }
    });
  });
} 
share|improve this question
    
Can you share the site with us? What does the event your pushing look like? –  Blexy Oct 16 '13 at 16:25
    
@Blexy, I cannot unfortunately but I have updated my question to show the complete function. –  rlsaj Oct 21 '13 at 0:50
    
Are any of the events firing? Have you looked into using a tool such as HTTPFox or Google Debugger to look at HTTP requests? –  Blexy Oct 21 '13 at 16:54
    
@Blexy, I use Google Analytics Debugger (Firefox) and use the other events do fire. I just tested this again this morning. –  rlsaj Oct 21 '13 at 22:05

1 Answer 1

up vote 2 down vote accepted

I have no way of testing this code without creating a jsfiddle or having you show me the site, but from a high-level, if a title does not exist, meaning it would be given "" as a value:

    var title = (typeof(el.attr('title')) != 'undefined' ) ? el.attr('title') :"";   

Then, you do your else if, and attempt to match title using "" as the value of title, it probably won't work, correct?

     else if (title.match(/^"Matching Content"\:/i)) {          
      elEv.category = "Matching Content Click"; 
      elEv.action = "click-Matching-Content"; 
      elEv.label = href.replace(/^https?\:\/\//i, '');   
      elEv.non_i = true; 
      elEv.loc = href; 
    } 

Thoughts?

share|improve this answer
    
Thanks Blexy. Turns out I didn't need \: at the end of my Matching Content string, because of course I wasn't checking for :. Silly mistake on my behalf. And yes, would've been solved if i could share my site with you. –  rlsaj Oct 28 '13 at 22:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.