jas1988

Mixpanel

Dec 7th, 2015
66
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Returns default properties sent with every event for a user.
  3.  *
  4.  * During a single request, it will cache the default properties for
  5.  * a given user account.
  6.  *
  7.  * @param object $account
  8.  *   (optional) The user these defaults are for. If not given, the currently
  9.  *   logged in user will be used.
  10.  * @param bool $reset
  11.  *   (optional) If set to TRUE, the cache will be cleared and fresh data will be
  12.  *   returned.
  13.  *
  14.  * @return array
  15.  *   Array of the default mixpanel variables.
  16.  *
  17.  * @see hook_mixpanel_default_alter()
  18.  * @see mixpanel_track()
  19.  *
  20.  * @ingroup mixpanel
  21.  */
  22. function mixpanel_get_defaults($account = NULL, $reset = FALSE) {
  23.   global $user;
  24.  
  25.   $defaults =& drupal_static(__FUNCTION__, array());
  26.  
  27.   // If user object is passed in, favor that, otherwise, set $account to the
  28.   // current object.
  29.   if (is_null($account)) {
  30.     $account = $user;
  31.   }
  32.  
  33.   if (!isset($defaults[$account->uid]) || $reset) {
  34.     $properties = array(
  35.       'ip' => ip_address(),
  36.       '$browser' => _mixpanel_get_browser(),
  37.       '$os' => _mixpanel_get_os(),
  38.       '$device' => _mixpanel_get_device(),
  39.       '$referrer' => $_SERVER['HTTP_REFERER'],
  40.       '$referring_domain' => parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST),
  41.     );
  42.  
  43.     // For authenticated users.
  44.     if ($account->uid != 0) {
  45.       $properties = array_merge($properties, array(
  46.         'uid' => $account->uid,
  47.         'mp_name_tag' => $account->name,
  48.         'distinct_id' => $account->uid,
  49.       ));
  50.     }
  51.  
  52.     // Let other modules alter the defaults.
  53.     drupal_alter('mixpanel_defaults', $properties, $account);
  54.  
  55.     $defaults[$account->uid] = $properties;
  56.   }
  57.  
  58.   return $defaults[$account->uid];
  59. }
RAW Paste Data