← All changes
|
includes/seo/email-report-sections/class-position-summary-section.php
+40
-15
2.11.0
→
2.14.1
View file →
| @@ -3,9 +3,10 @@ | ||
| 3 | 3 | * Position Summary Section — "Where your keywords rank". |
| 4 | 4 | * |
| 5 | 5 | * Buckets the period's queries into Top 3 / 4–10 / 11–50 / 51–100 and draws |
| 6 | 6 | * them as bars. Source: GSC `position_distribution` already computed by |
| 7 | - * Analytics_Manager. | |
| 7 | + * Analytics_Manager over the whole property (#913), with queries ranked | |
| 8 | + * past 100 in `over_100`. | |
| 8 | 9 | * |
| 9 | 10 | * @package ThinkRank |
| 10 | 11 | * @subpackage SEO\Email_Report_Sections |
| 11 | 12 | * @since 1.9.0 |
| @@ -50,17 +51,22 @@ | ||
| 50 | 51 | if (!is_array($dist) || empty($dist)) { |
| 51 | 52 | return []; |
| 52 | 53 | } |
| 53 | 54 | return [ |
| 54 | - 'top_3' => (int) ($dist['top_3'] ?? 0), | |
| 55 | - '4_10' => (int) ($dist['4_10'] ?? 0), | |
| 56 | - '11_50' => (int) ($dist['10_50'] ?? 0), // GSC's `10_50` bucket starts at 11 | |
| 57 | - '51_100' => (int) ($dist['51_100'] ?? 0), | |
| 55 | + 'top_3' => (int) ($dist['top_3'] ?? 0), | |
| 56 | + '4_10' => (int) ($dist['4_10'] ?? 0), | |
| 57 | + '11_50' => (int) ($dist['10_50'] ?? 0), // GSC's `10_50` bucket starts at 11 | |
| 58 | + '51_100' => (int) ($dist['51_100'] ?? 0), | |
| 59 | + // Counted over the whole property since #913. A payload cached | |
| 60 | + // before then has neither key and reads as before. | |
| 61 | + 'over_100' => (int) ($dist['over_100'] ?? 0), | |
| 62 | + 'complete' => (bool) ($dist['complete'] ?? true), | |
| 58 | 63 | ]; |
| 59 | 64 | } |
| 60 | 65 | |
| 61 | 66 | public function has_data(array $payload): bool { |
| 62 | - return array_sum(array_map('intval', $payload)) > 0; | |
| 67 | + $counts = array_intersect_key($payload, array_flip(['top_3', '4_10', '11_50', '51_100', 'over_100'])); | |
| 68 | + return array_sum(array_map('intval', $counts)) > 0; | |
| 63 | 69 | } |
| 64 | 70 | |
| 65 | 71 | public function render(array $payload): string { |
| 66 | 72 | $counts = [ |
| @@ -68,28 +74,47 @@ | ||
| 68 | 74 | '4_10' => (int) ($payload['4_10'] ?? 0), |
| 69 | 75 | '11_50' => (int) ($payload['11_50'] ?? 0), |
| 70 | 76 | '51_100' => (int) ($payload['51_100'] ?? 0), |
| 71 | 77 | ]; |
| 72 | - $total = array_sum($counts); | |
| 78 | + // The bars share out the top 100; queries ranked past it still had | |
| 79 | + // an impression, so they count toward the headline total (#913). | |
| 80 | + $ranked = array_sum($counts); | |
| 81 | + $over_100 = max(0, (int) ($payload['over_100'] ?? 0)); | |
| 82 | + $total = $ranked + $over_100; | |
| 73 | 83 | if ($total === 0) { |
| 74 | 84 | return ''; |
| 75 | 85 | } |
| 76 | 86 | $page_one = $counts['top_3'] + $counts['4_10']; |
| 77 | 87 | |
| 78 | - $html = Email_Report_Html::heading( | |
| 79 | - $this->label(), | |
| 80 | - sprintf( | |
| 88 | + // Incomplete means Search Console could not be paged to the end, so | |
| 89 | + // the count covers the top of the property by clicks, not all of it. | |
| 90 | + $subtitle = (bool) ($payload['complete'] ?? true) | |
| 91 | + ? sprintf( | |
| 81 | 92 | /* translators: %s: number of queries. */ |
| 82 | 93 | _n('%s query got at least one impression this period', '%s queries got at least one impression this period', $total, 'thinkrank'), |
| 83 | 94 | number_format_i18n($total) |
| 84 | 95 | ) |
| 85 | - ); | |
| 96 | + : sprintf( | |
| 97 | + /* translators: %s: number of queries counted. */ | |
| 98 | + _n('Counted over your top %s query by clicks this period', 'Counted over your top %s queries by clicks this period', $total, 'thinkrank'), | |
| 99 | + number_format_i18n($total) | |
| 100 | + ); | |
| 101 | + | |
| 102 | + $html = Email_Report_Html::heading($this->label(), $subtitle); | |
| 86 | 103 | $html .= '<table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="margin-top:14px;">' |
| 87 | - . Email_Report_Html::bar_row(__('Top 3', 'thinkrank'), $counts['top_3'], $total, Email_Report_Html::PRIMARY) | |
| 88 | - . Email_Report_Html::bar_row(__('Positions 4–10', 'thinkrank'), $counts['4_10'], $total, '#6e79ff') | |
| 89 | - . Email_Report_Html::bar_row(__('Positions 11–50', 'thinkrank'), $counts['11_50'], $total, '#b3b9ff') | |
| 90 | - . Email_Report_Html::bar_row(__('Positions 51–100', 'thinkrank'), $counts['51_100'], $total, '#dcdfff') | |
| 104 | + . Email_Report_Html::bar_row(__('Top 3', 'thinkrank'), $counts['top_3'], $ranked, Email_Report_Html::PRIMARY) | |
| 105 | + . Email_Report_Html::bar_row(__('Positions 4–10', 'thinkrank'), $counts['4_10'], $ranked, '#6e79ff') | |
| 106 | + . Email_Report_Html::bar_row(__('Positions 11–50', 'thinkrank'), $counts['11_50'], $ranked, '#b3b9ff') | |
| 107 | + . Email_Report_Html::bar_row(__('Positions 51–100', 'thinkrank'), $counts['51_100'], $ranked, '#dcdfff') | |
| 91 | 108 | . '</table>'; |
| 109 | + if ($over_100 > 0) { | |
| 110 | + $html .= Email_Report_Html::note(sprintf( | |
| 111 | + /* translators: 1: queries ranking in the top 100, 2: queries ranking beyond position 100. */ | |
| 112 | + _n('%1$s rank in the top 100 and %2$s ranks beyond position 100.', '%1$s rank in the top 100 and %2$s rank beyond position 100.', $over_100, 'thinkrank'), | |
| 113 | + number_format_i18n($ranked), | |
| 114 | + number_format_i18n($over_100) | |
| 115 | + )); | |
| 116 | + } | |
| 92 | 117 | $html .= Email_Report_Html::note(sprintf( |
| 93 | 118 | /* translators: %s: number of queries ranking in positions 1–10. */ |
| 94 | 119 | _n('%s query is on page one.', '%s queries are on page one.', $page_one, 'thinkrank'), |
| 95 | 120 | number_format_i18n($page_one) |