google_analytics_counter.install in Google Analytics Counter 7.3
Same filename and directory in other branches
Update, and uninstall functions for the Google Analytics Counter module.
File
google_analytics_counter.installView source
<?php
/**
* @file
* Update, and uninstall functions for the Google Analytics Counter module.
*/
/**
* Implements hook_uninstall().
*/
function google_analytics_counter_uninstall() {
$query = db_select('variable', 'v')
->fields('v', array(
'name',
))
->condition('name', db_like('google_analytics_counter') . '%', 'LIKE')
->execute();
while ($variable = $query
->fetchAssoc()) {
variable_del($variable['name']);
}
}
/**
* 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',
'size' => 'big',
// big int unsigned: 8 B (18446744073709551615)
'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;
}
/**
* Add the google_analytics_counter table.
*/
function google_analytics_counter_update_7201() {
if (!db_table_exists('google_analytics_counter')) {
$schema = google_analytics_counter_schema();
db_create_table('google_analytics_counter', $schema['google_analytics_counter']);
return st('Add the google_analytics_counter table for the Google Analytics Counter module.');
}
}
/**
* Add the google_analytics_counter_storage table.
*/
function google_analytics_counter_update_7301() {
if (!db_table_exists('google_analytics_counter_storage')) {
$schema = google_analytics_counter_schema();
db_create_table('google_analytics_counter_storage', $schema['google_analytics_counter_storage']);
return st('Add the google_analytics_counter_storage table for the Google Analytics Counter module.');
}
}
/**
* Implements hook_requirements().
*/
function google_analytics_counter_requirements($phase) {
$requirements = array();
$t = get_t();
// Verify that the user has authenticated with Google Analytics.
// If not, display a warning on the status page.
if ($phase == 'runtime') {
$params = array(
'%google_analytics_counter_profile_id' => variable_get('google_analytics_counter_profile_id', 0),
);
$requirements['google_analytics_counter_authentication'] = array(
'title' => $t('Google Analytics Counter'),
'description' => $t('Google Analytics account ga:%google_analytics_counter_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 (variable_get('google_analytics_counter_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;
}
Functions
Name![]() |
Description |
---|---|
google_analytics_counter_requirements | Implements hook_requirements(). |
google_analytics_counter_schema | Implements hook_schema(). |
google_analytics_counter_uninstall | Implements hook_uninstall(). |
google_analytics_counter_update_7201 | Add the google_analytics_counter table. |
google_analytics_counter_update_7301 | Add the google_analytics_counter_storage table. |