forked from wp-plugins/wpmandrill
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stats.php
275 lines (250 loc) · 12 KB
/
stats.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
<?php if (!current_user_can('manage_options')) wp_die( __('You do not have sufficient permissions to access this page.') ); ?>
<?php wpMandrill::getConnected(); ?>
<div class="wrap">
<div class="icon32" style="background: url('<?php echo plugins_url('images/mandrill-head-icon.png',__FILE__); ?>');"><br /></div>
<h2><?php _e('Mandrill Service Report', 'wpmandrill'); ?></h2><?php
$stats = self::getCurrentStats();
if ( empty($stats) ) {
echo '<p>' . __('There was a problem retrieving statistics.', 'wpmandrill') . '</p>';
echo '</div>';
return;
}
$delivered = $stats['general']['stats']['sent'] -
$stats['general']['stats']['hard_bounces'] -
$stats['general']['stats']['soft_bounces'] -
$stats['general']['stats']['rejects'];
$lit = array();
$lit['hourly']['title'] = __('Hourly Sending Volume and Open/Click Rate','wpmandrill');
$lit['hourly']['Xtitle'] = __('Hours','wpmandrill');
$lit['hourly']['tooltip'] = __('Hour','wpmandrill');
$lit['daily']['title'] = __('Daily Sending Volume and Open/Click Rate','wpmandrill');
$lit['daily']['Xtitle'] = __('Days','wpmandrill');
$lit['daily']['tooltip'] = __('Day','wpmandrill');
$lit['subtitle'] = __('in the last 30 days','wpmandrill');
$lit['Ytitle'] = __('Open & Click Rate','wpmandrill');
$lit['SerieName'] = __('Volume','wpmandrill');
$lit['emails'] = __('emails','wpmandrill');
$lit['openrate'] = __('Open Rate','wpmandrill');
$lit['clickrate'] = __('Click Rate','wpmandrill');
?>
<div id="alltime_report">
<h3><?php echo sprintf(__('All-time statistics since %s: ', 'wpmandrill'),date('m/d/Y',strtotime($stats['general']['created_at']))); ?></h3>
<div id="alltime_report_canvas">
<div class="stat_box"><?php _e('Reputation:', 'wpmandrill'); ?><br/><span><?php echo $stats['general']['reputation']?>%</span></div>
<div class="stat_box"><?php _e('Quota:', 'wpmandrill'); ?><br/><span><?php echo $stats['general']['hourly_quota']?> <?php _e('sends/hour', 'wpmandrill'); ?></span></div>
<div class="stat_box"><?php _e('Emails sent:', 'wpmandrill'); ?><br/><span><?php echo $stats['general']['stats']['sent']?></span></div>
<div class="stat_box"><?php _e('Emails delivered:', 'wpmandrill'); ?><br/><span><?php echo $delivered?> (<?php echo number_format( $delivered*100 / ( ($stats['general']['stats']['sent'])?$stats['general']['stats']['sent']:1 ) ,2); ?>%)</span></div>
<div class="stat_box"><?php _e('Tracked opens:', 'wpmandrill'); ?><br/><span><?php echo $stats['general']['stats']['opens']?></span></div>
<div class="stat_box"><?php _e('Tracked clicks:', 'wpmandrill'); ?><br/><span><?php echo $stats['general']['stats']['clicks']?></span></div>
<?php
if ( $stats['general']['stats']['rejects'] ) echo '<div class="stat_box warning">'.__('Rejects:', 'wpmandrill').'<br/><span>'.$stats['general']['stats']['rejects'].'</span></div>';
if ( $stats['general']['stats']['complaints'] ) echo '<div class="stat_box warning">'.__('Complaints:', 'wpmandrill').'<br/><span>'.$stats['general']['stats']['complaints'].'</span></div>';
if ( $stats['general']['backlog'] ) echo '<div class="stat_box warning">'.__('Current backlog:', 'wpmandrill').'<br/><span>'.$stats['general']['backlog'].' emails</span></div>';
?>
</div>
</div>
<div style="clear: both;"></div>
<div id="filtered_reports">
<h3><?php _e('Filtered statistics:', 'wpmandrill'); ?></h3>
<label for="filter"><?php _e('Filter by:', 'wpmandrill'); ?> </label>
<select id="filter" name="filter">
<option value="none" selected="selected" ><?php _e('No filter', 'wpmandrill'); ?></option>
<optgroup label="<?php _e('Sender:', 'wpmandrill'); ?>">
<?php
foreach ( array_keys($stats['stats']['hourly']['senders']) as $sender) {
echo '<option value="s:'.$sender.'">'.$sender.'</option>';
}
?>
</optgroup>
<optgroup label="<?php _e('Tag:', 'wpmandrill'); ?>">
<?php
if ( isset($stats['stats']['hourly']['tags']['detailed_stats'])
&& is_array($stats['stats']['hourly']['tags']['detailed_stats']) ) {
foreach ( array_keys($stats['stats']['hourly']['tags']['detailed_stats']) as $tag) {
echo '<option value="'.$tag.'">'.$tag.'</option>';
}
}
?>
</optgroup>
</select>
<label for="display"><?php _e('Display:', 'wpmandrill'); ?> </label>
<select id="display" name="display">
<option value="volume"><?php _e('Total Volume per Period', 'wpmandrill'); ?></option>
<option value="average"><?php _e('Average Volume per Period', 'wpmandrill'); ?></option>
</select><div id="ajax-icon-container"><span id="loading_data" class="hidden"></span></div>
<div id="filtered_reports_canvas">
<div id="filtered_recent" style="width: 50%;height: 300px; float: left;"></div>
<div id="filtered_oldest" style="width: 50%;height: 300px; float: left;"></div>
</div>
<div style="clear: both;"></div>
</div>
<br/><br/>
<div id="hourly_report"></div>
<script type="text/javascript">
function emailFormatter(v, axis) {
return v.toFixed(axis.tickDecimals) +" emails";
}
function percentageFormatter(v, axis) {
return v.toFixed(axis.tickDecimals) +"%";
}
function wpm_showTooltip(x, y, contents) {
jQuery('<div id="wpm_tooltip">' + contents + '</div>').css( {
position: 'absolute',
display: 'none',
top: y + 5,
left: x + 5,
border: '1px solid #fdd',
padding: '2px',
'background-color': '#fee',
opacity: 0.80
}).appendTo("body").fadeIn(200);
}
<?php
// hourly stats data
$hticks = array_keys($stats['graph']['hourly']['delivered']);
array_walk($hticks, 'wpMandrill_transformJSArray');
$hvolume = $stats['graph']['hourly']['delivered'];
$horate = $stats['graph']['hourly']['open_rate'];
$hcrate = $stats['graph']['hourly']['click_rate'];
array_walk($hvolume,'wpMandrill_transformJSArray');
array_walk($horate, 'wpMandrill_transformJSArray');
array_walk($hcrate, 'wpMandrill_transformJSArray');
// daily stats data
$dticks = array_keys($stats['graph']['daily']['delivered']);
array_walk($dticks, 'wpMandrill_transformJSArray');
$day_keys = array();
foreach(array_keys($stats['graph']['daily']['delivered']) as $day_index => $day_key) {
$day_keys[$day_index] = $day_key;
}
$dvolume = $stats['graph']['daily']['delivered'];
$dorate = $stats['graph']['daily']['open_rate'];
$dcrate = $stats['graph']['daily']['click_rate'];
array_walk($dvolume,'wpMandrill_transformJSArray', array(1, $day_keys));
array_walk($dorate, 'wpMandrill_transformJSArray', array(1, $day_keys));
array_walk($dcrate, 'wpMandrill_transformJSArray', array(1, $day_keys));
?>
var hvolume = [<?php echo implode(',',$hvolume);?>];
var hopenrates = [<?php echo implode(',',$horate);?>];
var hclickrates = [<?php echo implode(',',$hcrate);?>]
var dvolume = [<?php echo implode(',',$dvolume);?>];
var dopenrates = [<?php echo implode(',',$dorate);?>];
var dclickrates = [<?php echo implode(',',$dcrate);?>]
var dticks = [<?php echo implode(',',array_keys($stats['graph']['daily']['delivered']));?>]
jQuery(function () {
var previousPoint = null;
jQuery("#hourly_report_canvas").bind("plothover", function (event, pos, item) {
if (item) {
if (previousPoint != item.dataIndex) {
previousPoint = item.dataIndex;
jQuery("#wpm_tooltip").remove();
var x = item.datapoint[0].toFixed(0);
if ( item.seriesIndex == 0 ) {
var y = item.datapoint[1].toFixed(0);
wpm_showTooltip(item.pageX, item.pageY, item.series.label + " (at hour " + x + ") = " + y + " emails");
} else {
var y = item.datapoint[1].toFixed(2);
wpm_showTooltip(item.pageX, item.pageY, item.series.label + " (at hour " + x + ") = " + y + "%");
}
}
}
else {
jQuery("#wpm_tooltip").remove();
previousPoint = null;
}
});
jQuery("#daily_report_canvas").bind("plothover", function (event, pos, item) {
if (item) {
if (previousPoint != item.dataIndex) {
previousPoint = item.dataIndex;
jQuery("#wpm_tooltip").remove();
var x = dticks[item.dataIndex];
if ( item.seriesIndex == 0 ) {
var y = item.datapoint[1].toFixed(0);
wpm_showTooltip(item.pageX, item.pageY, "Day " + x + ": " + y + " emails");
} else {
var y = item.datapoint[1].toFixed(2);
wpm_showTooltip(item.pageX, item.pageY, item.series.label + " for " + x + ": " + y + "%");
}
}
}
else {
jQuery("#wpm_tooltip").remove();
previousPoint = null;
}
});
jQuery.plot(jQuery("#hourly_report_canvas"),
[ { data: hvolume, label: "Volume", yaxis: 2, bars: {show: true, barWidth: 0.6, align: "center"}, lines: { show: true }},
{ data: hopenrates, label: "Open Rate" },
{ data: hclickrates, label: "Click Rate" }],
{
series: {
points: { show: true },
lines: { show: true },
shadowSize: 7
},
grid: {
hoverable: true,
aboveData: true,
borderWidth: 0,
minBorderMargin: 10,
margin: {
top: 10,
left: 10,
bottom: 15,
right: 100
}
},
xaxes: [ { ticks: [<?php echo implode(',',$hticks);?>] } ],
yaxes: [ { min: 0, tickFormatter: percentageFormatter },
{
min: 0,
alignTicksWithAxis: 1, //1=right, null=left
position: 'sw',
tickFormatter: emailFormatter
} ],
legend: { position: 'ne', margin: [20, 10]}
});
jQuery.plot(jQuery("#daily_report_canvas"),
[ { data: dvolume, label: "Volume", yaxis: 2, bars: {show: true, barWidth: 0.6, align: "center"}, lines: { show: true }},
{ data: dopenrates, label: "Open Rate" },
{ data: dclickrates, label: "Click Rate" }],
{
series: {
points: { show: true },
lines: { show: true },
shadowSize: 7
},
grid: {
hoverable: true,
aboveData: true,
borderWidth: 0,
minBorderMargin: 10,
margin: {
top: 10,
left: 10,
bottom: 15,
right: 10
}
},
xaxes: [ { ticks: [<?php echo implode(',', $dticks);?>] } ],
yaxes: [ { min: 0, tickFormatter: percentageFormatter },
{
min: 0,
alignTicksWithAxis: 1, //1=right, null=left
position: 'sw',
tickFormatter: emailFormatter
} ],
legend: { position: 'ne', margin: [20, 10]}
});
});
</script>
<h3><?php echo $lit['hourly']['title']; ?></h3>
<h4><?php echo $lit['subtitle']; ?></h4>
<div id="hourly_report_canvas" style="height: 400px;"></div><br/><br/>
<h3><?php echo $lit['daily']['title']; ?></h3>
<h4><?php echo $lit['subtitle']; ?></h4>
<div id="daily_report_canvas" style="height: 400px;"></div>
<h3><a href="http://mandrillapp.com/" target="_target"><?php _e('For more detailed statistics, please visit your Mandrill Dashboard','wpmandrill'); ?></a>.</h3>
<?php
wpMandrill::$stats = $stats;
?>