1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Overview Report |
4
|
|
|
* |
5
|
|
|
* Ensures all of the reports have a uniform class with helper functions. |
6
|
|
|
* |
7
|
|
|
* @since 6.0.0 |
8
|
|
|
* |
9
|
|
|
* @package MonsterInsights |
10
|
|
|
* @subpackage Reports |
11
|
|
|
* @author Chris Christoff |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
// Exit if accessed directly |
15
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
16
|
|
|
exit; |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
final class MonsterInsights_Report_Overview extends MonsterInsights_Report { |
20
|
|
|
|
21
|
|
|
public $title; |
22
|
|
|
public $class = 'MonsterInsights_Report_Overview'; |
23
|
|
|
public $name = 'overview'; |
24
|
|
|
public $version = '1.0.0'; |
25
|
|
|
public $level = 'lite'; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Primary class constructor. |
29
|
|
|
* |
30
|
|
|
* @access public |
31
|
|
|
* @since 6.0.0 |
32
|
|
|
*/ |
33
|
|
|
public function __construct() { |
34
|
|
|
$this->title = __( 'Overview', 'google-analytics-for-wordpress' ); |
35
|
|
|
parent::__construct(); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Prepare report-specific data for output. |
40
|
|
|
* |
41
|
|
|
* @param array $data The data from the report before it gets sent to the frontend. |
42
|
|
|
* |
43
|
|
|
* @return mixed |
44
|
|
|
*/ |
45
|
|
|
public function prepare_report_data( $data ) { |
46
|
|
|
// Add flags to the countries report. |
47
|
|
|
if ( ! empty( $data['data']['countries'] ) ) { |
48
|
|
|
$country_names = monsterinsights_get_country_list( true ); |
49
|
|
|
foreach ( $data['data']['countries'] as $key => $country ) { |
50
|
|
|
$data['data']['countries'][ $key ]['name'] = isset( $country_names[ $country['iso'] ] ) ? $country_names[ $country['iso'] ] : $country['iso']; |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
// Escape urls for the top pages report. |
55
|
|
|
if ( ! empty( $data['data']['toppages'] ) ) { |
56
|
|
|
foreach ( $data['data']['toppages'] as $key => $page ) { |
57
|
|
|
$title = $data['data']['toppages'][ $key ]['title']; |
58
|
|
|
$url = '(not set)' === $title ? '' : esc_url( $data['data']['toppages'][ $key ]['hostname'] ); |
59
|
|
|
|
60
|
|
|
$data['data']['toppages'][ $key ]['hostname'] = $url; |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
// Bounce rate add symbol. |
65
|
|
|
if ( ! empty( $data['data']['infobox']['bounce']['value'] ) ) { |
66
|
|
|
$data['data']['infobox']['bounce']['value'] .= '%'; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
// Add GA links. |
70
|
|
|
if ( ! empty( $data['data'] ) ) { |
71
|
|
|
$data['data']['galinks'] = array( |
72
|
|
|
'countries' => 'https://analytics.google.com/analytics/web/#report/visitors-geo/' . MonsterInsights()->auth->get_referral_url() . $this->get_ga_report_range( $data['data'] ), |
|
|
|
|
73
|
|
|
'referrals' => 'https://analytics.google.com/analytics/web/#report/trafficsources-referrals/' . MonsterInsights()->auth->get_referral_url() . $this->get_ga_report_range( $data['data'] ), |
74
|
|
|
'topposts' => 'https://analytics.google.com/analytics/web/#/report/content-pages/' . MonsterInsights()->auth->get_referral_url() . $this->get_ga_report_range( $data['data'] ), |
75
|
|
|
); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
return $data; |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|