0 ? gmdate( 'Y-m-d', time() - $days * DAY_IN_SECONDS ) : '1970-01-01', gmdate( 'Y-m-d', time() - DAY_IN_SECONDS ), ); } } if ( ! function_exists( 'aieo_landing_income_titles' ) ) { function aieo_landing_income_titles( $paths ) { $module = class_exists( 'AIEO_DMM' ) ? AIEO_DMM::instance()->get_module( 'landing_income' ) : null; if ( ! is_object( $module ) || ! method_exists( $module, 'resolve_titles' ) ) { return array(); } return (array) $module->resolve_titles( array_values( array_filter( (array) $paths ) ) ); } } if ( ! function_exists( 'aieo_landing_income_decorate' ) ) { function aieo_landing_income_decorate( $rows ) { $titles = aieo_landing_income_titles( wp_list_pluck( $rows, 'landing_path' ) ); foreach ( $rows as $i => $r ) { $path = (string) $r['landing_path']; $rows[ $i ]['title'] = isset( $titles[ $path ] ) ? (string) $titles[ $path ]['title'] : ''; $rows[ $i ]['page'] = '' !== $rows[ $i ]['title'] ? $rows[ $i ]['title'] : $path; $rows[ $i ]['path_sub'] = '' !== $rows[ $i ]['title'] ? $path : ''; $rows[ $i ]['url'] = home_url( $path ); } return $rows; } } if ( ! function_exists( 'aieo_landing_income_pages_rows' ) ) { function aieo_landing_income_pages_rows( $params ) { global $wpdb; $lcd = $wpdb->prefix . 'aieo_landing_campaign_daily'; if ( (string) $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $lcd ) ) !== $lcd ) { return array(); } list( $from, $to ) = aieo_landing_income_window( $params ); $chan = isset( $params['channel'] ) ? (string) $params['channel'] : ''; $has_rev = (bool) $wpdb->get_var( $wpdb->prepare( "SHOW COLUMNS FROM `{$lcd}` LIKE %s", 'revenue' ) ); $rev_sel = $has_rev ? 'ROUND(SUM(l.revenue),2)' : '0'; $where = 'WHERE l.`date` BETWEEN %s AND %s AND l.landing_path <> \'\'' . AIEO_DMM_Landing_Income::exclude_sql( 'l.landing_path' ); $args = array( $from, $to ); if ( '' !== $chan ) { $where .= ' AND l.channel = %s'; $args[] = $chan; } $join = ''; $nl_sel = '0'; $ps_sel = '0'; $lq_sel = '0'; if ( class_exists( 'AIEO_DMM_Conversions_Registry' ) ) { $conv = AIEO_DMM_Conversions_Registry::table(); if ( (string) $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $conv ) ) === $conv ) { $join = $wpdb->prepare( " LEFT JOIN ( SELECT landing_path, SUM( goal_key = 'newsletter_signup' ) nl, SUM( goal_key = 'push_subscribe' ) ps, SUM( goal_key IN ( 'product_request', 'waitlist_signup' ) ) lq FROM `{$conv}` WHERE conversion_type = 'goal' AND landing_path <> '' AND occurred_at BETWEEN %s AND %s GROUP BY landing_path ) g ON g.landing_path = l.landing_path", $from . ' 00:00:00', $to . ' 23:59:59' ); $nl_sel = 'COALESCE(MAX(g.nl),0)'; $ps_sel = 'COALESCE(MAX(g.ps),0)'; $lq_sel = 'COALESCE(MAX(g.lq),0)'; } } $rows = (array) $wpdb->get_results( $wpdb->prepare( "SELECT l.landing_path, SUM(l.sessions) s, SUM(l.engaged_sessions) e, SUM(l.cart_adds) c, SUM(l.goals) g, SUM(l.purchases) o, {$rev_sel} rev, {$rev_sel} / NULLIF(SUM(l.sessions),0) rps, {$nl_sel} nl, {$ps_sel} ps, {$lq_sel} lq FROM `{$lcd}` l {$join} {$where} GROUP BY l.landing_path", $args ), ARRAY_A ); return aieo_landing_income_decorate( $rows ); } } if ( ! function_exists( 'aieo_landing_income_zeroes_rows' ) ) { function aieo_landing_income_zeroes_rows( $params ) { global $wpdb; $lcd = $wpdb->prefix . 'aieo_landing_campaign_daily'; if ( (string) $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $lcd ) ) !== $lcd ) { return array(); } list( $from, $to ) = aieo_landing_income_window( $params ); $rows = (array) $wpdb->get_results( $wpdb->prepare( "SELECT landing_path, SUM(sessions) s, SUM(engaged_sessions) e, SUM(cart_adds) c FROM `{$lcd}` WHERE `date` BETWEEN %s AND %s AND landing_path <> '' AND channel = 'organic_search'" . AIEO_DMM_Landing_Income::exclude_sql() . " GROUP BY landing_path HAVING s >= 30 AND c = 0", $from, $to ), ARRAY_A ); return aieo_landing_income_decorate( $rows ); } } $aieo_landing_params = array( 'days' => array( 'type' => 'int', 'default' => 30, 'options' => array( 0, 7, 30, 90, 365 ), 'label' => 'Period', ), 'channel' => array( 'type' => 'text', 'default' => '', 'label' => 'Arrived through', ), ); $aieo_landing_page_column = array( 'key' => 'page', 'label' => 'Page', 'type' => 'link', 'subline' => 'path_sub', 'sortable' => true, 'searchable' => true, 'filter' => 'text', 'truncate' => 70, 'tooltip' => true, 'format' => array( 'href' => 'url', 'external' => true ), ); return array( array( 'id' => 'landing_income_pages', 'label' => 'Sessions and revenue per page', 'description' => '', 'source' => 'rows', 'rows' => 'aieo_landing_income_pages_rows', 'registry_id' => 'landing_income.by_page', 'scope' => 'both', 'version' => '1', 'per_page' => 25, 'params' => $aieo_landing_params, 'row_key' => 'landing_path', 'default_sort' => array( 'rev', 'desc' ), 'empty_state' => 'Nothing in this period. Widen the window, or clear the channel.', 'columns' => array( $aieo_landing_page_column, array( 'key' => 'landing_path', 'label' => 'Path', 'type' => 'code', 'hidden' => true, ), array( 'key' => 'url', 'label' => 'URL', 'type' => 'link', 'hidden' => true, ), array( 'key' => 'title', 'label' => 'Title', 'type' => 'text', 'hidden' => true, ), array( 'key' => 's', 'label' => 'Sessions', 'type' => 'integer', 'width' => '95px', 'sortable' => true, 'filter' => 'number_range', 'aggregate' => 'SUM', ), array( 'key' => 'e', 'label' => 'Engaged', 'type' => 'integer', 'width' => '95px', 'sortable' => true, 'aggregate' => 'SUM', ), array( 'key' => 'c', 'label' => 'Cart adds', 'type' => 'integer', 'width' => '100px', 'sortable' => true, 'aggregate' => 'SUM', 'header_tip' => 'Recorded in the visitor\'s own session, so this is the reliable signal. Orders and revenue depend on the session-to-order link, which is thin historically.', ), array( 'key' => 'o', 'label' => 'Orders', 'type' => 'integer', 'width' => '90px', 'sortable' => true, 'aggregate' => 'SUM', ), array( 'key' => 'rev', 'label' => 'Revenue', 'type' => 'money', 'width' => '130px', 'sortable' => true, 'filter' => 'number_range', 'aggregate' => 'SUM', ), array( 'key' => 'rps', 'label' => 'Revenue / session', 'type' => 'money', 'width' => '140px', 'sortable' => true, 'empty' => '', 'aggregate' => 'AVG', ), array( 'key' => 'nl', 'label' => 'Newsletter', 'type' => 'integer', 'width' => '110px', 'sortable' => true, 'empty_zero' => true, 'aggregate' => 'SUM', 'header_tip' => 'Opt-ins credited to the page the visit STARTED on, not the page the prompt appeared on.', ), array( 'key' => 'ps', 'label' => 'Push', 'type' => 'integer', 'width' => '90px', 'sortable' => true, 'empty_zero' => true, 'aggregate' => 'SUM', 'header_tip' => 'Opt-ins credited to the page the visit STARTED on. The push prompt waits for about a minute of engagement, so it usually appears on a different page.', ), array( 'key' => 'lq', 'label' => 'Requests', 'type' => 'integer', 'width' => '110px', 'sortable' => true, 'empty_zero' => true, 'aggregate' => 'SUM', 'header_tip' => 'Quote requests and back-in-stock requests, credited to the page the visit STARTED on. On a catalogue site this is the conversion column: demand a page created that no order will ever show you.', ), array( 'key' => 'g', 'label' => 'Goals', 'type' => 'integer', 'hidden' => true, ), ), ), array( 'id' => 'landing_income_zeroes', 'label' => 'Organic traffic, no cart adds', 'description' => '', 'source' => 'rows', 'rows' => 'aieo_landing_income_zeroes_rows', 'registry_id' => 'landing_income.organic_traffic_that_produces_not', 'scope' => 'both', 'version' => '1', 'per_page' => 25, 'params' => $aieo_landing_params, 'row_key' => 'landing_path', 'default_sort' => array( 's', 'desc' ), 'empty_state' => 'None — every page with real organic traffic produced at least one cart add.', 'columns' => array( $aieo_landing_page_column, array( 'key' => 'landing_path', 'label' => 'Path', 'type' => 'code', 'hidden' => true, ), array( 'key' => 'url', 'label' => 'URL', 'type' => 'link', 'hidden' => true, ), array( 'key' => 'title', 'label' => 'Title', 'type' => 'text', 'hidden' => true, ), array( 'key' => 's', 'label' => 'Organic sessions', 'type' => 'integer', 'width' => '140px', 'sortable' => true, 'filter' => 'number_range', 'aggregate' => 'SUM', ), array( 'key' => 'e', 'label' => 'Engaged', 'type' => 'integer', 'width' => '110px', 'sortable' => true, 'aggregate' => 'SUM', ), array( 'key' => 'c', 'label' => 'Cart adds', 'type' => 'integer', 'width' => '100px', 'sortable' => false, 'bands' => array( array( 'min' => 0, 'max' => 0, 'tone' => 'warning' ) ), ), ), ), );