googleanalytics.variable.inc 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. function googleanalytics_validate_googleanalytics_account($variable) {
  39. // Replace all type of dashes (n-dash, m-dash, minus) with the normal dashes.
  40. $variable['value'] = str_replace(array('–', '—', '−'), '-', $variable['value']);
  41. if (!preg_match('/^UA-\d+-\d+$/', $variable['value'])) {
  42. return t('A valid Google Analytics Web Property ID is case sensitive and formatted like UA-xxxxxxx-yy.');
  43. }
  44. }