Change a variable dynamically without it persisting in the DB I am wanting to change a variable (google analytics ID) programmatically based on the environment, BUT I do not want to change the saved value, so variable_set() is not an option.

Ideally I would also like the value that I set to be cached so as to not undermine performance.
So this is what I came up with, an implementation of hook_init(). Perhaps there is a better solution?

function MYMODULE_init() {
  global $conf;

  // If we have the environmental variable ENV &amp;&amp; we are not on a config page
  if ($env = getenv('ENV') &amp;&amp; current_path() != 'admin/config/system/googleanalytics') {

    // Alter the googleanalytics_account ID
    if ($env == 'dev') {
      $conf['googleanalytics_account'] = 'UA-xxxxxxxx-x';
    }
  }
}