-
Notifications
You must be signed in to change notification settings - Fork 3
/
google_analytics_counter.install
106 lines (100 loc) · 3.68 KB
/
google_analytics_counter.install
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
<?php
/**
* @file
* Update, and uninstall functions for the Google Analytics Counter module.
*/
/**
* Implements hook_schema().
*
* See http://drupal.org/node/146939
*/
function google_analytics_counter_schema() {
$schema['google_analytics_counter'] = array(
'description' => 'Google Analytics data storage.',
'fields' => array(
'pagepath_hash' => array(
'type' => 'varchar',
'length' => 32,
'description' => 'md5 hash of the relative page path.',
'not null' => TRUE,
),
'pagepath' => array(
'type' => 'varchar',
// Varchar faster than text on MySQL (not creating temp table on disk);
// see http://drupal.org/node/146939#comment-2281846
'length' => 2048,
// See http://stackoverflow.com/a/417184/269383
'description' => 'Relative page path, for example "node/1" or "contact", as stored by GA.',
'not null' => TRUE,
),
'pageviews' => array(
'type' => 'int',
// Big int unsigned: 8 B (18446744073709551615).
'size' => 'big',
'description' => 'Pageview count.',
'unsigned' => TRUE,
'default' => 0,
'not null' => TRUE,
),
),
'primary key' => array('pagepath_hash'),
'indexes' => array(
'pagepath' => array(array('pagepath', 20)),
'pageviews' => array('pageviews'),
),
);
$schema['google_analytics_counter_storage'] = array(
'description' => 'Google Analytics Counter module table holding pageview counts.',
'fields' => array(
'nid' => array(
'description' => 'Node IDs',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'pageview_total' => array(
'description' => 'Total pageview counts',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
),
'primary key' => array('nid'),
'indexes' => array(
'pageview_total' => array('pageview_total'),
),
);
return $schema;
}
/**
* Implements hook_requirements().
*/
function google_analytics_counter_requirements($phase) {
$requirements = array();
// Verify that the user has authenticated with Google Analytics.
// If not, display a warning on the status page.
if ($phase == 'runtime') {
$config = \Drupal::config('google_analytics_counter.settings');
$params = array(
'%profile_id' => $config->get('profile_id'),
);
$requirements['google_analytics_counter_authentication'] = array(
'title' => t('Google Analytics Counter'),
'description' => t('Google Analytics account ga:%profile_id has been authenticated. You can change it or revoke authentication <a href="/admin/config/system/google_analytics_counter/authentication">here</a>.', $params),
'severity' => REQUIREMENT_OK,
'value' => t('A Google Analytics profile is authenticated: OK'),
);
$authenticated = FALSE;
// It's a weak test but better than none.
if ($config->get('profile_id') <> '') {
$authenticated = TRUE;
}
if (!$authenticated) {
$requirements['google_analytics_counter_authentication']['title'] = t('Google Analytics Counter requirements');
$requirements['google_analytics_counter_authentication']['description'] = t('No Google Analytics profile has been authenticated. Google Analytics Counter can not fetch any new data. Please authenticate <a href="/admin/config/system/google_analytics_counter/authentication">here</a>.');
$requirements['google_analytics_counter_authentication']['severity'] = REQUIREMENT_ERROR;
$requirements['google_analytics_counter_authentication']['value'] = t('No Google Analytics profile has been authenticated!');
}
}
return $requirements;
}