/**
  * Sets the company_data on a contact
  *
  * @param	object
  * @return	object
  */
 function get_company_details($lead)
 {
     global $blacklist_freemail_domains;
     global $blacklist_nonmail_domains;
     $site_url = site_url();
     $email_domain = end(explode('@', $lead->lead_email));
     $inboundrocket_user = inboundrocket_get_current_user();
     $company_data = '';
     if (strstr($inboundrocket_user['email'], ',')) {
         $inboundrocket_user_email = reset(explode(',', $inboundrocket_user['email']));
     } else {
         $inboundrocket_user_email = $inboundrocket_user['email'];
     }
     if (!in_array($email_domain, $blacklist_nonmail_domains) && !in_array($email_domain, $blacklist_freemail_domains)) {
         if (!$lead->company_data) {
             // Grab the company intel lookup
             $company_data = json_decode($this->query_company_lookup_endpoint($email_domain, $inboundrocket_user_email, $site_url));
             if (isset($company_data->status) && $company_data->status != 'error') {
                 $this->update_company_lookup_data($this->hashkey, serialize($company_data));
                 inboundrocket_track_plugin_activity('Company Lookup Result', array('status' => 'success'));
             } else {
                 inboundrocket_track_plugin_activity('Company Lookup Result', array('status' => 'error'));
             }
         } else {
             $company_data = unserialize($lead->company_data);
         }
     }
     return $company_data;
 }
/**
 * Track plugin activity in MixPanel
 *
 * @param   string
 *
 * @return  array
 */
function inboundrocket_track_plugin_activity($activity_desc, $custom_properties = array())
{
    if (!function_exists('curl_init')) {
        return false;
    }
    $inboundrocket_user = inboundrocket_get_current_user();
    global $wp_version;
    global $current_user;
    get_currentuserinfo();
    $user_id = md5(get_site_url());
    $plugins = wp_get_active_and_valid_plugins();
    $default_properties = array("distinct_id" => $user_id, '$wp-url' => get_site_url(), '$wp-version' => $wp_version, '$ir-version' => INBOUNDROCKET_PLUGIN_VERSION, '$wp-plugins' => $plugins);
    $properties = array_merge((array) $default_properties, (array) $custom_properties);
    $mp = Mixpanel::getInstance(INBOUNDROCKET_MIXPANEL_PROJECT_TOKEN, array("debug" => true));
    $mp->track($activity_desc, $properties);
    return true;
}
 /**
  * Creates Mixpanel tracking email pixel
  *
  * @return  string      specs @ https://mixpanel.com/docs/api-documentation/pixel-based-event-tracking
  */
 function create_tracking_pixel()
 {
     $url_properties = array('token' => INBOUNDROCKET_MIXPANEL_PROJECT_TOKEN);
     $inboundrocket_user = inboundrocket_get_current_user();
     $inboundrocket_user_properties = array('distinct_id' => $inboundrocket_user['user_id'], '$wp-url' => $inboundrocket_user['wp_url'], '$wp-version' => $inboundrocket_user['wp_version'], '$ir-version' => $inboundrocket_user['ir_version']);
     $properties = array_merge($url_properties, $inboundrocket_user_properties);
     $params = array('event' => 'Contact Notification Opened', 'properties' => $properties);
     return 'http://api.mixpanel.com/track/?data=' . base64_encode(json_encode($params)) . '&ip=1&img=1';
 }