Passed
Push — master ( 6f0a6d...90a9ca )
by
unknown
09:41
created

MonsterInsights_Notification_Bounce_Rate   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
dl 0
loc 37
rs 10
c 1
b 0
f 0
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A prepare_notification_data() 0 24 4
1
<?php
2
3
/**
4
 * Add notification when bounce rate is higher than 70%
5
 * Recurrence: Once weekly
6
 *
7
 * @since 7.12.3
8
 */
9
final class MonsterInsights_Notification_Bounce_Rate extends MonsterInsights_Notification_Event {
10
11
	public $notification_id             = 'monsterinsights_notification_bounce_rate';
12
	public $notification_interval       = 7; // in days
13
	public $notification_type           = array( 'basic', 'lite', 'master', 'plus', 'pro' );
14
15
	/**
16
	 * Build Notification
17
	 *
18
	 * @return array $notification notification is ready to add
19
	 *
20
	 * @since 7.12.3
21
	 */
22
	public function prepare_notification_data( $notification ) {
23
		$data                = array();
24
		$report              = $this->get_report( 'overview', $this->report_start_from, $this->report_end_to );
25
		$data['bounce_rate'] = isset( $report['data']['infobox']['bounce']['value'] ) ? $report['data']['infobox']['bounce']['value'] : 0;
26
27
		if ( ! empty( $data ) && $data['bounce_rate'] > 70 ) {
28
			$notification['title']   = __( 'Your website bounce rate is higher than 70%', 'google-analytics-for-wordpress' );
29
			// Translators: Bounce rate notification content
30
			$notification['content'] = sprintf( __( 'Your website bounce rate is %s. High bounce rates can hurt your site’s conversions rates. A high bounce rate might mean that people aren’t finding what they’re looking for on your site. %sHere%s are some points to remember and steps to follow to get your bounce rates back to manageable levels.', 'google-analytics-for-wordpress' ), $data['bounce_rate'] . '%', '<a href="'. $this->build_external_link('https://www.monsterinsights.com/how-to-reduce-bounce-rate/' ) .'" target="_blank">', '</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.monsterinsights.com/how-to-reduce-bounce-rate/' ),
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_Bounce_Rate();
52