Note that there are some explanatory texts on larger screens.

plurals
  1. POUncaught ReferenceError: pageTracker is not defined
    text
    copied!<p>You'll have to forgive me on this one. I understand that the issue is probably very simple, but I'm not a JS coder and am only just starting to get to grips with jQuery.</p> <p>So I have a jQuery Ajax call in <code>$(document).ready</code>:</p> <pre><code>$('#newesttab').click(function() { $('li').removeClass('selectedtab'); $('#newesttab').addClass('selectedtab'); $('#col2').removeClass('featuredcol topratedcol').addClass('newestcol'); $("#ajaxresults").fadeOut("slow", function() { $.ajax({ url: "&lt;?php echo site_url('code/newest'); ?&gt;", success: function(msg) { $('#ajaxresults').html(msg); $("#ajaxresults").fadeIn("fast"); &lt;?php if ($_SERVER['HTTP_HOST'] != 'localhost:8888') { ?&gt;pageTracker._trackPageview('/code/newest/ajax');&lt;?php } ?&gt; } }) }); }); </code></pre> <p>So basically when <code>#newesttab</code> is clicked, it does a bit of mumbo-jumbo with some Clases &amp; IDs, fades stuff out, then loads some data from an Ajax CodeIgniter function. On success, the div <code>#ajaxresults</code> is filled with the data, fades in - and finally, you'll see this line:</p> <pre><code>&lt;?php if ($_SERVER['HTTP_HOST'] != 'localhost:8888') { ?&gt; pageTracker._trackPageview('/code/newest/ajax'); &lt;?php } ?&gt; </code></pre> <p>All that does is check if I'm not on MAMP localhost so as to not get funky data in Analytics. If not, I call Google Analytic's <code>pageTracker</code> thingy to track the URL <code>code/newest/ajax</code> so it appears in my Analytics despite the page being called via Ajax. <strong>That's correct, right?</strong></p> <p>Well Chrome's console shows me this error: <code>Uncaught ReferenceError: pageTracker is not defined</code></p> <p><strong>The part I don't understand, is</strong> that because this code is in <code>(document).ready</code> surely it should only fire when the entire document has loaded? And that means, therefore, that the Google Analytics Asynchronous snippet has loaded before my <code>&lt;/body&gt;</code> tag (yep, it's definitely there)... I guess I'm misunerstanding something, right? </p> <p>And before anybody asks, yes, I've tried this <em>not</em> on localhost ;)</p> <p>Thanks!</p> <p>Jack</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload