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