drupal_static array losing values I have a module that i created for the sole purpose of integrating it with sitecatalyst.  If you are unaware of what sitecatalyst is, it is an api that helps create reports based on statistics of your website. EX: Pageviews, Visitors, etc.  Im aware there already is a module for omniture sitecatalyst but is not something i can really use.  I need to track many different variables as well as make it track when certain events fire.  EX: User Login, Create New Account, Comment Submitted, Search for something, etc.  Below i have code that fires everytime in preprocess_page, whenever a user logs in successfully, the properties i need set, and the setting of a static array with all the values i need to create the javascript code needed in order to track everything correctly.

My problem:
I used mymodule_user_login and launches as soon as a user logs in successfully.  I set all the properties and then set all those variables inside my static array.  However, the code in the preprocess_page gets launched everytime and therefore would overwrite the static array created when the mymodule_user_login function was called.  Can someone please help me how to figure out how to do this.  Ive been racking my brain.

Thank you in advance for any help

function mymodule_preprocess_page(&amp;$variables) {
    if (arg(0) == 'admin') {
       return;
    }

    $props = retrieve_props();
    foreach ($props as $key =&gt; $data){
        mymodule_set_variable($key.'=', $data);
    }

    //CODE TO CREATE JAVASCRIPT CODE GOES HERE FOR SITE CATALYST
}   



function mymodule_user_login(&amp;$edit, &amp;$account) {
    $props = retrieve_props();
    foreach ($props as $key =&gt; $data){
        mymodule_set_variable($key.'=', $data);
    }
    mymodule_set_variable('s.events=', 'event13');
}    

function retrieve_props(){
    $props = array();

    /*Program Properties*/
    if (isset($_COOKIE['tsource'])) 
        $tsource = $_COOKIE['tsource'];
    else
        $tsource = 'Organic';
    $props['s.campaign'] = $tsource;

    $server = $_SERVER['COMPUTERNAME'];
    $props['s.server'] = $server;

    $header = drupal_get_http_header();
    if(isset($header['status'])){
        $pageType = 'errorPage';
    }
    else{
        $pageType = null;
    }   
    $props['s.pageType'] = $pageType;

    $rel = getNodeRelation();
    $deg_level = null;
    $cat = null;
    $sub_cat = null;

    if (isset($rel['level']))
        $deg_level = $rel['level']['val'];

    if (isset($rel['category']))
        $cat = $rel['category']['val'];

    if (isset($rel['subject']))
        $sub_cat = $rel['subject']['val'];

    $props['s.prop1'] = $deg_level;
    $props['s.prop2'] = $cat;
    $props['s.prop3'] = $sub_cat;

    $schoolName = null;
    $program = null;
    $channel = null;
    $pageType = null;

    if(arg(0) == 'node'){
        $currentURL = drupal_get_path_alias($_GET['q']);
        $arrURL = explode('/',$currentURL);
        $channel = $arrURL[0];

        if ($variables['node']-&gt;type == 'school') {
            if (count($arrURL) &gt; 1)
                $schoolName = $arrURL[1];
        }
     }
     else if (arg(0) == 'online-degree'){
         $program = arg(1).'-'.arg(4);
         $pagetype = 'program';
     }
     $props['s.prop4'] = $schoolName;
     $props['s.prop5'] = $program;

     $searchTerm = null;    
     if (isset($_GET['textsearch']))    
         $searchTerm = $_GET['textsearch'];

     $props['s.prop6'] = $searchTerm;

     return $props;
}

function mymodule_set_variable($name = NULL, $value = NULL) {
  $variables = &amp;drupal_static(__FUNCTION__, array(), FALSE);

  if (empty($name)) {
     return $variables;
  }
  else {
     $variables['variables'][$name] = $value;
  }
}

function mymodule_get_variables() {
  return mymodule_set_variable();
}
If you look at the code for the form submission handler used for the user login form (user_login_submit()), you will notice that it executes the following code.

  global $user;
  $user = user_load($form_state['uid']);
  $form_state['redirect'] = 'user/' . $user-&gt;uid;

  user_login_finalize($form_state);


user_login_finalize() is the function that invokes the hook_user_login() implementations.

  global $user;
  watchdog('user', 'Session opened for %name.', array('%name' =&gt; $user-&gt;name));
  // Update the user table timestamp noting user has logged in.
  // This is also used to invalidate one-time login links.
  $user-&gt;login = REQUEST_TIME;
  db_update('users')
    -&gt;fields(array('login' =&gt; $user-&gt;login))
    -&gt;condition('uid', $user-&gt;uid)
    -&gt;execute();

  // Regenerate the session ID to prevent against session fixation attacks.
  // This is called before hook_user in case one of those functions fails
  // or incorrectly does a redirect which would leave the old session in place.
  drupal_session_regenerate();

  user_module_invoke('login', $edit, $user);


Effectively, the user is redirected after hook_user_login() is invoked, which means a new page is being served, and Drupal is bootstrapping once again. The content returned from drupal_static() is then reset.

The solution is saving the value in a session variable, for example using functions like ctools_object_cache_get(), and ctools_object_cache_set(), which are already available if you are using the Views module on your site, as it requires the Chaos tool suite, on Drupal 7.