1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218:
<?php
class Landing_Pages_Split_Testing_Stats {
public function __construct() {
self::load_hooks();
}
public static function load_hooks() {
add_action( 'lp_record_impression' , array( __CLASS__ , 'record_impression' ) , 10, 3);
add_action( 'inbound_track_link', array(__CLASS__, 'record_conversion'));
add_filter( 'inboundnow_store_lead_pre_filter_data' , array( __CLASS__ , 'record_conversion' ) ,10,1);
}
public static function record_impression($post_id, $post_type , $variation_id = 0) {
if (strstr( $_SERVER['HTTP_REFERER'] , 'edit.php?post_type=landing-page' )) {
return;
}
if (strstr( $_SERVER['HTTP_REFERER'] , 'post.php' )) {
return;
}
if (strstr( $_SERVER['HTTP_REFERER'] , 'edit.php' )) {
return;
}
if ( $post_type == 'landing-page' ) {
$impressions = Landing_Pages_Variations::get_impressions( $post_id, $variation_id );
$impressions++;
Landing_Pages_Variations::set_impressions_count( $post_id, $variation_id, $impressions );
}
else {
$impressions = Landing_Pages_Split_Testing_Stats::get_impressions_count( $post_id );
$impressions++;
Landing_Pages_Split_Testing_Stats::set_impressions_count( $post_id, $impressions );
}
}
public static function record_conversion($data) {
if (!isset( $data['page_id'] ) ) {
return $data;
}
$do_not_track = apply_filters('inbound_analytics_stop_track' , false );
if ( $do_not_track ) {
return $data;
}
$post_type = get_post_type($data['page_id']);
$data['vid'] = (isset($data['vid'])) ? $data['vid'] : 0;
$data['vid'] = (isset($data['variation'])) ? $data['variation'] : $data['vid'];
if (current_filter() == 'inbound_track_link' && $post_type != 'landing-page' ) {
return;
} else if ($post_type === 'landing-page' ) {
$data['vid'] = (isset($data['lp-variation-id'])) ? $data['lp-variation-id'] : $data['vid']; $data['vid'];
$conversions = Landing_Pages_Variations::get_conversions( $data['page_id'] , $data['vid'] );
$conversions++;
Landing_Pages_Variations::set_conversions_count( $data['page_id'] , $data['vid'] , $conversions );
}
else {
$conversions = Landing_Pages_Split_Testing_Stats::get_conversions_count( $data['page_id'] );
$conversions++;
Landing_Pages_Split_Testing_Stats::set_conversions_count( $data['page_id'] , $conversions );
}
return $data;
}
public static function register_columns( $cols ) {
$cols['inbound_impressions'] = __( 'Impressions' , 'inbound-email' );
$cols['inbound_conversions'] = __( 'Conversions' , 'inbound-email' );
$cols['inbound_conversion_rate'] = __( 'Conversion Rate' , 'inbound-email' );
return $cols;
}
public static function prepare_column_data( $column , $post_id ) {
global $post;
switch ($column) {
case "inbound_impressions":
echo self::get_impressions_count( $post->ID );
break;
case "inbound_conversions":
echo self::get_conversions_count( $post->ID );
break;
case "inbound_conversion_rate":
echo self::get_conversion_rate( $post->ID);
break;
}
}
public static function get_impressions_count( $post_id ) {
$impressions = get_post_meta( $post_id , '_inbound_impressions_count' , true);
if (!is_numeric($impressions)) {
$impressions = 0;
}
return $impressions;
}
public static function get_conversions_count( $post_id ) {
$conversions = get_post_meta( $post_id , '_inbound_conversions_count' , true);
if (!is_numeric($conversions)) {
$conversions = 0;
}
return $conversions;
}
public static function get_conversion_rate( $post_id ) {
$impressions = Landing_Pages_Split_Testing_Stats::get_impressions_count( $post_id );
$conversions = Landing_Pages_Split_Testing_Stats::get_conversions_count( $post_id );
if ($impressions > 0) {
$conversion_rate = $conversions / $impressions;
$conversion_rate_number = $conversion_rate * 100;
$conversion_rate_number = round($conversion_rate_number, 2);
$conversion_rate = $conversion_rate_number;
} else {
$conversion_rate = 0;
}
return $conversion_rate;
}
public static function set_impressions_count( $post_id , $count ) {
update_post_meta( $post_id, '_inbound_impressions_count', $count );
}
public static function set_conversions_count( $post_id , $count ) {
update_post_meta( $post_id, '_inbound_conversions_count', $count );
}
}
new Landing_Pages_Split_Testing_Stats;