Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Returns default properties sent with every event for a user.
- *
- * During a single request, it will cache the default properties for
- * a given user account.
- *
- * @param object $account
- * (optional) The user these defaults are for. If not given, the currently
- * logged in user will be used.
- * @param bool $reset
- * (optional) If set to TRUE, the cache will be cleared and fresh data will be
- * returned.
- *
- * @return array
- * Array of the default mixpanel variables.
- *
- * @see hook_mixpanel_default_alter()
- * @see mixpanel_track()
- *
- * @ingroup mixpanel
- */
- function mixpanel_get_defaults($account = NULL, $reset = FALSE) {
- global $user;
- $defaults =& drupal_static(__FUNCTION__, array());
- // If user object is passed in, favor that, otherwise, set $account to the
- // current object.
- if (is_null($account)) {
- $account = $user;
- }
- if (!isset($defaults[$account->uid]) || $reset) {
- $properties = array(
- 'ip' => ip_address(),
- '$browser' => _mixpanel_get_browser(),
- '$os' => _mixpanel_get_os(),
- '$device' => _mixpanel_get_device(),
- '$referrer' => $_SERVER['HTTP_REFERER'],
- '$referring_domain' => parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST),
- );
- // For authenticated users.
- if ($account->uid != 0) {
- $properties = array_merge($properties, array(
- 'uid' => $account->uid,
- 'mp_name_tag' => $account->name,
- 'distinct_id' => $account->uid,
- ));
- }
- // Let other modules alter the defaults.
- drupal_alter('mixpanel_defaults', $properties, $account);
- $defaults[$account->uid] = $properties;
- }
- return $defaults[$account->uid];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement