title: Using custom variable in GA event tracking
body: <p>I am trying to get a custom variable into some Event Tracking in a dynamic templating system. It uses information from the URL to use as the variable.</p>
  
  <p>There is nothing coming across into analytics with this script appended. Can anyone see anything wrong with it? </p>
  
  <pre><code>jQuery(function iCatGaFunction() {
      jQuery('#catbanner').click(function () {
          var url = jQuery(location).attr('href'); // get the current url
          var iCat = url.substring(url.lastIndexOf('/') + 1); // Last index of the url icat reference 
          _gaq.push(['_setCustomVar', 1, 'iCatBanner', iCat]); // GA snippet
      });
  });
  
  jQuery('#catbanner').find('a:first').attr('onClick', 'iCatGaFunction()'); // wrap first a href around &lt;img&gt; and call function onclick
  </code></pre>
  
  <p>I followed the instructions here - perhaps something to do with scope? 
  <a href="https://developers.google.com/analytics/devguides/collection/gajs/methods/gaJSApiBasicConfiguration#_gat.GA_Tracker_._setCustomVar" rel="nofollow">https://developers.google.com/analytics/devguides/collection/gajs/methods/gaJSApiBasicConfiguration#_gat.GA_Tracker_._setCustomVar</a></p>