|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Add notification when percentage of visitors from mobile device is less than 10% |
|
4
|
|
|
* Recurrence: 15 Days |
|
5
|
|
|
* |
|
6
|
|
|
* @since 7.12.3 |
|
7
|
|
|
*/ |
|
8
|
|
|
final class MonsterInsights_Notification_Mobile_Device extends MonsterInsights_Notification_Event { |
|
9
|
|
|
|
|
10
|
|
|
public $notification_id = 'monsterinsights_notification_mobile_device'; |
|
11
|
|
|
public $notification_interval = 15; // in days |
|
12
|
|
|
public $notification_type = array( 'basic', 'lite', 'master', 'plus', 'pro' ); |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Prepare Notification |
|
16
|
|
|
* |
|
17
|
|
|
* @return array $notification notification is ready to add |
|
18
|
|
|
* |
|
19
|
|
|
* @since 7.12.3 |
|
20
|
|
|
*/ |
|
21
|
|
|
public function prepare_notification_data( $notification ) { |
|
22
|
|
|
$data = array(); |
|
23
|
|
|
$report = $this->get_report( 'overview', $this->report_start_from, $this->report_end_to ); |
|
24
|
|
|
$data['percentage_of_mobile_visitors'] = isset( $report['data']['devices']['mobile'] ) ? $report['data']['devices']['mobile'] : 0; |
|
25
|
|
|
|
|
26
|
|
|
if ( ! empty( $data ) && $data['percentage_of_mobile_visitors'] < 10 ) { |
|
27
|
|
|
// Translators: Mobile device notification title |
|
28
|
|
|
$notification['title'] = sprintf( __( 'Traffic from Mobile Devices is %s%%', 'google-analytics-for-wordpress' ), $data['percentage_of_mobile_visitors'] ); |
|
29
|
|
|
// Translators: Mobile device notification content |
|
30
|
|
|
$notification['content'] = sprintf( __( 'Traffic from mobile devices is considerably lower on your site compared to desktop devices. This could be an indicator that your site is not optimised for mobile devices.<br><br>Take a look now at %show your site looks%s on mobile and make sure all your content can be accessed correctly.', 'google-analytics-for-wordpress' ), '<a href="'. $this->build_external_link( 'https://www.wpbeginner.com/beginners-guide/how-to-preview-the-mobile-layout-of-your-site/' ) .'">', '</a>' ); |
|
31
|
|
|
$notification['btns'] = array( |
|
32
|
|
|
"view_report" => array( |
|
33
|
|
|
'url' => $this->get_view_url(), |
|
34
|
|
|
'text' => __( 'View Report', 'google-analytics-for-wordpress' ) |
|
35
|
|
|
), |
|
36
|
|
|
"learn_more" => array( |
|
37
|
|
|
'url' => $this->build_external_link('https://www.wpbeginner.com/beginners-guide/how-to-preview-the-mobile-layout-of-your-site/' ), |
|
38
|
|
|
'text' => __( 'Learn More', 'google-analytics-for-wordpress' ) |
|
39
|
|
|
), |
|
40
|
|
|
); |
|
41
|
|
|
|
|
42
|
|
|
return $notification; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
return false; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
// initialize the class |
|
51
|
|
|
new MonsterInsights_Notification_Mobile_Device(); |
|
52
|
|
|
|