googleanalytics.variable.inc 1.83 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
<?php

/**
 * @file
 * Definition of variables for Variable API module..
 */

/**
 * Implements hook_variable_info().
 */
function googleanalytics_variable_info($options) {
hass's avatar
hass committed
12
13
14
15
  $variables['googleanalytics_account'] = array(
    'type' => 'string',
    'title' => t('Web Property ID', array(), $options),
    'default' => 'UA-',
16
    '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),
hass's avatar
hass committed
17
    'required' => TRUE,
18
19
    'group' => 'googleanalytics',
    'localize' => TRUE,
hass's avatar
hass committed
20
21
    'validate callback' => 'googleanalytics_validate_googleanalytics_account',
  );
22
23
24
25

  return $variables;
}

hass's avatar
hass committed
26
27
/**
 * Implements hook_variable_group_info().
28
 */
hass's avatar
hass committed
29
30
function googleanalytics_variable_group_info() {
  $groups['googleanalytics'] = array(
31
    'title' => t('Google Analytics'),
hass's avatar
hass committed
32
33
34
    'description' => t('Configure tracking behavior to get insights into your website traffic and marketing effectiveness.'),
    'access' => 'administer google analytics',
    'path' => array('admin/config/system/googleanalytics'),
35
36
  );

hass's avatar
hass committed
37
38
39
40
41
42
  return $groups;
}

/**
 * Validate Web Property ID variable.
 */
43
function googleanalytics_validate_googleanalytics_account($variable) {
hass's avatar
hass committed
44
45
  if (!preg_match('/^UA-\d{4,}-\d+$/', $variable['value'])) {
    return t('A valid Google Analytics Web Property ID is case sensitive and formatted like UA-xxxxxxx-yy.');
46
  }
hass's avatar
hass committed
47
}