views:

37

answers:

1

EDIT: This question is solved, but I can't accept my own answer just yet.

Howdy!

So I've got a PHP/CodeIgniter webapp. I've got some custom Ajax-based tracking code inserted into my page - however obviously, for testing purposes, I don't want this code to fire when I'm running the site locally on my development computer.

In order to avoid Analytics still tracking, I'm using this in my source code:

<?php if ($_SERVER['HTTP_HOST'] != 'localhost:8888'){ ?>
    _gaq.push(['_trackPageview', '/my/ajax/page']);
<?php } ?>

That does the job fine in the source code - when I'm on http://localhost:8888 (MAMP's URL) it doesn't appear. When I'm running live, it appears. Woot.

However I've found some seemingly infinite error. When you click a link that fires an Ajax event, the Firebug log repeatedly fills up and up and up with errors, if you leave it a couple of minutes it gets into the thousands (I guess it's an infinite loop). The error each time is:

_gaq is not defined

Then it references it being on localhost:8888 (line 26). Line 26 reads:

<!-- Includes for Uniform JS -->

Just a comment... I've removed that (and the subsequent Uniform JS script links beneath), same error, just goes to the next possible line. So I thought it might be the script above causing it the problem, that was Typekit. Commented out Typekit, still the same issue. Ouch.

Anybody know what's going wrong here?

*Could I just forget the PHP blocking bit and can I block my localhost in Google Analytics? The problem is I'm on a dynamic IP so changing Analytics settings every time my computer gets switched on will be a pain in the bum *.

Thanks!

Jack

EDIT: I should make it clear that EVERY reference to Google Analytics is put between the <?php ?> blocks, including the declaration at the foot of the page. So it's not like there's some Analytics JS appearing and not the rest.

A: 

Problem solved. Thanks to everyone who read this question and considered answers for me.

It was a pretty easy one:

<?php if ($_SERVER['HTTP_HOST'] == 'localhost:8888') { ?>

Turns out I'd written == by mistake, instead of != on one occurrence of the PHP block!

Oops, Thanks!

Jack Webb-Heller
I can't accept my answer for another two days though :/
Jack Webb-Heller