-
Notifications
You must be signed in to change notification settings - Fork 7
/
google_analytics_reports.views.inc
128 lines (115 loc) · 3.83 KB
/
google_analytics_reports.views.inc
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
<?php
/**
* @file
* Provide views data and handlers for Google Analytics Core Reporting API.
*/
/**
* Implements hook_views_data().
*/
function google_analytics_reports_views_data() {
$data['google_analytics']['table']['group'] = t('Google Analytics');
$data['google_analytics']['table']['base'] = array(
'title' => t('Google Analytics'),
'query class' => 'google_analytics_reports_query',
'help' => t('Views Google Analytics query builder'),
);
$data['google_analytics']['start_date'] = array(
'title' => t('Start date of report'),
'help' => t('Start date of report.'),
'argument' => array(
'handler' => 'google_analytics_reports_handler_argument',
),
'filter' => array(
'handler' => 'google_analytics_reports_handler_filter_date',
),
'sort' => array(
'handler' => 'views_handler_sort_date',
),
);
$data['google_analytics']['end_date'] = array(
'title' => t('End date of report'),
'help' => t('End date of report.'),
'argument' => array(
'handler' => 'google_analytics_reports_handler_argument',
),
'filter' => array(
'handler' => 'google_analytics_reports_handler_filter_date',
),
'sort' => array(
'handler' => 'views_handler_sort_date',
),
);
$data['google_analytics']['profile_id'] = array(
'title' => t('Profile ID'),
'help' => t('Profile ID'),
'argument' => array(
'handler' => 'google_analytics_reports_handler_argument',
),
'filter' => array(
'handler' => 'google_analytics_reports_handler_filter_string',
),
);
module_load_include('inc', 'google_analytics_reports');
$fields = google_analytics_reports_get_fields();
foreach ($fields as $field_name => $field) {
if (isset($field['calculation'])) {
$field['description'] = $field['description'] . '<br />' . t('Calculation: <code>@formula</code>.',
array('@formula' => $field['calculation']));
}
$field['description'] = $field['description'] . '<br />' . t('API name: <code>@ga</code>.',
array('@ga' => 'ga:' . $field_name));
// Provide default handler.
$field_handler = 'views_handler_field';
$float = FALSE;
if (google_analytics_reports_is_custom($field_name)) {
$field_handler = 'google_analytics_reports_handler_field';
}
elseif (in_array($field['datatype'], array('date', 'time'))) {
$field_handler = 'views_handler_field_date';
}
elseif (in_array($field['datatype'],
array('integer', 'float', 'percent', 'currency'))) {
$field_handler = 'views_handler_field_numeric';
$float = TRUE;
}
$data['google_analytics'][$field_name] = array(
'title' => $field['name'],
'help' => $field['description'],
'group' => $field['group'],
'field' => array(
'handler' => $field_handler,
'click sortable' => TRUE,
'float' => $float,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'argument' => array(
'handler' => 'google_analytics_reports_handler_argument',
),
'filter' => array(
'handler' => ($field['type'] == 'metric') ? 'google_analytics_reports_handler_filter_numeric' : 'google_analytics_reports_handler_filter_string',
),
);
}
return $data;
}
/**
* Implements hook_views_plugins().
*/
function google_analytics_reports_views_plugins() {
return array(
'query' => array(
'google_analytics_reports_query' => array(
'title' => t('Google Analytics Query'),
'handler' => 'google_analytics_reports_plugin_query_google_analytics',
),
),
'argument default' => array(
'google_analytics_reports_path' => array(
'title' => t('Current page path (Google Analytics Reports)'),
'handler' => 'google_analytics_reports_plugin_argument_default_google_analytics_reports_path',
),
),
);
}