non security modules update

This commit is contained in:
Bachir Soussi Chiadmi
2015-04-20 16:32:07 +02:00
parent 6a8d30db08
commit 37fbabab56
466 changed files with 32690 additions and 9652 deletions

View File

@@ -80,7 +80,15 @@ function googleanalytics_admin_settings_form($form_state) {
'#title' => t('List of top-level domains'),
'#type' => 'textarea',
'#default_value' => variable_get('googleanalytics_cross_domains', ''),
'#description' => t('If you selected "Multiple top-level domains" above, enter all related top-level domains. Add one domain per line. By default, the data in your reports only includes the path and name of the page, and not the domain name. For more information see section <em>Show separate domain names</em> in <a href="@url">Tracking Multiple Domains</a>.', array('@url' => url('http://support.google.com/analytics/bin/answer.py', array('query' => array('answer' => '1034342'))))),
'#description' => t('If you selected "Multiple top-level domains" above, enter all related top-level domains. Add one domain per line. By default, the data in your reports only includes the path and name of the page, and not the domain name. For more information see section <em>Show separate domain names</em> in <a href="@url">Tracking Multiple Domains</a>.', array('@url' => 'https://support.google.com/analytics/answer/1034342')),
'#states' => array(
'enabled' => array(
':input[name="googleanalytics_domain_mode"]' => array('value' => '2'),
),
'required' => array(
':input[name="googleanalytics_domain_mode"]' => array('value' => '2'),
),
),
);
// Page specific visibility configurations.
@@ -97,8 +105,8 @@ function googleanalytics_admin_settings_form($form_state) {
if ($visibility == 2 && !$php_access) {
$form['tracking']['page_vis_settings'] = array();
$form['tracking']['page_vis_settings']['visibility'] = array('#type' => 'value', '#value' => 2);
$form['tracking']['page_vis_settings']['pages'] = array('#type' => 'value', '#value' => $pages);
$form['tracking']['page_vis_settings']['googleanalytics_visibility_pages'] = array('#type' => 'value', '#value' => 2);
$form['tracking']['page_vis_settings']['googleanalytics_pages'] = array('#type' => 'value', '#value' => $pages);
}
else {
$options = array(
@@ -172,6 +180,12 @@ function googleanalytics_admin_settings_form($form_state) {
),
'#default_value' => variable_get('googleanalytics_custom', 0),
);
$form['tracking']['user_vis_settings']['googleanalytics_trackuserid'] = array(
'#type' => 'checkbox',
'#title' => t('Track User ID'),
'#default_value' => variable_get('googleanalytics_trackuserid', 0),
'#description' => t('User ID enables the analysis of groups of sessions, across devices, using a unique, persistent, and non-personally identifiable ID string representing a user. <a href="@url">Learn more about the benefits of using User ID</a>.', array('@url' => 'https://support.google.com/analytics/answer/3123663')),
);
// Link specific configurations.
$form['tracking']['linktracking'] = array(
@@ -199,7 +213,28 @@ function googleanalytics_admin_settings_form($form_state) {
'#type' => 'textfield',
'#default_value' => variable_get('googleanalytics_trackfiles_extensions', GOOGLEANALYTICS_TRACKFILES_EXTENSIONS),
'#description' => t('A file extension list separated by the | character that will be tracked as download when clicked. Regular expressions are supported. For example: !extensions', array('!extensions' => GOOGLEANALYTICS_TRACKFILES_EXTENSIONS)),
'#maxlength' => 255,
'#maxlength' => 500,
'#states' => array(
'enabled' => array(
':input[name="googleanalytics_trackfiles"]' => array('checked' => TRUE),
),
// Note: Form required marker is not visible as title is invisible.
'required' => array(
':input[name="googleanalytics_trackfiles"]' => array('checked' => TRUE),
),
),
);
$form['tracking']['linktracking']['googleanalytics_tracklinkid'] = array(
'#type' => 'checkbox',
'#title' => t('Track enhanced link attribution'),
'#default_value' => variable_get('googleanalytics_tracklinkid', 0),
'#description' => t('Enhanced Link Attribution improves the accuracy of your In-Page Analytics report by automatically differentiating between multiple links to the same URL on a single page by using link element IDs. <a href="@url">Enable enhanced link attribution</a> in the Admin UI of your Google Analytics account.', array('@url' => 'https://support.google.com/analytics/answer/2558867')),
);
$form['tracking']['linktracking']['googleanalytics_trackurlfragments'] = array(
'#type' => 'checkbox',
'#title' => t('Track changing URL fragments as pageviews'),
'#default_value' => variable_get('googleanalytics_trackurlfragments', 0),
'#description' => t('By default, the URL reported to Google Analytics will not include the "fragment identifier" (i.e. the portion of the URL beginning with a hash sign), and hash changes by themselves will not cause new pageviews to be reported. Checking this box will cause hash changes to be reported as pageviews (in modern browsers) and all pageview URLs to include the fragment where applicable.'),
);
// Message specific configurations.
@@ -211,7 +246,7 @@ function googleanalytics_admin_settings_form($form_state) {
'#type' => 'checkboxes',
'#title' => t('Track messages of type'),
'#default_value' => variable_get('googleanalytics_trackmessages', array()),
'#description' => t('This will track the selected message types shown to users. Tracking of form validation errors may help you identifying usability issues in your site. Keep in mind that Google allows a maximum of 500 events per session only and every message is tracked as one individual event. If the limit has been exceeded no further events are tracked, but normal page tracking is not effected. Messages from excluded pages cannot tracked.'),
'#description' => t('This will track the selected message types shown to users. Tracking of form validation errors may help you identifying usability issues in your site. For each visit (user session), a maximum of approximately 500 combined GATC requests (both events and page views) can be tracked. Every message is tracked as one individual event. Note that - as the number of events in a session approaches the limit - additional events might not be tracked. Messages from excluded pages cannot tracked.'),
'#options' => array(
'status' => t('Status message'),
'warning' => t('Warning message'),
@@ -219,21 +254,19 @@ function googleanalytics_admin_settings_form($form_state) {
),
);
// Google already have many translations, if not - they display a note to change the language.
global $language;
$form['tracking']['search_and_advertising'] = array(
'#type' => 'fieldset',
'#title' => t('Search and Advertising'),
);
$site_search_dependencies = '<div class="admin-dependencies">';
$site_search_dependencies .= t('Depends on: !dependencies', array('!dependencies' => (module_exists('search') ? t('@module (<span class="admin-enabled">enabled</span>)', array('@module' => 'Search')) : t('@module (<span class="admin-disabled">disabled</span>)', array('@module' => 'Search')))));
$site_search_dependencies = '<div class="admin-requirements">';
$site_search_dependencies .= t('Requires: !module-list', array('!module-list' => (module_exists('search') ? t('@module (<span class="admin-enabled">enabled</span>)', array('@module' => 'Search')) : t('@module (<span class="admin-disabled">disabled</span>)', array('@module' => 'Search')))));
$site_search_dependencies .= '</div>';
$form['tracking']['search_and_advertising']['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 <strong>search</strong>. For more information see <a href="@url">Setting Up Site Search for a Profile</a>.', array('@url' => url('http://support.google.com/analytics/bin/answer.py', array('query' => array('answer' => '1012264'))))) . $site_search_dependencies,
'#description' => t('If checked, internal search keywords are tracked. You must configure your Google account to use the internal query parameter <strong>search</strong>. For more information see <a href="@url">Setting Up Site Search for a Profile</a>.', array('@url' => 'https://support.google.com/analytics/answer/1012264')) . $site_search_dependencies,
'#default_value' => variable_get('googleanalytics_site_search', FALSE),
'#disabled' => (module_exists('search') ? FALSE : TRUE),
);
@@ -245,8 +278,8 @@ function googleanalytics_admin_settings_form($form_state) {
);
$form['tracking']['search_and_advertising']['googleanalytics_trackdoubleclick'] = array(
'#type' => 'checkbox',
'#title' => t('Track DoubleClick data'),
'#description' => t('If checked, the alternative Google <a href="@doubleclick">DoubleClick data tracking</a> is used to enable AdWords remarketing features. If you choose this option you will need to <a href="@privacy">update your privacy policy</a>.', array('@doubleclick' => url('http://support.google.com/analytics/bin/answer.py', array('query' => array('answer' => '2444872'))), '@privacy' => url('http://support.google.com/analytics/bin/answer.py', array('query' => array('answer' => '2636405'))))),
'#title' => t('Track display features'),
'#description' => t('The display features plugin can be used to enable Display Advertising Features in Google Analytics, such as Remarketing, Demographics and Interest Reporting, and more. <a href="@displayfeatures">Learn more about Display Advertising Features in Google Analytics</a>. If you choose this option you will need to <a href="@privacy">update your privacy policy</a>.', array('@displayfeatures' => 'https://support.google.com/analytics/answer/3450482', '@privacy' => 'https://support.google.com/analytics/answer/2700409')),
'#default_value' => variable_get('googleanalytics_trackdoubleclick', FALSE),
);
@@ -259,7 +292,7 @@ function googleanalytics_admin_settings_form($form_state) {
'#type' => 'checkbox',
'#title' => t('Anonymize visitors IP address'),
'#description' => t('Tell Google Analytics to anonymize the information sent by the tracker objects by removing the last octet of the IP address prior to its storage. Note that this will slightly reduce the accuracy of geographic reporting. In some countries it is not allowed to collect personally identifying information for privacy reasons and this setting may help you to comply with the local laws.'),
'#default_value' => variable_get('googleanalytics_tracker_anonymizeip', 0),
'#default_value' => variable_get('googleanalytics_tracker_anonymizeip', 1),
);
$form['tracking']['privacy']['googleanalytics_privacy_donottrack'] = array(
'#type' => 'checkbox',
@@ -268,79 +301,107 @@ function googleanalytics_admin_settings_form($form_state) {
'#default_value' => variable_get('googleanalytics_privacy_donottrack', 1),
);
// Custom variables.
$form['googleanalytics_custom_var'] = array(
// Custom Dimensions.
$form['googleanalytics_custom_dimension'] = array(
'#collapsed' => TRUE,
'#collapsible' => TRUE,
'#description' => t('You can add Google Analytics <a href="@custom_var_documentation">Custom Variables</a> here. These will be added to every page that Google Analytics tracking code appears on. Google Analytics will only accept custom variables if the <em>name</em> and <em>value</em> combined are less than 128 bytes after URL encoding. Keep the names as short as possible and expect long values to get trimmed. You may use tokens in custom variable names and values. Global and user tokens are always available; on node pages, node tokens are also available.', array('@custom_var_documentation' => 'https://developers.google.com/analytics/devguides/collection/gajs/gaTrackingCustomVariables')),
'#description' => t('You can set values for Google Analytics <a href="@custom_var_documentation">Custom Dimensions</a> here. You must have already configured your custom dimensions in the <a href="@setup_documentation">Google Analytics Management Interface</a>. You may use tokens. Global and user tokens are always available; on node pages, node tokens are also available. A dimension <em>value</em> is allowed to have a maximum lenght of 150 bytes. Expect longer values to get trimmed.', array('@custom_var_documentation' => 'https://developers.google.com/analytics/devguides/collection/analyticsjs/custom-dims-mets', '@setup_documentation' => 'https://support.google.com/analytics/answer/2709829')),
'#theme' => 'googleanalytics_admin_custom_var_table',
'#title' => t('Custom variables'),
'#title' => t('Custom dimensions'),
'#tree' => TRUE,
'#type' => 'fieldset',
);
$googleanalytics_custom_vars = variable_get('googleanalytics_custom_var', array());
$googleanalytics_custom_dimension = variable_get('googleanalytics_custom_dimension', array());
// Google Analytics supports up to 5 custom variables.
for ($i = 1; $i < 6; $i++) {
$form['googleanalytics_custom_var']['slots'][$i]['slot'] = array(
// Google Analytics supports up to 20 custom dimensions.
for ($i = 1; $i <= 20; $i++) {
$form['googleanalytics_custom_dimension']['indexes'][$i]['index'] = array(
'#default_value' => $i,
'#description' => t('Slot number'),
'#description' => t('Index number'),
'#disabled' => TRUE,
'#size' => 1,
'#title' => t('Custom variable slot #@slot', array('@slot' => $i)),
'#title' => t('Custom dimension index #@index', array('@index' => $i)),
'#title_display' => 'invisible',
'#type' => 'textfield',
);
$form['googleanalytics_custom_var']['slots'][$i]['name'] = array(
'#default_value' => !empty($googleanalytics_custom_vars['slots'][$i]['name']) ? $googleanalytics_custom_vars['slots'][$i]['name'] : '',
'#description' => t('The custom variable name.'),
$form['googleanalytics_custom_dimension']['indexes'][$i]['value'] = array(
'#default_value' => isset($googleanalytics_custom_dimension[$i]['value']) ? $googleanalytics_custom_dimension[$i]['value'] : '',
'#description' => t('The custom dimension value.'),
'#maxlength' => 255,
'#size' => 20,
'#title' => t('Custom variable name #@slot', array('@slot' => $i)),
'#title_display' => 'invisible',
'#type' => 'textfield',
'#element_validate' => array('googleanalytics_token_element_validate'),
'#token_types' => array('node'),
);
$form['googleanalytics_custom_var']['slots'][$i]['value'] = array(
'#default_value' => !empty($googleanalytics_custom_vars['slots'][$i]['value']) ? $googleanalytics_custom_vars['slots'][$i]['value'] : '',
'#description' => t('The custom variable value.'),
'#maxlength' => 255,
'#title' => t('Custom variable value #@slot', array('@slot' => $i)),
'#title' => t('Custom dimension value #@index', array('@index' => $i)),
'#title_display' => 'invisible',
'#type' => 'textfield',
'#element_validate' => array('googleanalytics_token_element_validate'),
'#token_types' => array('node'),
);
if (module_exists('token')) {
$form['googleanalytics_custom_var']['slots'][$i]['name']['#element_validate'][] = 'token_element_validate';
$form['googleanalytics_custom_var']['slots'][$i]['value']['#element_validate'][] = 'token_element_validate';
$form['googleanalytics_custom_dimension']['indexes'][$i]['value']['#element_validate'][] = 'token_element_validate';
}
$form['googleanalytics_custom_var']['slots'][$i]['scope'] = array(
'#default_value' => !empty($googleanalytics_custom_vars['slots'][$i]['scope']) ? $googleanalytics_custom_vars['slots'][$i]['scope'] : 3,
'#description' => t('The scope for the custom variable.'),
'#title' => t('Custom variable slot #@slot', array('@slot' => $i)),
'#title_display' => 'invisible',
'#type' => 'select',
'#options' => array(
1 => t('Visitor'),
2 => t('Session'),
3 => t('Page'),
),
}
$form['googleanalytics_custom_dimension']['googleanalytics_description'] = array(
'#type' => 'item',
'#description' => t('You can supplement Google Analytics\' basic IP address tracking of visitors by segmenting users based on custom dimensions. Section 7 of the <a href="@ga_tos">Google Analytics terms of service</a> requires that You will not (and will not allow any third party to) use the Service to track, collect or upload any data that personally identifies an individual (such as a name, userid, email address or billing information), or other data which can be reasonably linked to such information by Google. You will have and abide by an appropriate Privacy Policy and will comply with all applicable laws and regulations relating to the collection of information from Visitors. You must post a Privacy Policy and that Privacy Policy must provide notice of Your use of cookies that are used to collect traffic data, and You must not circumvent any privacy features (e.g., an opt-out) that are part of the Service.', array('@ga_tos' => 'http://www.google.com/analytics/terms/gb.html')),
);
if (module_exists('token')) {
$form['googleanalytics_custom_dimension']['googleanalytics_token_tree'] = array(
'#theme' => 'token_tree',
'#token_types' => array('node'),
'#dialog' => TRUE,
);
}
$form['googleanalytics_custom_var']['googleanalytics_custom_var_description'] = array(
'#type' => 'item',
'#description' => t('You can supplement Google Analytics\' basic IP address tracking of visitors by segmenting users based on custom variables. Section 7 of the <a href="@ga_tos">Google Analytics terms of service</a> requires that You will not (and will not allow any third party to) use the Service to track, collect or upload any data that personally identifies an individual (such as a name, email address or billing information), or other data which can be reasonably linked to such information by Google. You will have and abide by an appropriate Privacy Policy and will comply with all applicable laws and regulations relating to the collection of information from Visitors. You must post a Privacy Policy and that Privacy Policy must provide notice of Your use of cookies that are used to collect traffic data, and You must not circumvent any privacy features (e.g., an opt-out) that are part of the Service.', array('@ga_tos' => 'http://www.google.com/analytics/terms/gb.html')),
);
$form['googleanalytics_custom_var']['googleanalytics_custom_var_token_tree'] = array(
'#theme' => 'token_tree',
'#token_types' => array('node'),
'#dialog' => TRUE,
// Custom Metrics.
$form['googleanalytics_custom_metric'] = array(
'#collapsed' => TRUE,
'#collapsible' => TRUE,
'#description' => t('You can add Google Analytics <a href="@custom_var_documentation">Custom Metrics</a> here. You must have already configured your custom metrics in the <a href="@setup_documentation">Google Analytics Management Interface</a>. You may use tokens. Global and user tokens are always available; on node pages, node tokens are also available.', array('@custom_var_documentation' => 'https://developers.google.com/analytics/devguides/collection/analyticsjs/custom-dims-mets', '@setup_documentation' => 'https://support.google.com/analytics/answer/2709829')),
'#theme' => 'googleanalytics_admin_custom_var_table',
'#title' => t('Custom metrics'),
'#tree' => TRUE,
'#type' => 'fieldset',
);
$googleanalytics_custom_metric = variable_get('googleanalytics_custom_metric', array());
// Google Analytics supports up to 20 custom metrics.
for ($i = 1; $i <= 20; $i++) {
$form['googleanalytics_custom_metric']['indexes'][$i]['index'] = array(
'#default_value' => $i,
'#description' => t('Index number'),
'#disabled' => TRUE,
'#size' => 1,
'#title' => t('Custom metric index #@index', array('@index' => $i)),
'#title_display' => 'invisible',
'#type' => 'textfield',
);
$form['googleanalytics_custom_metric']['indexes'][$i]['value'] = array(
'#default_value' => isset($googleanalytics_custom_metric[$i]['value']) ? $googleanalytics_custom_metric[$i]['value'] : '',
'#description' => t('The custom metric value.'),
'#maxlength' => 255,
'#title' => t('Custom metric value #@index', array('@index' => $i)),
'#title_display' => 'invisible',
'#type' => 'textfield',
'#element_validate' => array('googleanalytics_token_element_validate'),
'#token_types' => array('node'),
);
if (module_exists('token')) {
$form['googleanalytics_custom_metric']['indexes'][$i]['value']['#element_validate'][] = 'token_element_validate';
}
}
$form['googleanalytics_custom_metric']['googleanalytics_description'] = array(
'#type' => 'item',
'#description' => t('You can supplement Google Analytics\' basic IP address tracking of visitors by segmenting users based on custom metrics. Section 7 of the <a href="@ga_tos">Google Analytics terms of service</a> requires that You will not (and will not allow any third party to) use the Service to track, collect or upload any data that personally identifies an individual (such as a name, userid, email address or billing information), or other data which can be reasonably linked to such information by Google. You will have and abide by an appropriate Privacy Policy and will comply with all applicable laws and regulations relating to the collection of information from Visitors. You must post a Privacy Policy and that Privacy Policy must provide notice of Your use of cookies that are used to collect traffic data, and You must not circumvent any privacy features (e.g., an opt-out) that are part of the Service.', array('@ga_tos' => 'http://www.google.com/analytics/terms/gb.html')),
);
if (module_exists('token')) {
$form['googleanalytics_custom_metric']['googleanalytics_token_tree'] = array(
'#theme' => 'token_tree',
'#token_types' => array('node'),
'#dialog' => TRUE,
);
}
// Advanced feature configurations.
$form['advanced'] = array(
@@ -372,33 +433,36 @@ function googleanalytics_admin_settings_form($form_state) {
'#title' => t('Custom JavaScript code'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#description' => t('You can add custom Google Analytics <a href="@snippets">code snippets</a> here. These will be added every time tracking is in effect. Before you add your custom code, you should read the <a href="@ga_concepts_overview">Google Analytics Tracking Code - Functional Overview</a> and the <a href="@ga_js_api">Google Analytics Tracking API</a> documentation. <strong>Do not include the &lt;script&gt; tags</strong>, and always end your code with a semicolon (;).', array('@snippets' => 'http://drupal.org/node/248699', '@ga_concepts_overview' => 'https://developers.google.com/analytics/resources/concepts/gaConceptsTrackingOverview', '@ga_js_api' => 'https://developers.google.com/analytics/devguides/collection/gajs/methods/')),
'#description' => t('You can add custom Google Analytics <a href="@snippets">code snippets</a> here. These will be added every time tracking is in effect. Before you add your custom code, you should read the <a href="@ga_concepts_overview">Google Analytics Tracking Code - Functional Overview</a> and the <a href="@ga_js_api">Google Analytics Tracking API</a> documentation. <strong>Do not include the &lt;script&gt; tags</strong>, and always end your code with a semicolon (;).', array('@snippets' => 'http://drupal.org/node/248699', '@ga_concepts_overview' => 'https://developers.google.com/analytics/resources/concepts/gaConceptsTrackingOverview', '@ga_js_api' => 'https://developers.google.com/analytics/devguides/collection/analyticsjs/method-reference')),
);
$form['advanced']['codesnippet']['googleanalytics_codesnippet_create'] = array(
'#type' => 'textarea',
'#title' => t('Create only fields'),
'#default_value' => _googleanalytics_get_name_value_string(variable_get('googleanalytics_codesnippet_create', array())),
'#rows' => 5,
'#description' => t('Enter one value per line, in the format name|value. Settings in this textarea will be added to <code>ga("create", "UA-XXXX-Y", {"name":"value"});</code>. For more information, read <a href="@url">create only fields</a> documentation in the Analytics.js field reference.', array('@url' => 'https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#create')),
'#element_validate' => array('googleanalytics_validate_create_field_values'),
);
$form['advanced']['codesnippet']['googleanalytics_codesnippet_before'] = array(
'#type' => 'textarea',
'#title' => t('Code snippet (before)'),
'#default_value' => variable_get('googleanalytics_codesnippet_before', ''),
'#rows' => 5,
'#description' => t("Code in this textarea will be added <strong>before</strong> _gaq.push(['_trackPageview'])."),
'#description' => t('Code in this textarea will be added <strong>before</strong> <code>ga("send", "pageview");</code>.'),
);
$form['advanced']['codesnippet']['googleanalytics_codesnippet_after'] = array(
'#type' => 'textarea',
'#title' => t('Code snippet (after)'),
'#default_value' => variable_get('googleanalytics_codesnippet_after', ''),
'#rows' => 5,
'#description' => t("Code in this textarea will be added <strong>after</strong> _gaq.push(['_trackPageview']). This is useful if you'd like to track a site in two accounts."),
'#description' => t('Code in this textarea will be added <strong>after</strong> <code>ga("send", "pageview");</code>. 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('Google recommends adding the external JavaScript files to the header for performance reasons. If <em>Multiple top-level domains</em> has been selected, this setting will be forced to header.'),
'#options' => array(
'footer' => t('Footer'),
'header' => t('Header'),
),
'#default_value' => variable_get('googleanalytics_js_scope', 'header'),
'#disabled' => (variable_get('googleanalytics_domain_mode', 0) == 2) ? TRUE : FALSE,
$form['advanced']['googleanalytics_debug'] = array(
'#type' => 'checkbox',
'#title' => t('Enable debugging'),
'#description' => t('If checked, the Google Universal Analytics debugging script will be loaded. You should not enable your production site to use this version of the JavaScript. The analytics_debug.js script is larger than the analytics.js tracking code and it is not typically cached. Using it in your production site will slow down your site for all of your users. Again, this is only for your own testing purposes. Debug messages are printed to the <code>window.console</code> object.'),
'#default_value' => variable_get('googleanalytics_debug', 0),
);
return system_settings_form($form);
@@ -408,31 +472,37 @@ function googleanalytics_admin_settings_form($form_state) {
* Implements _form_validate().
*/
function googleanalytics_admin_settings_form_validate($form, &$form_state) {
// Custom variables validation.
foreach ($form_state['values']['googleanalytics_custom_var']['slots'] as $custom_var) {
$form_state['values']['googleanalytics_custom_var']['slots'][$custom_var['slot']]['name'] = trim($custom_var['name']);
$form_state['values']['googleanalytics_custom_var']['slots'][$custom_var['slot']]['value'] = trim($custom_var['value']);
// Validate empty names/values.
if (empty($custom_var['name']) && !empty($custom_var['value'])) {
form_set_error("googleanalytics_custom_var][slots][" . $custom_var['slot'] . "][name", t('The custom variable @slot-number requires a <em>Name</em> if a <em>Value</em> has been provided.', array('@slot-number' => $custom_var['slot'])));
}
elseif (!empty($custom_var['name']) && empty($custom_var['value'])) {
form_set_error("googleanalytics_custom_var][slots][" . $custom_var['slot'] . "][value", t('The custom variable @slot-number requires a <em>Value</em> if a <em>Name</em> has been provided.', array('@slot-number' => $custom_var['slot'])));
// Trim custom dimensions and metrics.
foreach ($form_state['values']['googleanalytics_custom_dimension']['indexes'] as $dimension) {
$form_state['values']['googleanalytics_custom_dimension']['indexes'][$dimension['index']]['value'] = trim($dimension['value']);
// Remove empty values from the array.
if (!drupal_strlen($form_state['values']['googleanalytics_custom_dimension']['indexes'][$dimension['index']]['value'])) {
unset($form_state['values']['googleanalytics_custom_dimension']['indexes'][$dimension['index']]);
}
}
$form_state['values']['googleanalytics_custom_dimension'] = $form_state['values']['googleanalytics_custom_dimension']['indexes'];
foreach ($form_state['values']['googleanalytics_custom_metric']['indexes'] as $metric) {
$form_state['values']['googleanalytics_custom_metric']['indexes'][$metric['index']]['value'] = trim($metric['value']);
// Remove empty values from the array.
if (!drupal_strlen($form_state['values']['googleanalytics_custom_metric']['indexes'][$metric['index']]['value'])) {
unset($form_state['values']['googleanalytics_custom_metric']['indexes'][$metric['index']]);
}
}
$form_state['values']['googleanalytics_custom_metric'] = $form_state['values']['googleanalytics_custom_metric']['indexes'];
// Trim some text values.
$form_state['values']['googleanalytics_account'] = trim($form_state['values']['googleanalytics_account']);
$form_state['values']['googleanalytics_pages'] = trim($form_state['values']['googleanalytics_pages']);
$form_state['values']['googleanalytics_cross_domains'] = trim($form_state['values']['googleanalytics_cross_domains']);
$form_state['values']['googleanalytics_codesnippet_create'] = _googleanalytics_extract_create_field_values($form_state['values']['googleanalytics_codesnippet_create']);
$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']);
// Replace all type of dashes (n-dash, m-dash, minus) with the normal dashes.
$form_state['values']['googleanalytics_account'] = str_replace(array('', '—', ''), '-', $form_state['values']['googleanalytics_account']);
if (!preg_match('/^UA-\d{4,}-\d+$/', $form_state['values']['googleanalytics_account'])) {
if (!preg_match('/^UA-\d+-\d+$/', $form_state['values']['googleanalytics_account'])) {
form_set_error('googleanalytics_account', t('A valid Google Analytics Web Property ID is case sensitive and formatted like UA-xxxxxxx-yy.'));
}
@@ -440,16 +510,25 @@ function googleanalytics_admin_settings_form_validate($form, &$form_state) {
if ($form_state['values']['googleanalytics_domain_mode'] == 2 && empty($form_state['values']['googleanalytics_cross_domains'])) {
form_set_error('googleanalytics_cross_domains', t('A list of top-level domains is required if <em>Multiple top-level domains</em> has been selected.'));
}
// Clear the domain list if cross domains are disabled.
if ($form_state['values']['googleanalytics_domain_mode'] != 2) {
$form_state['values']['googleanalytics_cross_domains'] = '';
}
// Disallow empty list of download file extensions.
if ($form_state['values']['googleanalytics_trackfiles'] && empty($form_state['values']['googleanalytics_trackfiles_extensions'])) {
form_set_error('googleanalytics_trackfiles_extensions', t('List of download file extensions cannot empty.'));
}
// Clear obsolete local cache if cache has been disabled.
if (empty($form_state['values']['googleanalytics_cache']) && $form['advanced']['googleanalytics_cache']['#default_value']) {
googleanalytics_clear_js_cache();
}
// 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')) {
if (stristr($form_state['values']['googleanalytics_codesnippet_before'], 'google-analytics.com/analytics.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')) {
if (stristr($form_state['values']['googleanalytics_codesnippet_after'], 'google-analytics.com/analytics.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'])) {
@@ -458,11 +537,6 @@ function googleanalytics_admin_settings_form_validate($form, &$form_state) {
if (preg_match('/(.*)<\/?script(.*)>(.*)/i', $form_state['values']['googleanalytics_codesnippet_after'])) {
form_set_error('googleanalytics_codesnippet_after', t('Do not include the &lt;script&gt; tags in the javascript code snippets.'));
}
// Header section must be forced for multiple top-level domains.
if ($form_state['values']['googleanalytics_domain_mode'] == 2) {
$form_state['values']['googleanalytics_js_scope'] = 'header';
}
}
/**
@@ -472,27 +546,25 @@ function theme_googleanalytics_admin_custom_var_table($variables) {
$form = $variables['form'];
$header = array(
array('data' => t('Slot')),
array('data' => t('Name')),
array('data' => t('Index')),
array('data' => t('Value')),
array('data' => t('Scope')),
);
$rows = array();
foreach (element_children($form['slots']) as $key => $id) {
foreach (element_children($form['indexes']) as $key => $id) {
$rows[] = array(
'data' => array(
drupal_render($form['slots'][$id]['slot']),
drupal_render($form['slots'][$id]['name']),
drupal_render($form['slots'][$id]['value']),
drupal_render($form['slots'][$id]['scope']),
drupal_render($form['indexes'][$id]['index']),
drupal_render($form['indexes'][$id]['value']),
),
);
}
$output = theme('table', array('header' => $header, 'rows' => $rows));
$output .= drupal_render($form['googleanalytics_custom_var_description']);
$output .= drupal_render($form['googleanalytics_custom_var_token_tree']);
$output .= drupal_render($form['googleanalytics_description']);
if (isset($form['googleanalytics_token_tree'])) {
$output .= drupal_render($form['googleanalytics_token_tree']);
}
return $output;
}
@@ -599,3 +671,198 @@ function _googleanalytics_contains_forbidden_token($token_string) {
return preg_match('/' . implode('|', array_map('preg_quote', $token_blacklist)) . '/i', $token_string);
}
/**
* #element_validate callback for create only fields.
*
* @param $element
* An associative array containing the properties and children of the
* generic form element.
* @param $form_state
* The $form_state array for the form this element belongs to.
*
* @see form_process_pattern()
*/
function googleanalytics_validate_create_field_values(&$element, &$form_state) {
$values = _googleanalytics_extract_create_field_values($element['#value']);
if (!is_array($values)) {
form_error($element, t('The %element-title field contains invalid input.', array('%element-title' => $element['#title'])));
}
else {
// Check that name and value are valid for the field type.
foreach ($values as $name => $value) {
if ($error = _googleanalytics_validate_create_field_name($name)) {
form_error($element, $error);
break;
}
if ($error = _googleanalytics_validate_create_field_value($value)) {
form_error($element, $error);
break;
}
}
return $element;
}
}
/**
* Extracts the values array from the element.
*
* @param string $string
* The raw string to extract values from.
*
* @return array|null
* The array of extracted key/value pairs, or NULL if the string is invalid.
*
* @see \Drupal\options\Plugin\Field\FieldType\ListTextItem::allowedValuesString()
*/
function _googleanalytics_extract_create_field_values($string) {
$values = array();
$list = explode("\n", $string);
$list = array_map('trim', $list);
$list = array_filter($list, 'strlen');
foreach ($list as $position => $text) {
// Check for an explicit key.
$matches = array();
if (preg_match('/(.*)\|(.*)/', $text, $matches)) {
// Trim key and value to avoid unwanted spaces issues.
$name = trim($matches[1]);
$value = trim($matches[2]);
}
else {
return;
}
$values[$name] = $value;
}
return _googleanalytics_convert_form_value_data_types($values);
}
/**
* Checks whether a field name is valid.
*
* @param string $name
* The option value entered by the user.
*
* @return string
* The error message if the specified value is invalid, NULL otherwise.
*/
function _googleanalytics_validate_create_field_name($name) {
// List of supported field names:
// https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#create
$create_only_fields = array(
'clientId',
'userId',
'sampleRate',
'siteSpeedSampleRate',
'alwaysSendReferrer',
'allowAnchor',
'cookieName',
'cookieDomain',
'cookieExpires',
'legacyCookieDomain',
);
if ($name == 'name') {
return t('Create only field name %name is a disallowed field name. Changing the <em>Tracker Name</em> is currently not supported.', array('%name' => $name));
}
if ($name == 'allowLinker') {
return t('Create only field name %name is a disallowed field name. Please select <em>Multiple top-level domains</em> under <em>What are you tracking</em> to enable cross domain tracking.', array('%name' => $name));
}
if (!in_array($name, $create_only_fields)) {
return t('Create only field name %name is an unknown field name. Field names are case sensitive. Please see <a href="@url">create only fields</a> documentation for supported field names.', array('%name' => $name, '@url' => 'https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#create'));
}
}
/**
* Checks whether a field value is valid.
*
* @param string $value
* The option value entered by the user.
*
* @return string
* The error message if the specified value is invalid, NULL otherwise.
*/
function _googleanalytics_validate_create_field_value($value) {
if (!is_bool($value) && !drupal_strlen($value)) {
return t('A create only field requires a value.');
}
if (drupal_strlen($value) > 255) {
return t('The value of a create only field must be a string at most 255 characters long.');
}
}
/**
* Generates a string representation of an array.
*
* This string format is suitable for edition in a textarea.
*
* @param array $values
* An array of values, where array keys are values and array values are
* labels.
*
* @return string
* The string representation of the $values array:
* - Values are separated by a carriage return.
* - Each value is in the format "name|value" or "value".
*/
function _googleanalytics_get_name_value_string($values) {
$lines = array();
foreach ($values as $name => $value) {
// Convert data types.
// @todo: #2251377: Json utility class serializes boolean values to incorrect data type
if (is_bool($value)) {
$value = ($value) ? 'true' : 'false';
}
$lines[] = "$name|$value";
}
return implode("\n", $lines);
}
/**
* Prepare form data types for Json conversion.
*
* @param array $values
* Array of name/value pairs.
*
* @return array
* Array of name/value pairs with casted data types.
*/
function _googleanalytics_convert_form_value_data_types($values) {
foreach ($values as $name => $value) {
// Convert data types.
// @todo: #2251377: Json utility class serializes boolean values to incorrect data type
$match = drupal_strtolower($value);
if ($match == 'true') {
$value = TRUE;
}
elseif ($match == 'false') {
$value = FALSE;
}
// Convert other known fields.
// @todo: #2251343: Json utility class serializes numeric values to incorrect data type
switch ($name) {
case 'sampleRate':
// Float
settype($value, 'float');
break;
case 'siteSpeedSampleRate':
case 'cookieExpires':
// Integer
settype($value, 'integer');
break;
}
$values[$name] = $value;
}
return $values;
}