-
Notifications
You must be signed in to change notification settings - Fork 7
/
google_analytics_reports.module
89 lines (81 loc) · 2.71 KB
/
google_analytics_reports.module
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
<?php
/**
* @file
* Front-end interfaces that use the Google Analytics Reports API module.
*/
/**
* Implements hook_permission().
*/
function google_analytics_reports_permission() {
return array(
'access google analytics reports' => array(
'title' => t('access google analytics reports'),
),
);
}
/**
* Implements hook_views_api().
*/
function google_analytics_reports_views_api() {
return array(
'api' => 3.0,
);
}
/**
* Determines if a field is custom or not.
*/
function google_analytics_reports_is_custom($field) {
return preg_match('/XX/', $field) ? TRUE : FALSE;
}
/**
* Converts a base custom field name and number into a specific field name.
*/
function google_analytics_reports_custom_to_variable_field($field, $number) {
return preg_replace('/XX/', $number, $field);
}
/**
* Converts a specific field name into a base custom field name.
*/
function google_analytics_reports_variable_to_custom_field($field) {
return preg_replace('/\d/', 'XX', $field);
}
/**
* Adds custom CSS style for Google Analytics Reports views pages.
*/
function google_analytics_reports_preprocess_views_view(&$vars) {
$view = &$vars['view'];
if (($view->name == 'google_analytics_reports_summary' && $view->current_display == 'page') ||
($view->name == 'google_analytics_reports_page' && $view->current_display == 'page') ||
($view->name == 'google_analytics_reports_page' && $view->current_display == 'page_front')) {
drupal_add_css(drupal_get_path('module', 'google_analytics_reports') . '/google_analytics_reports.css');
}
}
/**
* Implements hook_views_pre_build().
*/
function google_analytics_reports_views_pre_build(&$view) {
if ($view->name == 'google_analytics_reports_page' && $view->current_display == 'page') {
// Find page path for Google Analytics.
if (!empty($view->display_handler->options['path'])) {
// Decode current page url, that might appear due to browsers
// particularities.
$current_url = check_plain(urldecode(request_uri()));
// Return front page path ("/") if it is preview in Views UI.
if ($current_url == '/admin/structure/views/view/google_analytics_reports_page/preview/page/ajax') {
$view->args[0] = '/';
return;
}
// Menu path for current view without "%" at the end.
$menu_path = $view->display_handler->options['path'];
$menu_path = str_replace('%', '', $menu_path);
// Real url for Google Analytics.
$ga_url = str_replace($menu_path, '', $current_url);
// Remove old view arguments.
foreach ($view->args as $numb => $value) {
unset($view->args[$numb]);
}
// Set up real Google Analytics path as view argument.
$view->args[0] = $ga_url;
}
}
}