You are here

function google_analytics_counter_admin in Google Analytics Counter 7.2

Same name and namespace in other branches
  1. 6.2 google_analytics_counter_settings.inc \google_analytics_counter_admin()
  2. 6 google_analytics_counter_settings.inc \google_analytics_counter_admin()
  3. 7.3 google_analytics_counter_settings.inc \google_analytics_counter_admin()
  4. 7 google_analytics_counter_settings.inc \google_analytics_counter_admin()

Config form shown at admin/config/system/google_analytics_counter

1 string reference to 'google_analytics_counter_admin'
google_analytics_counter_menu in ./google_analytics_counter.module
Menu for this module

File

./google_analytics_counter_settings.inc, line 11
Settings form.

Code

function google_analytics_counter_admin($form, &$form_state) {
  $defaultcroninterval = 60;
  $chunk = 1000;

  // Could be up to 10000 but keeping the default low so that it works even for people without external cron.
  $dayquota = 10000;
  $times = array();
  $intervals = array(
    1,
    3,
    5,
    10,
    20,
    30,
    60,
    180,
    360,
    720,
    1440,
  );
  foreach ($intervals as $interval) {
    $times[] = $interval;
  }
  $form['google_analytics_counter_cron_interval'] = array(
    '#type' => 'select',
    '#title' => t('Minimum time between Google Analytics data fetching'),
    '#default_value' => variable_get('google_analytics_counter_cron_interval', $defaultcroninterval),
    '#description' => t('Google Analytics statistical data is fetched and processed via a cron job. If your cron runs too frequently, you may waste your GA daily quota too fast. Set here the minimum time that needs to elapse before the Google Analytics Counter cron runs (even if your cron job runs more frequently). Specify the time in <em>minutes</em>. Default: %defaultcroninterval minutes.', array(
      '%defaultcroninterval' => check_plain($defaultcroninterval),
    )),
    '#options' => drupal_map_assoc($times),
    '#required' => TRUE,
  );
  $times = array();
  $curquota = variable_get('google_analytics_counter_api_dayquota', $dayquota);
  for ($chunks = 1; $chunks <= $curquota / 1000; $chunks++) {
    $times[] = $chunks * 1000;
  }
  $form['google_analytics_counter_chunk_to_fetch'] = array(
    '#type' => 'select',
    '#title' => t('Number of items to fetch from Google Analytics in one request'),
    '#default_value' => variable_get('google_analytics_counter_chunk_to_fetch', $chunk),
    '#description' => t('How many items will be fetched from Google Analytics in one request (during a cron run). The maximum allowed by Google is 10000 but it may take too long and time out. Default: %chunk items.', array(
      '%chunk' => check_plain($chunk),
    )),
    '#options' => drupal_map_assoc($times),
    '#required' => TRUE,
  );
  $form['google_analytics_counter_api_dayquota'] = array(
    '#type' => 'textfield',
    '#title' => t('Maximum GA API requests per day'),
    '#default_value' => variable_get('google_analytics_counter_api_dayquota', $dayquota),
    '#size' => 9,
    '#maxlength' => 9,
    '#description' => t('This is the <em>daily limit</em> of requests <em>per profile</em> to the Google Analytics API. You don\'t need to change this value until Google relaxes their quota policy. Current value: %dayquota.<br />It is reasonable to expect that Google will increase this low number sooner rather than later, so watch the <a href="https://developers.google.com/analytics/devguides/reporting/core/v3/limits-quotas#discovery" target="_blank">quota</a> page for changes.<br />To get the full quota, you must <a href="https://developers.google.com/analytics/devguides/reporting/core/v3/limits-quotas#full_quota" target="_blank">register your Analytics API</a>.', array(
      '%dayquota' => check_plain($dayquota),
    )),
    '#required' => TRUE,
  );

  // GA response cache options
  $times = array();
  for ($hours = 1; $hours <= 24; $hours++) {
    $times[] = $hours * GOOGLE_ANALYTICS_COUNTER_HOUR;
  }
  for ($days = 1; $days <= 6; $days++) {
    $times[] = $days * GOOGLE_ANALYTICS_COUNTER_DAY;
  }
  for ($weeks = 1; $weeks <= 4; $weeks++) {
    $times[] = $weeks * GOOGLE_ANALYTICS_COUNTER_WEEK;
  }
  $form['google_analytics_counter_cache_length'] = array(
    '#type' => 'select',
    '#title' => t('Google Analytics query cache'),
    '#description' => t('Limit the minimum time to elapse between getting fresh data for the same query from Google Analytics. Defaults to 1 day.'),
    '#options' => drupal_map_assoc($times, 'format_interval'),
    '#default_value' => variable_get('google_analytics_counter_cache_length', GOOGLE_ANALYTICS_COUNTER_DAY),
    '#required' => TRUE,
  );
  return system_settings_form($form);
}