Hacker News new | ask | show | jobs
by cookiemonsta 3700 days ago
What would be the reason for this:

// analytics disable if url contains underscore try { if(window.location.href.indexOf('_') > 0) {window['ga-disable-UA-20753548-1'] = true;} } catch(e) {} });

3 comments

It seems like they store files (presumably both internal and public) under https://www.nsa.gov/ia/_files/ so I guess it's the way they represent their non-indexable urls.
The if condition is wrong. This is why functions like indexOf should return a tuple of a boolean and an offset instead of encoding "not found" by returning -1.
The if condition should use >= rather than >, but it otherwise makes sense.
I'm not arguing in favor of writing it that way, but I might argue it's not incorrect as written. location.href can never start with an underscore.

A regex on location.pathname would sure be a lot clearer to read, though.

My guess is that there is a test scenario in which they don't want google analytics to load?