You are here

function _googleanalytics_validate_create_field_name in Google Analytics 6.4

Same name and namespace in other branches
  1. 7.2 googleanalytics.admin.inc \_googleanalytics_validate_create_field_name()

Checks whether a field name is valid.

Parameters

string $name: The option value entered by the user.

Return value

string The error message if the specified value is invalid, NULL otherwise.

1 call to _googleanalytics_validate_create_field_name()
googleanalytics_validate_create_field_values in ./googleanalytics.admin.inc
#element_validate callback for create only fields.

File

./googleanalytics.admin.inc, line 755
Administrative page callbacks for the googleanalytics module.

Code

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(
    'allowAnchor',
    'alwaysSendReferrer',
    'clientId',
    'cookieName',
    'cookieDomain',
    'cookieExpires',
    'legacyCookieDomain',
    'legacyHistoryImport',
    'sampleRate',
    'siteSpeedSampleRate',
    'storage',
    'useAmpClientId',
  );
  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 ($name == 'userId') {
    return t('Create only field name %name is a disallowed field name. Please enable <em>Track User ID</em> under <em>Tracking scope > Users</em>.', [
      '%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',
    ));
  }
}