Friday, June 25, 2010

Google Analytics Custom Variables - How To Trim Properly

Well I've been geeking out with Google Analytics as of late, and I've got to say, why would anyone pay for it anymore? Awesome tool that satisfies most Analytics needs.

That being said, recently Google launched a new feature called Custom Variables. This new feature is very powerful, but it has some limitations. One of these is that during a single page load request, if you total up all the keys and all the values for your request, they can only equal 64 bytes in total.

Other limitation are that you are limited to setting 5 key value pairs at a time, and the other limitation I have run up against is that you cannot send multiple values for a single key in a single page load.

But wait there's more.... The 64 character limit is URIEncoded, that is to say if you have a string with a character that gets URIEncoded, say like a semi-colon, this single byte will be expanded to 3 bytes when it gets URIEncoded.

So AB;

Becomes

AB%3D

If you are using the code on the net I found that URIEncodes, then trims the string, then URIDecodes before passing to _setCustomVar, you can run into an error where you wind up with a partial string on the end, that when URIDecoded will generate an error. To solve this problem I wrote the following function that allows the setting of custom variables and will trim them to an arbitrary length and will also get rid of any partially URIEncoded strings at the end.

Enjoy:

  function gaTrimCustomVar(vstr,vlen) {
// URI encode and truncate to vlen
var tstr = encodeURIComponent(vstr).substr(0,vlen);

// If the first character is URL encoded and length is not at least 3
// we'll return untrimmed and let the upper level deal otherwise we would clear
// the value completely and return an empty string.
if( tstr.indexOf('%') == 0 && vlen < 3) {
return vstr;
}

// load a pointer to any partial URI encoded characters at the end

var uptr = tstr.substr(tstr.length - 2,2).indexOf('%');

// If there aren't any partial URI encoded characters at the end, return
if(uptr == -1) {
return decodeURIComponent(tstr);
}

// return only up to the last partially URI encoded character.
return decodeURIComponent(tstr.substr(0,(tstr.length - 2) + 1));

}

Thursday, June 24, 2010

Conficker - Still paying for the mistakes of the past

I've been specializing in Analytics lately and I use Linux on all my desktop machines, so I haven't really paying that much attention to the Windoze arena other than the nicely manicured, maintained by a team of overseas engineers Windoze machines. I was reading this article from The Atlantic the other day, and I think the time has finally come to migrate off of Redmond Swiss Cheese once and for all.

The Conficker worm is one MF, for sure. The problem is this. You don't have to get infected by it directly. If there's a machine that's on the same network you're on, and it has the Conficker worm. That machine will actively attack your machine. It will try new security holes, and it will even try password cracks to try and guess your passwords.

First detected back in 2008, this thing has just gotten bigger and badder ever since. Sure there are patches, and apparently only some unreleased Beta of Windows 7 was vulnerable, but most of the other release before it were at one point vulnerable.

So let's say that you have one of these Windows systems and you are installing it fresh. It's probably vulnerable out of the box and will need an update. Well guess what, you have to connect to the Internet, to get the patch to close the hole. If you are on a network and there are machines that are infected, they will be actively attacking your machine. It's a race against time to see if you can patch your system before the nasties get in.

I just don't get it, I'm talking with my significant other's employer, they have seem to be having the same problems every network with Windows has, things work, then don't work, machines get infected with virus' and other nasty stuff, compatibility issues with older version and when I tell them they need to get off Windows and onto Mac's or Linux, they say "Well Windows has been working fine for us". When in fact they have all of the problems I just described. It's funny how people computers can run slow, crash and have all kinds of other issues that keep them from working and things are "working fine for us". The very next day, this same person I had the conversation with has the nastiest picture she has ever seen, spread eagle on her screen with the message "Watch Me Masturbate!". I think their ready for Linux now :)