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

MonsterInsights_Notification_Traffic_Dropping   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 the number of total sessions is less than the previous 30 days.
5
 * Recurrence: 30 Days
6
 *
7
 * @since 7.12.3
8
 */
9
final class MonsterInsights_Notification_Traffic_Dropping extends MonsterInsights_Notification_Event {
10
11
	public $notification_id             = 'monsterinsights_notification_traffic_dropping';
12
	public $notification_interval       = 30; // 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();
25
		$data['prev_sessions_difference'] = isset( $report['data']['infobox']['sessions']['prev'] ) ? $report['data']['infobox']['sessions']['prev'] : 0;
26
27
		if ( ! empty( $data ) && $data['prev_sessions_difference'] < 0 ) {
28
			$notification['title']   = __( 'Your Website Traffic Is Dropping', 'google-analytics-for-wordpress' );
29
			// Translators: Traffic dropping notification content
30
			$notification['content'] = sprintf( __( 'Your website traffic is decreasing and that’s a reason to take action now. Less traffic means less opportunities to make your brand known, make relationships and ultimately sell your service or product. <br><br>Follow the marketing hacks of %sthis article%s to start growing your traffic again.', 'google-analytics-for-wordpress' ), '<a href="'. $this->build_external_link( 'https://www.monsterinsights.com/marketing-hacks-guaranteed-to-grow-your-traffic/' ) .'" target="_blank">', '</a>' );
31
			$notification['btns']    = array(
32
				"learn_more"  => array(
33
					'url'  => $this->build_external_link( 'https://www.monsterinsights.com/marketing-hacks-guaranteed-to-grow-your-traffic/' ),
34
					'text' => __( 'Learn More', 'google-analytics-for-wordpress' )
35
				),
36
				"view_report" => array(
37
					'url'  => $this->get_view_url(),
38
					'text' => __( 'View Report', '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_Traffic_Dropping();
52