'));
if ($access) {
$options[] = t('Add if the following PHP code returns TRUE
(PHP-mode, experts only).');
$description .= ' '. t('If the PHP-mode is chosen, enter PHP code between %php. Note that executing incorrect PHP-code can break your Drupal site.', array('%php' => ''));
}
$form['page_vis_settings']['googleanalytics_visibility'] = array(
'#type' => 'radios',
'#title' => t('Add tracking to specific pages'),
'#options' => $options,
'#default_value' => $visibility,
);
$form['page_vis_settings']['googleanalytics_pages'] = array(
'#type' => 'textarea',
'#title' => t('Pages'),
'#default_value' => $pages,
'#description' => $description,
'#wysiwyg' => FALSE,
);
}
$profile_enabled = module_exists('profile');
$form['segmentation'] = array(
'#type' => 'fieldset',
'#title' => t('User segmentation settings'),
'#collapsible' => TRUE,
);
// Compile a list of fields to show.
$fields = variable_get('googleanalytics_segmentation_default_fields', array('roles' => t('User roles')));
if ($profile_enabled) {
$result = db_query('SELECT name, title, type, weight FROM {profile_fields} ORDER BY weight');
while ($record = db_fetch_object($result)) {
$fields[$record->name] = $record->title;
}
}
$form['segmentation']['googleanalytics_segmentation'] = array(
'#type' => 'select',
'#title' => t('Add segmentation information to tracking code'),
'#description' => t('Segment users based on different properties, additionally to the basic IP address based tracking provided by Google Analytics.') . (!$profile_enabled ? ' '. t('Enable the profile module to be able to use profile fields for more granular tracking.', array('@module_list' => url('admin/build/modules'))) : '') .' '. t('Make sure you will not associate (or permit any third party to associate) any data gathered from Your Website(s) (or such third parties\' website(s)) with any personally identifying information from any source as part of Your use (or such third parties\' use) of the Google Analytics service. For more information see section 8.1 in the Google Analytics terms of use.', array('@ga_tos' => 'http://www.google.com/analytics/en-GB/tos.html')) .' '. t('Selecting one or more values is supported. To select multiple items, hold down CTRL (PC) or ⌘ (Mac) while selecting fields.'),
'#default_value' => variable_get('googleanalytics_segmentation', ''),
'#options' => $fields,
'#size' => (count($fields)>10) ? 10 : count($fields),
'#multiple' => TRUE
);
// Link specific configurations.
$form['linktracking'] = array(
'#type' => 'fieldset',
'#title' => t('Link tracking settings'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['linktracking']['googleanalytics_trackoutgoing'] = array(
'#type' => 'checkbox',
'#title' => t('Track outgoing links'),
'#default_value' => variable_get('googleanalytics_trackoutgoing', 1),
'#description' => t('Enables tracking of clicks on outgoing links.')
);
$form['linktracking']['googleanalytics_trackmailto'] = array(
'#type' => 'checkbox',
'#title' => t('Track mailto links'),
'#default_value' => variable_get('googleanalytics_trackmailto', 1),
'#description' => t('Enables tracking of clicks on mailto links.')
);
$form['linktracking']['googleanalytics_trackfiles'] = array(
'#type' => 'checkbox',
'#title' => t('Track download links'),
'#default_value' => variable_get('googleanalytics_trackfiles', 1),
'#description' => t('Enables tracking of clicks on links to files based on the file extensions list below.')
);
$form['linktracking']['googleanalytics_trackfiles_extensions'] = array(
'#type' => 'textfield',
'#title' => t('File extensions to track'),
'#default_value' => variable_get('googleanalytics_trackfiles_extensions', GA_TRACKFILES_EXTENSIONS),
'#description' => t('A pipe separated list of file extensions that should be tracked when clicked with regular expression support. Example: !extensions', array('!extensions' => GA_TRACKFILES_EXTENSIONS)),
'#maxlength' => 256,
);
// Advanced feature configurations.
$form['advanced'] = array(
'#type' => 'fieldset',
'#title' => t('Advanced settings'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['advanced']['googleanalytics_cache'] = array(
'#type' => 'checkbox',
'#title' => t('Cache tracking code file locally'),
'#description' => t("If checked, the tracking code file is retrieved from Google Analytics and cached locally. It is updated daily from Google's servers to ensure updates to tracking code are reflected in the local copy. Do not activate this until after Google Analytics has confirmed your tracker!"),
'#default_value' => variable_get('googleanalytics_cache', 0),
);
if (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC) == FILE_DOWNLOADS_PRIVATE) {
$form['advanced']['googleanalytics_cache']['#disabled'] = TRUE;
$form['advanced']['googleanalytics_cache']['#description'] .= ' '. t('Public file transfers must be enabled to allow local caching.', array('@url' => url('admin/settings/file-system', array('query' => drupal_get_destination()))));
}
// Allow for tracking of the originating node when viewing translation sets.
if (module_exists('translation')) {
$form['advanced']['googleanalytics_translation_set'] = array(
'#type' => 'checkbox',
'#title' => t('Track translation sets as one unit'),
'#description' => t('When a node is part of a translation set, record statistics for the originating node instead. This allows for a translation set to be treated as a single unit.'),
'#default_value' => variable_get('googleanalytics_translation_set', 0),
);
}
$site_search_dependencies = '';
$site_search_dependencies .= t('Depends on: !dependencies', array('!dependencies' => (module_exists('search') ? t('@module (enabled)', array('@module' => 'Search')) : t('@module (disabled)', array('@module' => 'Search')))));
$site_search_dependencies .= '
';
// Google already have many translations, if not - they display a note to change the language.
global $language;
$form['advanced']['googleanalytics_site_search'] = array(
'#type' => 'checkbox',
'#title' => t('Track internal search'),
'#description' => t('If checked, internal search keywords are tracked. You must configure your Google account to use the internal query parameter search. For more information see How do I set up Site Search for my profile.', array('@url' => 'http://www.google.com/support/analytics/bin/answer.py?hl='. $language->language .'&answer=75817')) . $site_search_dependencies,
'#default_value' => variable_get('googleanalytics_site_search', FALSE),
'#disabled' => (module_exists('search') ? FALSE : TRUE),
);
$form['advanced']['googleanalytics_trackadsense'] = array(
'#type' => 'checkbox',
'#title' => t('Track AdSense ads'),
'#description' => t('If checked, your AdSense ads will be tracked in your Google Analytics account.'),
'#default_value' => variable_get('googleanalytics_trackadsense', FALSE),
);
$form['advanced']['codesnippet'] = array(
'#type' => 'fieldset',
'#title' => t('Custom JavaScript code'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#description' => t('You can add custom Google Analytics code snippets here. These will be added to every page that Google Analytics appears on. Before you add custom code to the below textarea\'s you should read Google Analytics Tracking Code - Functional Overview and the Google Analytics Tracking API documentation. Do not include the <script> tags, and always end your code with a semicolon (;).', array('@snippets' => 'http://drupal.org/node/248699', '@ga_concepts_overview' => 'http://code.google.com/apis/analytics/docs/gaConceptsOverview.html', '@ga_js_api' => 'http://code.google.com/apis/analytics/docs/gaJSApi.html'))
);
$form['advanced']['codesnippet']['googleanalytics_codesnippet_before'] = array(
'#type' => 'textarea',
'#title' => t('Code snippet (before)'),
'#default_value' => variable_get('googleanalytics_codesnippet_before', ''),
'#rows' => 5,
'#wysiwyg' => FALSE,
'#description' => t('Code in this textarea will be added before pageTracker._trackPageview().')
);
$form['advanced']['codesnippet']['googleanalytics_codesnippet_after'] = array(
'#type' => 'textarea',
'#title' => t('Code snippet (after)'),
'#default_value' => variable_get('googleanalytics_codesnippet_after', ''),
'#rows' => 5,
'#wysiwyg' => FALSE,
'#description' => t("Code in this textarea will be added after pageTracker._trackPageview(). This is useful if you'd like to track a site in two accounts.")
);
$form['advanced']['googleanalytics_js_scope'] = array(
'#type' => 'select',
'#title' => t('JavaScript scope'),
'#description' => t("Warning: Google recommends adding the external JavaScript files to footer for performance reasons."),
'#options' => array(
'footer' => t('Footer'),
'header' => t('Header'),
),
'#default_value' => variable_get('googleanalytics_js_scope', 'footer'),
);
return system_settings_form($form);
}
function googleanalytics_admin_settings_form_validate($form, &$form_state) {
if (!preg_match('/^UA-\d{4,}-\d+$/', $form_state['values']['googleanalytics_account'])) {
form_set_error('googleanalytics_account', t('A valid Google Analytics account number is case sensitive and formatted like UA-xxxxxx-x.'));
}
// This is for the Newbie's who cannot read a text area description.
if (stristr($form_state['values']['googleanalytics_codesnippet_before'], 'google-analytics.com/ga.js')) {
form_set_error('googleanalytics_codesnippet_before', t('Do not add the tracker code provided by Google into the javascript code snippets! This module already builds the tracker code based on your Google Analytics account number and settings.'));
}
if (stristr($form_state['values']['googleanalytics_codesnippet_after'], 'google-analytics.com/ga.js')) {
form_set_error('googleanalytics_codesnippet_after', t('Do not add the tracker code provided by Google into the javascript code snippets! This module already builds the tracker code based on your Google Analytics account number and settings.'));
}
if (preg_match('/(.*)<\/?script(.*)>(.*)/i', $form_state['values']['googleanalytics_codesnippet_before'])) {
form_set_error('googleanalytics_codesnippet_before', t('Do not include the <script> tags in the javascript code snippets.'));
}
if (preg_match('/(.*)<\/?script(.*)>(.*)/i', $form_state['values']['googleanalytics_codesnippet_after'])) {
form_set_error('googleanalytics_codesnippet_after', t('Do not include the <script> tags in the javascript code snippets.'));
}
// Trim some text area values.
$form_state['values']['googleanalytics_pages'] = trim($form_state['values']['googleanalytics_pages']);
$form_state['values']['googleanalytics_codesnippet_before'] = trim($form_state['values']['googleanalytics_codesnippet_before']);
$form_state['values']['googleanalytics_codesnippet_after'] = trim($form_state['values']['googleanalytics_codesnippet_after']);
}