googleanalytics.variable.inc 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /**
  3. * @file
  4. * Definition of variables for Variable API module.
  5. */
  6. /**
  7. * Implements hook_variable_info().
  8. */
  9. function googleanalytics_variable_info($options) {
  10. $variables['googleanalytics_account'] = array(
  11. 'type' => 'string',
  12. 'title' => t('Web Property ID', array(), $options),
  13. 'default' => 'UA-',
  14. 'description' => t('This ID is unique to each site you want to track separately, and is in the form of UA-xxxxxxx-yy. To get a Web Property ID, <a href="@analytics">register your site with Google Analytics</a>, or if you already have registered your site, go to your Google Analytics Settings page to see the ID next to every site profile. <a href="@webpropertyid">Find more information in the documentation</a>.', array('@analytics' => 'http://www.google.com/analytics/', '@webpropertyid' => url('https://developers.google.com/analytics/resources/concepts/gaConceptsAccounts', array('fragment' => 'webProperty'))), $options),
  15. 'required' => TRUE,
  16. 'group' => 'googleanalytics',
  17. 'localize' => TRUE,
  18. 'multidomain' => TRUE,
  19. 'validate callback' => 'googleanalytics_validate_googleanalytics_account',
  20. );
  21. return $variables;
  22. }
  23. /**
  24. * Implements hook_variable_group_info().
  25. */
  26. function googleanalytics_variable_group_info() {
  27. $groups['googleanalytics'] = array(
  28. 'title' => t('Google Analytics'),
  29. 'description' => t('Configure tracking behavior to get insights into your website traffic and marketing effectiveness.'),
  30. 'access' => 'administer google analytics',
  31. 'path' => array('admin/config/system/googleanalytics'),
  32. );
  33. return $groups;
  34. }
  35. /**
  36. * Validate Web Property ID variable.
  37. *
  38. * @param array $variable
  39. *
  40. * @return string
  41. */
  42. function googleanalytics_validate_googleanalytics_account($variable) {
  43. // Replace all type of dashes (n-dash, m-dash, minus) with the normal dashes.
  44. $variable['value'] = str_replace(array('–', '—', '−'), '-', $variable['value']);
  45. if (!preg_match('/^UA-\d+-\d+$/', $variable['value'])) {
  46. return t('A valid Google Analytics Web Property ID is case sensitive and formatted like UA-xxxxxxx-yy.');
  47. }
  48. }