Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
98.21% |
165 / 168 |
|
80.00% |
4 / 5 |
CRAP | n/a |
0 / 0 |
|
| Automattic\Jetpack\PremiumAnalytics\get_author_single_report_page_default_layout | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
1 | |||
| Automattic\Jetpack\PremiumAnalytics\get_post_traffic_single_report_section_default_layout | |
100.00% |
18 / 18 |
|
100.00% |
1 / 1 |
1 | |||
| Automattic\Jetpack\PremiumAnalytics\get_email_opens_single_report_section_default_layout | |
100.00% |
37 / 37 |
|
100.00% |
1 / 1 |
1 | |||
| Automattic\Jetpack\PremiumAnalytics\get_email_clicks_single_report_section_default_layout | |
100.00% |
49 / 49 |
|
100.00% |
1 / 1 |
1 | |||
| Automattic\Jetpack\PremiumAnalytics\register_default_single_report_pages | |
98.18% |
54 / 55 |
|
0.00% |
0 / 1 |
4 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * The package's own single-report pages, registered through the single-report page API. |
| 4 | * |
| 5 | * @package automattic/jetpack-premium-analytics |
| 6 | */ |
| 7 | |
| 8 | namespace Automattic\Jetpack\PremiumAnalytics; |
| 9 | |
| 10 | require_once __DIR__ . '/single-report-pages.php'; |
| 11 | |
| 12 | /** |
| 13 | * The author page's fixed composition: performance, the scoped spotlights, top posts, all-time traffic. |
| 14 | * |
| 15 | * @return array |
| 16 | */ |
| 17 | function get_author_single_report_page_default_layout() { |
| 18 | return array( |
| 19 | get_dashboard_default_widget_instance( 'author-performance', 'jpa/author-performance', 1, 3, 2, array( 'chartType' => 'bar' ) ), |
| 20 | get_dashboard_default_widget_instance( 'author-popular-post', 'jpa/popular-post--author', 2, 2, 2, array( 'authorScoped' => true ) ), |
| 21 | get_dashboard_default_widget_instance( 'author-latest-post', 'jpa/latest-post--author', 3, 1, 2, array( 'authorScoped' => true ) ), |
| 22 | get_dashboard_default_widget_instance( 'author-top-posts', 'jpa/author-top-posts', 4, 3, 2 ), |
| 23 | get_dashboard_default_widget_instance( 'author-all-time-traffic', 'jpa/views-over-years--author', 5, 3, 2, array( 'authorScoped' => true ) ), |
| 24 | ); |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * The Post traffic section of the post page: highlights, views, likes, comments, UTM, all-time traffic. |
| 29 | * |
| 30 | * @return array |
| 31 | */ |
| 32 | function get_post_traffic_single_report_section_default_layout() { |
| 33 | return array( |
| 34 | get_dashboard_default_widget_instance( 'post-detail-highlights', 'jpa/post-detail-highlights', 1, 3, 1 ), |
| 35 | get_dashboard_default_widget_instance( 'post-views', 'jpa/post-views', 2, 3, 2, array( 'chartType' => 'bar' ) ), |
| 36 | get_dashboard_default_widget_instance( 'post-likes', 'jpa/post-likes', 3, 1, 2 ), |
| 37 | get_dashboard_default_widget_instance( 'post-comments', 'jpa/post-comments', 4, 1, 2 ), |
| 38 | // No "View all" or "Download CSV": the site-wide UTM report would drop this post's scope. |
| 39 | get_dashboard_default_widget_instance( |
| 40 | 'post-utm', |
| 41 | 'jpa/utm-insights--utm', |
| 42 | 5, |
| 43 | 1, |
| 44 | 2, |
| 45 | array( |
| 46 | 'utmDimension' => 'utm_source,utm_medium', |
| 47 | 'showReportLink' => false, |
| 48 | ) |
| 49 | ), |
| 50 | get_dashboard_default_widget_instance( 'post-all-time-traffic', 'jpa/post-all-time-traffic', 6, 3, 2 ), |
| 51 | ); |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * The Email opens section of the post page. |
| 56 | * |
| 57 | * @return array |
| 58 | */ |
| 59 | function get_email_opens_single_report_section_default_layout() { |
| 60 | return array( |
| 61 | get_dashboard_default_widget_instance( 'email-opens-highlights', 'jpa/email-top-row', 1, 3, 1, array( 'metric' => 'opens' ) ), |
| 62 | get_dashboard_default_widget_instance( 'email-opens-trend', 'jpa/email-time-series--total-opens', 2, 3, 2, array( 'metric' => 'opens' ) ), |
| 63 | get_dashboard_default_widget_instance( |
| 64 | 'email-opens-countries', |
| 65 | 'jpa/email-breakdown--location-opens', |
| 66 | 3, |
| 67 | 1, |
| 68 | 2, |
| 69 | array( |
| 70 | 'view' => 'countries', |
| 71 | 'metric' => 'opens', |
| 72 | ) |
| 73 | ), |
| 74 | get_dashboard_default_widget_instance( |
| 75 | 'email-opens-devices', |
| 76 | 'jpa/email-breakdown--platforms-opens', |
| 77 | 4, |
| 78 | 1, |
| 79 | 2, |
| 80 | array( |
| 81 | 'view' => 'devices', |
| 82 | 'metric' => 'opens', |
| 83 | ) |
| 84 | ), |
| 85 | get_dashboard_default_widget_instance( |
| 86 | 'email-opens-clients', |
| 87 | 'jpa/email-breakdown--clients-opens', |
| 88 | 5, |
| 89 | 1, |
| 90 | 2, |
| 91 | array( |
| 92 | 'view' => 'clients', |
| 93 | 'metric' => 'opens', |
| 94 | ) |
| 95 | ), |
| 96 | ); |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * The Email clicks section of the post page. |
| 101 | * |
| 102 | * @return array |
| 103 | */ |
| 104 | function get_email_clicks_single_report_section_default_layout() { |
| 105 | return array( |
| 106 | get_dashboard_default_widget_instance( 'email-clicks-highlights', 'jpa/email-top-row', 1, 3, 1, array( 'metric' => 'clicks' ) ), |
| 107 | get_dashboard_default_widget_instance( 'email-clicks-trend', 'jpa/email-time-series--total-clicks', 2, 3, 2, array( 'metric' => 'clicks' ) ), |
| 108 | // Width 2: the map unmounts below a 720px container floor. |
| 109 | get_dashboard_default_widget_instance( |
| 110 | 'email-clicks-countries', |
| 111 | 'jpa/email-breakdown--location-clicks', |
| 112 | 3, |
| 113 | 2, |
| 114 | 2, |
| 115 | array( |
| 116 | 'view' => 'countries', |
| 117 | 'metric' => 'clicks', |
| 118 | 'showMap' => true, |
| 119 | ) |
| 120 | ), |
| 121 | get_dashboard_default_widget_instance( |
| 122 | 'email-clicks-devices', |
| 123 | 'jpa/email-breakdown--platforms-clicks', |
| 124 | 4, |
| 125 | 1, |
| 126 | 2, |
| 127 | array( |
| 128 | 'view' => 'devices', |
| 129 | 'metric' => 'clicks', |
| 130 | ) |
| 131 | ), |
| 132 | get_dashboard_default_widget_instance( |
| 133 | 'email-clicks-clients', |
| 134 | 'jpa/email-breakdown--clients-clicks', |
| 135 | 5, |
| 136 | 1, |
| 137 | 2, |
| 138 | array( |
| 139 | 'view' => 'clients', |
| 140 | 'metric' => 'clicks', |
| 141 | ) |
| 142 | ), |
| 143 | get_dashboard_default_widget_instance( |
| 144 | 'email-clicks-links', |
| 145 | 'jpa/email-breakdown--top-links', |
| 146 | 6, |
| 147 | 2, |
| 148 | 2, |
| 149 | array( |
| 150 | 'view' => 'links', |
| 151 | 'metric' => 'clicks', |
| 152 | ) |
| 153 | ), |
| 154 | ); |
| 155 | } |
| 156 | |
| 157 | /** |
| 158 | * Registers the package's own single-report pages into the registry being hydrated. |
| 159 | * |
| 160 | * @param Single_Report_Page_Registry|null $registry The registry the action hands over. |
| 161 | */ |
| 162 | function register_default_single_report_pages( $registry = null ) { |
| 163 | if ( ! $registry instanceof Single_Report_Page_Registry ) { |
| 164 | $registry = Single_Report_Page_Registry::get_instance(); |
| 165 | } |
| 166 | |
| 167 | $post_sections = array( |
| 168 | array( |
| 169 | 'slug' => 'post-traffic', |
| 170 | 'label' => __( 'Post traffic', 'jetpack-premium-analytics-pkg' ), |
| 171 | 'default_layout' => __NAMESPACE__ . '\\get_post_traffic_single_report_section_default_layout', |
| 172 | ), |
| 173 | array( |
| 174 | 'slug' => 'email-opens', |
| 175 | 'label' => __( 'Email opens', 'jetpack-premium-analytics-pkg' ), |
| 176 | 'default_layout' => __NAMESPACE__ . '\\get_email_opens_single_report_section_default_layout', |
| 177 | 'controls' => false, |
| 178 | ), |
| 179 | array( |
| 180 | 'slug' => 'email-clicks', |
| 181 | 'label' => __( 'Email clicks', 'jetpack-premium-analytics-pkg' ), |
| 182 | 'default_layout' => __NAMESPACE__ . '\\get_email_clicks_single_report_section_default_layout', |
| 183 | 'controls' => false, |
| 184 | ), |
| 185 | ); |
| 186 | |
| 187 | $pages = array( |
| 188 | 'analytics/author' => array( |
| 189 | 'path' => 'author', |
| 190 | 'label' => __( 'Author', 'jetpack-premium-analytics-pkg' ), |
| 191 | 'dashboard_section' => 'traffic', |
| 192 | 'feature' => 'authors', |
| 193 | 'scope_param' => 'author_id', |
| 194 | 'icon' => 'jpa/post-author', |
| 195 | 'reports_page' => 'authors', |
| 196 | 'default_layout' => __NAMESPACE__ . '\\get_author_single_report_page_default_layout', |
| 197 | 'preferences_scope' => 'jetpack-premium-analytics/author-detail', |
| 198 | ), |
| 199 | 'analytics/post' => array( |
| 200 | 'entity' => array( |
| 201 | 'kind' => 'postType', |
| 202 | 'name' => 'post', |
| 203 | ), |
| 204 | 'dashboard_section' => 'traffic', |
| 205 | 'icon' => 'jpa/post', |
| 206 | 'sections' => $post_sections, |
| 207 | ), |
| 208 | 'analytics/page' => array( |
| 209 | 'entity' => array( |
| 210 | 'kind' => 'postType', |
| 211 | 'name' => 'page', |
| 212 | ), |
| 213 | 'dashboard_section' => 'traffic', |
| 214 | 'icon' => 'jpa/page', |
| 215 | 'sections' => $post_sections, |
| 216 | ), |
| 217 | ); |
| 218 | |
| 219 | foreach ( $pages as $id => $args ) { |
| 220 | if ( ! $registry->is_registered( DASHBOARD_NAME, $id ) ) { |
| 221 | $registry->register( DASHBOARD_NAME, $id, $args ); |
| 222 | } |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | add_action( Single_Report_Page_Registry::REGISTER_ACTION, __NAMESPACE__ . '\\register_default_single_report_pages' ); |