';
AIFLT_UI::empty_state('store', __('WooCommerce is needed', 'ai-flash-tune'), __('The funnel follows shoppers through your WooCommerce store. Activate WooCommerce to start.', 'ai-flash-tune'), '' . esc_html($aiflt_wc['button_text']) . '');
echo '';
return;
}
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only filter.
$aiflt_device = isset($_GET['device']) ? sanitize_key(wp_unslash($_GET['device'])) : 'all';
$aiflt_device = in_array($aiflt_device, ['all', 'desktop', 'mobile'], true) ? $aiflt_device : 'all';
// Side-by-side comparison is an AI Flash Tune Pro feature (it turns this filter on).
$aiflt_can_compare = (bool) apply_filters('aiflt_funnel_compare_enabled', true);
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only filter.
$aiflt_compare = isset($_GET['compare']) ? sanitize_key(wp_unslash($_GET['compare'])) : '';
$aiflt_compare = ($aiflt_can_compare && in_array($aiflt_compare, ['device', 'customer', 'source'], true)) ? $aiflt_compare : '';
if ($aiflt_compare !== '') {
$aiflt_device = 'all';
}
$aiflt_period = AIFLT_UI::period(30);
$aiflt_funnel = AIFLT_Funnel_Analyzer_Logic::get_funnel_data($aiflt_device, $aiflt_period['start'], $aiflt_period['end']);
// The same length of time just before, for the change figures.
$aiflt_prev_end = wp_date('Y-m-d', strtotime($aiflt_period['start'] . ' -1 day'));
$aiflt_prev_start = wp_date('Y-m-d', strtotime($aiflt_prev_end . ' -' . ($aiflt_period['days'] - 1) . ' days'));
$aiflt_prev = AIFLT_Funnel_Analyzer_Logic::get_funnel_data($aiflt_device, $aiflt_prev_start, $aiflt_prev_end);
$aiflt_has_prev = empty($aiflt_prev['is_empty']) && (int) ($aiflt_prev['total_sessions'] ?? 0) > 0;
$aiflt_change = static function ($key) use ($aiflt_funnel, $aiflt_prev, $aiflt_has_prev) {
$before = (float) ($aiflt_prev[$key] ?? 0);
return ($aiflt_has_prev && $before > 0) ? ((float) ($aiflt_funnel[$key] ?? 0) - $before) / $before * 100 : null;
};
$aiflt_has_data = empty($aiflt_funnel['is_empty']) && (int) ($aiflt_funnel['total_sessions'] ?? 0) > 0;
$aiflt_keep = ['page' => 'aiflt-funnel', 'device' => $aiflt_device, 'compare' => $aiflt_compare];
if ($aiflt_period['range'] === 'custom') {
$aiflt_keep += ['range' => 'custom', 'start_date' => $aiflt_period['start'], 'end_date' => $aiflt_period['end']];
} else {
$aiflt_keep['range'] = $aiflt_period['range'];
}
$aiflt_toolbar_right = '';
if ($aiflt_compare === '') {
$aiflt_toolbar_right .= AIFLT_UI::segmented(
['all' => __('All devices', 'ai-flash-tune'), 'desktop' => __('Desktop', 'ai-flash-tune'), 'mobile' => __('Mobile', 'ai-flash-tune')],
$aiflt_device,
'device',
array_diff_key($aiflt_keep, ['device' => 1]),
__('Device', 'ai-flash-tune')
);
}
if ($aiflt_can_compare) {
$aiflt_toolbar_right .= '' . AIFLT_UI::segmented(
['' => __('Off', 'ai-flash-tune'), 'device' => __('Devices', 'ai-flash-tune'), 'customer' => __('Customer type', 'ai-flash-tune'), 'source' => __('AI assistants', 'ai-flash-tune')],
$aiflt_compare,
'compare',
array_diff_key($aiflt_keep, ['compare' => 1, 'device' => 1]),
__('Compare', 'ai-flash-tune')
);
} else {
$aiflt_toolbar_right .= '' . AIFLT_UI::icon('lock') . esc_html__('Compare', 'ai-flash-tune') . '';
}
AIFLT_UI::period_toolbar(
$aiflt_period,
array_diff_key($aiflt_keep, ['range' => 1, 'start_date' => 1, 'end_date' => 1]),
$aiflt_toolbar_right
);
if (!$aiflt_has_data) {
echo '
' . esc_html__('Biggest difference:', 'ai-flash-tune') . ' '; printf( /* translators: 1: step name, 2: first group, 3: its percentage, 4: second group, 5: its percentage */ esc_html__('%1$s: %2$s keep %3$s, %4$s keep %5$s.', 'ai-flash-tune'), esc_html($aiflt_side_steps[0][1][$aiflt_diff[0]][0]), esc_html($aiflt_side_steps[0][0]), '' . esc_html(number_format_i18n($aiflt_diff[1], 0)) . '%', esc_html(mb_strtolower($aiflt_side_steps[1][0])), '' . esc_html(number_format_i18n($aiflt_diff[2], 0)) . '%' ); ?>
' . esc_html__('Biggest drop:', 'ai-flash-tune') . ' '; printf( esc_html($aiflt_drop_sentences[$aiflt_worst[0]]), '' . esc_html(number_format_i18n($aiflt_worst[1] * 100, 0)) . '%', esc_html(number_format_i18n($aiflt_worst[2])) ); ?>