/** * Class constructor * * @since 2.0.0 * * @param Optin_Monster_Track_Datastore $track_store The tracking datastore object */ public function __construct(Optin_Monster_Track_Datastore $track_store) { $this->track_store = $track_store; // Provide a hook to save custom tracking data. do_action('optin_monster_track_optin', $track_store->get_optin_id(), 'impression'); // Save the impression to the database. if (apply_filters('optin_monster_tracking', true, $track_store->get_optin_id())) { try { $this->response = $this->track_store->save('impression'); } catch (Exception $e) { $this->response = $e->getMessage(); } } else { $this->response = true; } }
/** * Handles conversion tracking for the Canvas addon. * * @since 2.0.1 */ function optin_monster_canvas_do_conversions() { // If the conversion parameter is empty, return early. if (empty($_GET['omcanvas'])) { return; } // Grab the optin. $optin = Optin_Monster::get_instance()->get_optin_by_slug(stripslashes($_GET['omcanvas'])); if (!$optin) { return; } // Process the conversion. if (!class_exists('Optin_Monster_Track_Datastore')) { require plugin_dir_path(Optin_Monster::get_instance()->file) . 'includes/global/track-datastore.php'; } $track = new Optin_Monster_Track_Datastore($optin->ID); $track->save('conversion'); // Add a hook for custom functionality. do_action('optin_monster_canvas_conversion', $optin); }
/** * Renders the rest of the columns in the list table. * * @since 2.0.0 * * @param object $optin The optin object. * @param string $column_name The name of the column. * @return string $value The value of the column. */ public function column_default($optin, $column_name) { // Load the track datastore interface. $track_store = new Optin_Monster_Track_Datastore($optin->ID); switch ($column_name) { case 'name': $value = !empty($optin->post_title) ? $optin->post_title : $optin->post_name; break; case 'notes': $value = get_post_meta($optin->ID, '_om_split_notes', true); $split = get_post_meta($optin->ID, '_om_is_clone', true); if (empty($split)) { $value = '<span class="om-split-test-title">' . __('Parent Optin', 'optin-monster') . '</span>'; } break; case 'impressions': $value = number_format($track_store->get_impressions()); break; case 'conversions': $value = number_format($track_store->get_conversions()); break; case 'percent': $imp = $track_store->get_impressions(); $conv = $track_store->get_conversions(); $value = 0 == $conv ? '0' : number_format($conv / $imp * 100, 2) . '%'; break; case 'status': $meta = get_post_meta($optin->ID, '_om_meta', true); $value = Optin_Monster_Common::get_instance()->get_optin_status($meta); $value .= '<div class="row-actions">'; $value .= Optin_Monster_Common::get_instance()->get_optin_status_link($meta, $optin->ID); $value .= '</div>'; break; case 'settings': $link = '<a href="#" class="om-settings-button" title="' . esc_attr__('Optin settings', 'optin-monster') . '"><i class="fa fa-cog"></i></a>'; $link .= '<div class="om-settings-popover">'; $link .= $this->get_settings_actions($optin); $link .= '</div>'; $value = $link; break; default: $value = apply_filters('optin_monster_column_value', '', $optin, $column_name); break; } return apply_filters('optin_monster_table_column', $value, $optin, $column_name); }
/** * Collects data about the optins. * * @since 2.1.0 * @return array */ private function get_optins() { if (!class_exists('Optin_Monster_Track_Datastore')) { require plugin_dir_path($this->base->file) . 'includes/global/track-datastore.php'; } $optin_posts = $this->base->get_optins(); $optins = array(); foreach ((array) $optin_posts as $optin) { $datastore = new Optin_Monster_Track_Datastore($optin->ID); $meta = get_post_meta($optin->ID, '_om_meta', true); $optins[] = array('type' => isset($meta['type']) ? $meta['type'] : 'Unknown', 'theme' => isset($meta['theme']) ? $meta['theme'] : 'Unknown', 'impressions' => $datastore->get_impressions(), 'conversions' => $datastore->get_conversions(), 'affiliate_link' => isset($meta['powered_by']) ? $meta['powered_by'] : 0); } return $optins; }
/** * The class constructor. * * @since 2.0.0 * * @param $data The user data from the browser * @param Optin_Monster_Provider $provider The provider object * @param Optin_Monster_Lead_Datastore $lead_store The lead datastore object * @param Optin_Monster_Track_Datastore $track_store The tracking datastore object */ public function __construct($data, Optin_Monster_Provider $provider, Optin_Monster_Lead_Datastore $lead_store, Optin_Monster_Track_Datastore $track_store) { // Set class properties. $this->provider = $provider; $this->lead_store = $lead_store; $this->track_store = $track_store; // Process the data from the browser. $lead['optin_id'] = isset($data['optin_id']) ? absint($data['optin_id']) : 0; $lead['referrer'] = isset($data['referrer']) ? stripslashes(esc_url($data['referrer'])) : ''; $lead['user_agent'] = isset($data['user_agent']) ? stripslashes(strip_tags($data['user_agent'])) : ''; $lead['lead_name'] = isset($data['name']) ? stripslashes($data['name']) : ''; $lead['lead_email'] = isset($data['email']) ? stripslashes($data['email']) : ''; $lead['referred_from'] = isset($data['previous']) ? stripslashes(esc_url($data['previous'])) : ''; $lead['post_id'] = isset($data['post_id']) ? absint($data['post_id']) : 0; $lead['lead_type'] = 'conversion'; // Get the optin meta data. $this->optin_meta = get_post_meta($lead['optin_id'], '_om_meta', true); // Provide a hook to save custom tracking data. do_action('optin_monster_track_optin', $lead['optin_id'], 'conversion'); // Increase the conversion counter. if (apply_filters('optin_monster_tracking', true, $lead['optin_id'])) { try { $track = $this->track_store->save('conversion'); } catch (Exception $e) { $this->response = $e->getMessage(); } } // Save the lead in the database. $option = get_option('optin_monster'); if (isset($option['leads']) && $option['leads']) { try { $save = $this->lead_store->save($lead); } catch (Exception $e) { $this->response = $e->getMessage(); } } // Save the lead to the email provider. $providers = Optin_Monster_Common::get_instance()->get_email_providers(true); $provider = $this->optin_meta['email']['provider']; $account = $this->optin_meta['email']['account']; $list_id = $this->optin_meta['email']['list_id']; // Prepare the provider account. $provider_account = $providers[$provider][$account]; $provider_account['account_id'] = $account; // Get segments if set. if (!empty($this->optin_meta['email']['segments'])) { $provider_account['segments'] = $this->optin_meta['email']['segments']; } // Get client if set. if (!empty($this->optin_meta['email']['client_id'])) { $provider_account['client'] = $this->optin_meta['email']['client_id']; } // Set the response. $this->response = $this->provider->optin($provider_account, $list_id, $lead); // Provide a hook to interact with the lead. do_action('optin_monster_after_lead_stored', $lead, $this); // Allow the response to be filtered (as long as it is not an error) so that lead data can be passed back to redirect URLs. if (!is_wp_error($this->response)) { $this->response = apply_filters('optin_monster_lead_response', $this->response, $lead, $this); } }