Blog Entry

Nov 27, 2009

Sneak Past Analytics Code While Developing

Let’s face it.  All too often, I end up working on living code; I work really hard and finally deploy a site, but it’s never truly done.  And when I’m working in a live server environment (and even when I’m not), I tend to make tons of incremental edits with lots of saves in between.  Why?  Well, because no matter how careful I am, it’s inevitable that these big sausage fingers will end up hitting the "=" key one too many times and make whole sections of a website disappear.

But with the constant slew of saving and tweaking comes the annoying fact that each page refresh pings your client’s analytic tracking code.  No, it’s not that big of a deal. But if you’re like me, it can be annoying — especially since it’s not uncommon to have loaded a hundred pages or more during the period of development.  It skews data and is just plain stinky.

So how do we stop this?  It’s easy, and I take no credit for the fix since a vegetable could figure it out.  Simply use an IF statement with ExpressionEngine’s conditional {logged_out} variable, like so:


{if logged_out}
<!—Insert your tracking code here.—>
{/if}

Note: If your ExpressionEngine site allows users to log in and interact as a user, you won’t want to use this code. Instead, you would want to bypass the tracking code only when logged in as a Super Admin.  The code for this is very similar to above, but uses a different conditional variable:


{if group_id != ‘1’}
<!—Insert your tracking code here.—>
{/if}

Keep in mind that this code isn’t just handy for analytic tracking code — it will show or hide anything your little heart desires.  Be creative.  Hope this helps!


Syndicate

 

Comments

No Comments

There aren't any comments on this entry yet. Why don't you share your thoughts?

Leave A Comment