Tuesday, March 27, 2012

Setting Keys Based on Build Type

One thing I've been doing for a while is using a different key for Google Analytics based on whether I'm developing the application or deploying it to the market.  The concept is simple enough, but it does result in a manual step of swapping the keys at deploy time.

The latest release of the ADT includes a new constant that gets set for you depending on the type of build!  Now you can query BuildConfig.DEBUG to determine if your build is for development (DEBUG = true) or deployment (DEBUG = false).

I'm using it successfully as follows:

UACODE = (BuildConfig.DEBUG) ? "UA-12345678-1" : "UA-12345678-2"; // Test : Production

No comments:

Post a Comment