-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflurry_status_board.php
86 lines (71 loc) · 2.89 KB
/
flurry_status_board.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
<?php
##################################################################
# Configuration Begin
# The README has more instructions on how to use this script
# Flurry API: http://support.flurry.com/index.php?title=API
##################################################################
$apiAccessCode = ""; # Your Flurry API access code. See API url above.
$apiKey = ""; # Flurry API Key for the app you want to track. See API url above.
$daysToShow = 7; # Number of days you want to view
$graphTitle = ""; # The title for the graph
$graphType = "line"; # Set to 'line' or 'bar'
$hideTotals = false; # Set to true if you want to hide totals on the y-axis, false otherwise
$displayTotal = false; # Set to true if you want the totals for each metric listed at the end of the graph.
$dateFormat = "M j"; # Date format for x-axis. Default format is "Apr 20". See http://php.net/manual/en/function.date.php
# This array comtains a hash for each Flurry metric you want to track.
# See http://support.flurry.com/index.php?title=API/Code for other metrics.
$metrics = array(
array(
'metric' => 'ActiveUsers',
'title' => 'Daily Active Users',
'color' => 'green'
),
array(
'metric' => 'NewUsers',
'title' => 'Daily New Users',
'color' => 'blue'
)
);
##################################################################
# Configuration Ends
##################################################################
$endDate = date("Y-m-d", time() - 60 * 60 * 24);
$startDate = date("Y-m-d", time() - 60 * 60 * 24 * $daysToShow);
$dataSequences = array();
foreach ($metrics as $metric) {
$metricMethod = $metric['metric'];
$url = "http://api.flurry.com/appMetrics/$metricMethod?apiAccessCode=$apiAccessCode&apiKey=$apiKey&startDate=$startDate&endDate=$endDate";
$options = array(
'http' => array(
'header' => array(
'Accept: application/json',
),
),
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
$result = json_decode($result, true);
$days = $result['day'];
$data = array();
foreach ($days as $day) {
$dateString = date($dateFormat, strtotime($day['@date']));
$value = $day['@value'];
$data[] = array('title' => $dateString, 'value' => $value);
}
$dataSequences[] = array('title' => $metric['title'], 'color' => $metric['color'], 'datapoints' => $data);
// Sleep for a sec, since the Flurry API only allows one call per second
sleep(1);
}
$graph = array(
'graph' => array(
'title' => $graphTitle,
'type' => $graphType,
'total' => $displayTotal,
'yAxis' => array(
'hide' => $hideTotals
),
'datasequences' => $dataSequences,
),
);
echo json_encode($graph);
?>