You are here

function googleanalytics_update_6301 in Google Analytics 6.3

Same name and namespace in other branches
  1. 6.4 googleanalytics.install \googleanalytics_update_6301()

Upgrade "User roles" tracking to custom variables.

File

./googleanalytics.install, line 331
Installation file for Google Analytics module.

Code

function googleanalytics_update_6301() {
  $ret = array();

  // Read previous segmentation settings.
  $segmentation = variable_get('googleanalytics_segmentation', array());
  if (module_exists('token') && in_array('roles', $segmentation)) {

    // Upgrade previous segmentation settings to new custom variables settings.
    $googleanalytics_custom_vars = variable_get('googleanalytics_custom_var', array());
    $googleanalytics_custom_vars['slots'][1]['slot'] = 1;
    $googleanalytics_custom_vars['slots'][1]['name'] = 'User roles';
    $googleanalytics_custom_vars['slots'][1]['value'] = '[user-role-names]';
    $googleanalytics_custom_vars['slots'][1]['scope'] = 1;

    // Sets the scope to visitor-level.
    variable_set('googleanalytics_custom_var', $googleanalytics_custom_vars);
    $ret[] = array(
      'success' => TRUE,
      'query' => t('The deprecated profile segmentation setting for "User roles" has been added to custom variables. You need to deselect all selected profile fields in <a href="@admin">Google Analytics settings</a> and upgrade other profile fields manually or you may loose tracking data in future! See Google Analytics <a href="@customvar">Custom Variables</a> for more information.', array(
        '@customvar' => 'https://developers.google.com/analytics/devguides/collection/gajs/gaTrackingCustomVariables',
        '@admin' => url('admin/settings/googleanalytics'),
      )),
    );
  }
  else {
    $ret[] = array(
      'success' => TRUE,
      'query' => t('You need to deselect all selected profile fields in <a href="@admin">Google Analytics settings</a> and upgrade other profile fields manually or you may loose tracking data in future! See Google Analytics <a href="@customvar">Custom Variables</a> for more information.', array(
        '@customvar' => 'https://developers.google.com/analytics/devguides/collection/gajs/gaTrackingCustomVariables',
        '@admin' => url('admin/settings/googleanalytics'),
      )),
    );
    $ret[] = array(
      'success' => TRUE,
      'query' => t('<a href="@token">Token</a> module is recommended for custom variables.', array(
        '@token' => 'http://drupal.org/project/token',
      )),
    );
  }
  return $ret;
}