googleanalytics.install 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537
  1. <?php
  2. /**
  3. * @file
  4. * Installation file for Google Analytics module.
  5. */
  6. /**
  7. * Implements hook_uninstall().
  8. */
  9. function googleanalytics_uninstall() {
  10. variable_del('googleanalytics_account');
  11. variable_del('googleanalytics_cache');
  12. variable_del('googleanalytics_codesnippet_create');
  13. variable_del('googleanalytics_codesnippet_before');
  14. variable_del('googleanalytics_codesnippet_after');
  15. variable_del('googleanalytics_cross_domains');
  16. variable_del('googleanalytics_custom');
  17. variable_del('googleanalytics_custom_dimension');
  18. variable_del('googleanalytics_custom_metric');
  19. variable_del('googleanalytics_debug');
  20. variable_del('googleanalytics_domain_mode');
  21. variable_del('googleanalytics_last_cache');
  22. variable_del('googleanalytics_pages');
  23. variable_del('googleanalytics_roles');
  24. variable_del('googleanalytics_site_search');
  25. variable_del('googleanalytics_trackadsense');
  26. variable_del('googleanalytics_trackdoubleclick');
  27. variable_del('googleanalytics_tracker_anonymizeip');
  28. variable_del('googleanalytics_trackfiles');
  29. variable_del('googleanalytics_trackfiles_extensions');
  30. variable_del('googleanalytics_tracklinkid');
  31. variable_del('googleanalytics_trackurlfragments');
  32. variable_del('googleanalytics_trackuserid');
  33. variable_del('googleanalytics_trackmailto');
  34. variable_del('googleanalytics_trackmessages');
  35. variable_del('googleanalytics_trackoutbound');
  36. variable_del('googleanalytics_translation_set');
  37. variable_del('googleanalytics_visibility_pages');
  38. variable_del('googleanalytics_visibility_roles');
  39. variable_del('googleanalytics_privacy_donottrack');
  40. // Remove backup variables if exist. Remove this code in D8.
  41. variable_del('googleanalytics_codesnippet_after_backup_7200');
  42. variable_del('googleanalytics_codesnippet_before_backup_7200');
  43. }
  44. /**
  45. * Implements hook_disable().
  46. *
  47. * Remove cache directory if module is disabled (or uninstalled).
  48. */
  49. function googleanalytics_disable() {
  50. googleanalytics_clear_js_cache();
  51. }
  52. /**
  53. * Implements hook_requirements().
  54. */
  55. function googleanalytics_requirements($phase) {
  56. $requirements = array();
  57. $t = get_t();
  58. if ($phase == 'runtime') {
  59. // Raise warning if Google user account has not been set yet.
  60. if (!preg_match('/^UA-\d+-\d+$/', variable_get('googleanalytics_account', 'UA-'))) {
  61. $requirements['googleanalytics_account'] = array(
  62. 'title' => $t('Google Analytics module'),
  63. 'description' => $t('Google Analytics module has not been configured yet. Please configure its settings from the <a href="@url">Google Analytics settings page</a>.', array('@url' => url('admin/config/system/googleanalytics'))),
  64. 'severity' => REQUIREMENT_WARNING,
  65. 'value' => $t('Not configured'),
  66. );
  67. }
  68. // Raise warning if debugging is enabled.
  69. if (variable_get('googleanalytics_debug', 0)) {
  70. $requirements['google_analytics_debugging'] = array(
  71. 'title' => $t('Google Analytics module'),
  72. 'description' => $t('Google Analytics module has debugging enabled. Please disable debugging setting in production sites from the <a href="@url">Google Analytics settings page</a>.', array('@url' => url('admin/config/system/googleanalytics'))),
  73. 'severity' => REQUIREMENT_WARNING,
  74. 'value' => $t('Debugging enabled'),
  75. );
  76. }
  77. }
  78. return $requirements;
  79. }
  80. /**
  81. * Upgrade old extension variable to new and use old name as enabled/disabled flag.
  82. */
  83. function googleanalytics_update_6000() {
  84. variable_set('googleanalytics_trackfiles_extensions', variable_get('googleanalytics_trackfiles', '7z|aac|avi|csv|doc|exe|flv|gif|gz|jpe?g|js|mp(3|4|e?g)|mov|pdf|phps|png|ppt|rar|sit|tar|torrent|txt|wma|wmv|xls|xml|zip'));
  85. $trackfiles = variable_get('googleanalytics_trackfiles', '7z|aac|avi|csv|doc|exe|flv|gif|gz|jpe?g|js|mp(3|4|e?g)|mov|pdf|phps|png|ppt|rar|sit|tar|torrent|txt|wma|wmv|xls|xml|zip') ? TRUE : FALSE;
  86. variable_set('googleanalytics_trackfiles', $trackfiles);
  87. return t('Updated download tracking file extensions.');
  88. }
  89. function googleanalytics_update_6001() {
  90. variable_set('googleanalytics_visibility', 0);
  91. // Remove tracking from all administrative pages, see http://drupal.org/node/34970.
  92. $pages = array(
  93. 'admin*',
  94. 'user*',
  95. 'node/add*',
  96. 'node/*/*',
  97. );
  98. variable_set('googleanalytics_pages', implode("\n", $pages));
  99. return t('Added page tracking to every page except the listed pages: @pages.', array('@pages' => implode(', ', $pages)));
  100. }
  101. /**
  102. * Upgrade role settings and per user tracking settings
  103. * of "User 1" and remove outdated tracking variables.
  104. */
  105. function googleanalytics_update_6002() {
  106. // Upgrade enabled/disabled roles to new logic (correct for upgrades from 5.x-1.4 and 6.x-1.0).
  107. $roles = array();
  108. $messages = array();
  109. foreach (user_roles() as $rid => $name) {
  110. if (variable_get('googleanalytics_track_' . $rid, FALSE)) {
  111. // Role ID is activated for user tracking.
  112. $roles[$rid] = $rid;
  113. $messages[] = t('Enabled page tracking for role: @name.', array('@name' => $name));
  114. }
  115. else {
  116. $messages[] = t('Disabled page tracking for role: @name.', array('@name' => $name));
  117. }
  118. }
  119. variable_set('googleanalytics_roles', $roles);
  120. // Upgrade disabled tracking of "user 1" to new logic.
  121. if (!$track_user1 = variable_get('googleanalytics_track__user1', 1)) {
  122. variable_set('googleanalytics_custom', 1);
  123. // Load user 1 object, set appropriate value and save new user settings back.
  124. $account = user_load(1);
  125. $account = user_save($account, array('data' => array('googleanalytics' => array('custom' => 0))), 'account');
  126. $messages[] = t('Disabled user specific page tracking for site administrator.');
  127. }
  128. // Delete outdated tracking settings.
  129. db_delete('variable')
  130. ->condition('name', db_like('googleanalytics_track_') . '%', 'LIKE')
  131. ->execute();
  132. return implode(', ', $messages);
  133. }
  134. /**
  135. * #262468: Clear menu cache to solve stale menu data in 5.x-1.5 and 6.x-1.1
  136. */
  137. function googleanalytics_update_6003() {
  138. menu_rebuild();
  139. return t('Menu has been rebuild.');
  140. }
  141. /**
  142. * Change visibility setting for path "user/*".
  143. */
  144. function googleanalytics_update_6004() {
  145. // Original pages setting.
  146. $pages = array(
  147. 'admin*',
  148. 'user*',
  149. 'node/add*',
  150. 'node/*/*',
  151. );
  152. $diff = array_diff($pages, preg_split('/(\r\n?|\n)/', variable_get('googleanalytics_pages', implode("\n", $pages))));
  153. if (empty($diff)) {
  154. // No diff to original settings found. Update with new settings.
  155. $pages = array(
  156. 'admin*',
  157. 'user/*/*',
  158. 'node/add*',
  159. 'node/*/*',
  160. );
  161. variable_set('googleanalytics_pages', implode("\n", $pages));
  162. return t('Path visibility filter setting changed from "user*" to "user/*/*".');
  163. }
  164. else {
  165. return t('Custom path visibility filter setting found. Update skipped!');
  166. }
  167. }
  168. /**
  169. * Change visibility setting for path "admin*".
  170. */
  171. function googleanalytics_update_6005() {
  172. // Original pages setting.
  173. $pages = array(
  174. 'admin*',
  175. 'user/*/*',
  176. 'node/add*',
  177. 'node/*/*',
  178. );
  179. $diff = array_diff($pages, preg_split('/(\r\n?|\n)/', variable_get('googleanalytics_pages', implode("\n", $pages))));
  180. if (empty($diff)) {
  181. // No diff to original settings found. Update with new settings.
  182. $pages = array(
  183. 'admin',
  184. 'admin/*',
  185. 'user/*/*',
  186. 'node/add*',
  187. 'node/*/*',
  188. );
  189. variable_set('googleanalytics_pages', implode("\n", $pages));
  190. return t('Path visibility filter setting changed from "admin*" to "admin" and "admin/*".');
  191. }
  192. else {
  193. return t('Custom path visibility filter setting found. Update skipped!');
  194. }
  195. }
  196. /**
  197. * Upgrade custom javascript settings.
  198. */
  199. function googleanalytics_update_6006() {
  200. variable_set('googleanalytics_codesnippet_before', variable_get('googleanalytics_codesnippet', ''));
  201. variable_del('googleanalytics_codesnippet');
  202. return t('Upgraded custom javascript codesnippet setting.');
  203. }
  204. /**
  205. * Remove "User identifier" and "User name" from segmentation fields.
  206. *
  207. * This is a data protection and privacy law change. For more information see Google Analytics
  208. * terms of use section 8.1 (http://www.google.com/analytics/en-GB/tos.html).
  209. */
  210. function googleanalytics_update_6007() {
  211. $profile_fields = variable_get('googleanalytics_segmentation', array());
  212. unset($profile_fields['uid']);
  213. unset($profile_fields['name']);
  214. variable_set('googleanalytics_segmentation', $profile_fields);
  215. return t('Removed "User identifier" and "User name" from segmentation fields.');
  216. }
  217. /**
  218. * Remove outdated legacy support variables and files.
  219. */
  220. function googleanalytics_update_6200() {
  221. $path = 'public://googleanalytics';
  222. if (file_exists($path)) {
  223. file_unmanaged_delete($path . '/urchin.js');
  224. }
  225. variable_del('googleanalytics_legacy_version');
  226. return t('Removed outdated legacy tracker stuff.');
  227. }
  228. /**
  229. * Update list of default file extensions.
  230. */
  231. function googleanalytics_update_6201() {
  232. if (variable_get('googleanalytics_trackfiles_extensions', '') == '7z|aac|avi|csv|doc|exe|flv|gif|gz|jpe?g|js|mp(3|4|e?g)|mov|pdf|phps|png|ppt|rar|sit|tar|torrent|txt|wma|wmv|xls|xml|zip') {
  233. variable_set('googleanalytics_trackfiles_extensions', '7z|aac|arc|arj|asf|asx|avi|bin|csv|doc|exe|flv|gif|gz|gzip|hqx|jar|jpe?g|js|mp(2|3|4|e?g)|mov(ie)?|msi|msp|pdf|phps|png|ppt|qtm?|ra(m|r)?|sea|sit|tar|tgz|torrent|txt|wav|wma|wmv|wpd|xls|xml|z|zip');
  234. }
  235. return t('The default extensions for download tracking have been updated.');
  236. }
  237. /**
  238. * Try to update Google Analytics custom code snippet to async version.
  239. */
  240. function googleanalytics_update_6300() {
  241. $messages = array();
  242. // TODO: Backup synchronous code snippets. Remove variables in D8.
  243. variable_set('googleanalytics_codesnippet_before_backup_6300', variable_get('googleanalytics_codesnippet_before', ''));
  244. variable_set('googleanalytics_codesnippet_after_backup_6300', variable_get('googleanalytics_codesnippet_after', ''));
  245. // Upgrade of BEFORE code snippet.
  246. $code_before = variable_get('googleanalytics_codesnippet_before', '');
  247. if (!empty($code_before)) {
  248. // No value, e.g. _setLocalRemoteServerMode()
  249. $code_before = preg_replace('/(.*)pageTracker\.(\w+)\(\);(.*)/i', '$1_gaq.push(["$2"]);$3', $code_before);
  250. // One value, e.g. _setCookiePath()
  251. $code_before = preg_replace('/(.*)pageTracker\.(\w+)\(("|\'?)(\w+)("|\'?)\);(.*)/i', '$1_gaq.push(["$2", $3$4$5]);$6', $code_before);
  252. // Multiple values e.g. _trackEvent()
  253. $code_before = preg_replace('/(.*)pageTracker\.(\w+)\((.*)\);(.*)/i', '$1_gaq.push(["$2", $3]);$4', $code_before);
  254. variable_set('googleanalytics_codesnippet_before', $code_before);
  255. drupal_set_message(Database::getConnection()->prefixTables("<strong>Attempted</strong> to upgrade Google Analytics custom 'before' code snippet. Backup of previous code snippet has been saved in database table '{variable}' as 'googleanalytics_codesnippet_before_backup_6300'. Please consult Google's <a href='https://developers.google.com/analytics/devguides/collection/gajs/'>Asynchronous Tracking Usage Guide</a> if the upgrade was successfully."), 'warning');
  256. $messages[] = t('Upgraded custom "before" code snippet.');
  257. }
  258. // Upgrade of AFTER code snippet.
  259. // We cannot update this code snippet automatically. Show message that the upgrade has been skipped.
  260. $code_after = variable_get('googleanalytics_codesnippet_after', '');
  261. if (!empty($code_after)) {
  262. drupal_set_message(Database::getConnection()->prefixTables("Automatic upgrade of Google Analytics custom 'after' code snippet has been skipped. Backup of previous code snippet has been saved in database table '{variable}' as 'googleanalytics_codesnippet_after_backup_6300'. You need to manually upgrade the custom 'after' code snippet."), 'error');
  263. $messages[] = t('Skipped custom "after" code snippet.');
  264. }
  265. return empty($messages) ? t('No custom code snipped found. Nothing to do.') : implode(' ', $messages);
  266. }
  267. /**
  268. * Run D6 -> D7 upgrades.
  269. */
  270. function googleanalytics_update_7000() {
  271. // Update JavaScript scope to 'header'.
  272. variable_set('googleanalytics_js_scope', 'header');
  273. $messages[] = t('Google tracking code has been moved to header.');
  274. // Upgrade D6 token placeholder to D7. update_6301 is not required.
  275. $googleanalytics_custom_vars = variable_get('googleanalytics_custom_var', array());
  276. if (!empty($googleanalytics_custom_vars['slots'][1]) && $googleanalytics_custom_vars['slots'][1]['name'] == 'User roles' && $googleanalytics_custom_vars['slots'][1]['value'] = '[user-role-names]') {
  277. $googleanalytics_custom_vars['slots'][1]['value'] = '[current-user:role-names]';
  278. variable_set('googleanalytics_custom_var', $googleanalytics_custom_vars);
  279. $messages[] = t("The D6 token placeholder [user-role-names] used in the custom variable 'User roles' has been replaced with [current-user:role-names].");
  280. }
  281. return implode(' ', $messages);
  282. }
  283. /**
  284. * Automatically enable anonymizing of IP addresses for Germany.
  285. */
  286. function googleanalytics_update_7001() {
  287. // By German law it's always best to enable the anonymizing of IP addresses.
  288. $countries = array(
  289. 'DE',
  290. );
  291. if (in_array(variable_get('site_default_country', ''), $countries)) {
  292. variable_set('googleanalytics_tracker_anonymizeip', 1);
  293. return t('The default country in your regional settings is Germany. Anonymizing of IP addresses has been enabled for privacy reasons.');
  294. }
  295. else {
  296. return t('The default country in your regional settings is <em>not</em> Germany. The anonymizing of IP addresses setting has not been changed. Make sure your site settings comply with the local privacy rules.');
  297. }
  298. }
  299. /**
  300. * Upgrade "User roles" tracking to custom variables.
  301. */
  302. function googleanalytics_update_7002() {
  303. // Read previous segmentation settings.
  304. $segmentation = variable_get('googleanalytics_segmentation', array());
  305. // If this is an upgrade from D6 the slot 1 may not empty.
  306. if (empty($googleanalytics_custom_vars['slots'][1]) && in_array('roles', $segmentation)) {
  307. // Upgrade previous segmentation settings to new custom variables settings.
  308. $googleanalytics_custom_vars = variable_get('googleanalytics_custom_var', array());
  309. $googleanalytics_custom_vars['slots'][1]['slot'] = 1;
  310. $googleanalytics_custom_vars['slots'][1]['name'] = 'User roles';
  311. $googleanalytics_custom_vars['slots'][1]['value'] = '[current-user:role-names]';
  312. $googleanalytics_custom_vars['slots'][1]['scope'] = 1; // Sets the scope to visitor-level.
  313. variable_set('googleanalytics_custom_var', $googleanalytics_custom_vars);
  314. return 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/config/system/googleanalytics')));
  315. }
  316. else {
  317. return 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/config/system/googleanalytics')));
  318. }
  319. }
  320. /**
  321. * Rename googleanalytics_trackoutgoing variable to googleanalytics_trackoutbound.
  322. */
  323. function googleanalytics_update_7003() {
  324. variable_set('googleanalytics_trackoutbound', variable_get('googleanalytics_trackoutgoing', 1));
  325. variable_del('googleanalytics_trackoutgoing');
  326. return t('Renamed "googleanalytics_trackoutgoing" settings variable to googleanalytics_trackoutbound.');
  327. }
  328. /**
  329. * Rename googleanalytics_visibility variable to googleanalytics_visibility_pages for consistency.
  330. */
  331. function googleanalytics_update_7004() {
  332. variable_set('googleanalytics_visibility_pages', variable_get('googleanalytics_visibility', 1));
  333. variable_del('googleanalytics_visibility');
  334. return t('Renamed "googleanalytics_visibility" settings variable to googleanalytics_visibility_pages.');
  335. }
  336. /**
  337. * Path visibility filter setting should hide "batch" path.
  338. */
  339. function googleanalytics_update_7005() {
  340. // Current pages setting.
  341. $pages = array(
  342. 'admin',
  343. 'admin/*',
  344. 'user/*/*',
  345. 'node/add*',
  346. 'node/*/*',
  347. );
  348. $diff = array_diff($pages, preg_split('/(\r\n?|\n)/', variable_get('googleanalytics_pages', implode("\n", $pages))));
  349. if (empty($diff)) {
  350. // No diff to previous settings found. Update with new settings.
  351. $pages = array(
  352. 'admin',
  353. 'admin/*',
  354. 'batch',
  355. 'node/add*',
  356. 'node/*/*',
  357. 'user/*/*',
  358. );
  359. variable_set('googleanalytics_pages', implode("\n", $pages));
  360. return t('Added "batch" to path visibility filter setting.');
  361. }
  362. else {
  363. return t('Custom path visibility filter setting found. Update skipped!');
  364. }
  365. }
  366. /**
  367. * Delete obsolete trackOutboundAsPageview variable.
  368. */
  369. function googleanalytics_update_7006() {
  370. variable_del('googleanalytics_trackoutboundaspageview');
  371. return t('Deleted obsolete trackOutboundAsPageview variable.');
  372. }
  373. /**
  374. * Delete obsolete googleanalytics_trackpageloadtime variable.
  375. */
  376. function googleanalytics_update_7007() {
  377. variable_del('googleanalytics_trackpageloadtime');
  378. return t('Deleted obsolete googleanalytics_trackpageloadtime variable.');
  379. }
  380. /**
  381. * Delete custom ga.js code snipptes to prevent malfunctions in new Universal Analytics tracker. A backup of your snippets will be created.
  382. */
  383. function googleanalytics_update_7200() {
  384. $messages = array();
  385. // ga.js code will cause the tracker to break. Remove custom code snippets.
  386. $googleanalytics_codesnippet_before = variable_get('googleanalytics_codesnippet_before', '');
  387. if (!empty($googleanalytics_codesnippet_before) && stristr($googleanalytics_codesnippet_before, '_gaq.push(')) {
  388. variable_set('googleanalytics_codesnippet_before_backup_7200', $googleanalytics_codesnippet_before);
  389. variable_del('googleanalytics_codesnippet_before');
  390. drupal_set_message(Database::getConnection()->prefixTables("A backup of your previous Google Analytics code snippet has been saved in database table '{variable}' as 'googleanalytics_codesnippet_before_backup_7200'. You need to manually upgrade the custom 'before' code snippet."), 'warning');
  391. $messages[] = t('Manual upgrade of custom "before" code snippet is required.');
  392. }
  393. $googleanalytics_codesnippet_after = variable_get('googleanalytics_codesnippet_after', '');
  394. if (!empty($googleanalytics_codesnippet_after) && stristr($googleanalytics_codesnippet_after, '_gaq.push(')) {
  395. variable_set('googleanalytics_codesnippet_after_backup_7200', $googleanalytics_codesnippet_after);
  396. variable_del('googleanalytics_codesnippet_after');
  397. drupal_set_message(Database::getConnection()->prefixTables("A backup of your previous Google Analytics code snippet has been saved in database table '{variable}' as 'googleanalytics_codesnippet_before_backup_7200'. You need to manually upgrade the custom 'before' code snippet."), 'warning');
  398. $messages[] = t('Manual upgrade of custom "after" code snippet is required.');
  399. }
  400. return empty($messages) ? t('No custom code snipped found. Nothing to do.') : implode(' ', $messages);
  401. }
  402. /**
  403. * Delete obsolete custom variables. Custom variables are now custom dimensions and metrics.
  404. */
  405. function googleanalytics_update_7201() {
  406. variable_del('googleanalytics_custom_var');
  407. return t('Deleted obsolete custom variables. Custom variables are now custom dimensions and metrics and you need to manually configure them!');
  408. }
  409. /**
  410. * Delete obsolete JavaScript scope variable.
  411. */
  412. function googleanalytics_update_7202() {
  413. // Remove obsolete scope variable
  414. variable_del('googleanalytics_js_scope');
  415. return t('Removed obsolete JavaScript scope variable.');
  416. }
  417. /**
  418. * Flatten the metrics and dimensions arrays.
  419. */
  420. function googleanalytics_update_7203() {
  421. $googleanalytics_custom_dimension = variable_get('googleanalytics_custom_dimension', array());
  422. if (isset($googleanalytics_custom_dimension['indexes'])) {
  423. foreach ($googleanalytics_custom_dimension['indexes'] as $dimension) {
  424. $googleanalytics_custom_dimension['indexes'][$dimension['index']]['value'] = trim($dimension['value']);
  425. // Remove empty values from the array.
  426. if (!drupal_strlen($googleanalytics_custom_dimension['indexes'][$dimension['index']]['value'])) {
  427. unset($googleanalytics_custom_dimension['indexes'][$dimension['index']]);
  428. }
  429. }
  430. variable_set('googleanalytics_custom_dimension', $googleanalytics_custom_dimension['indexes']);
  431. }
  432. $googleanalytics_custom_metric = variable_get('googleanalytics_custom_metric', array());
  433. if (isset($googleanalytics_custom_metric['indexes'])) {
  434. foreach ($googleanalytics_custom_metric['indexes'] as $dimension) {
  435. $googleanalytics_custom_metric['indexes'][$dimension['index']]['value'] = trim($dimension['value']);
  436. // Remove empty values from the array.
  437. if (!drupal_strlen($googleanalytics_custom_metric['indexes'][$dimension['index']]['value'])) {
  438. unset($googleanalytics_custom_metric['indexes'][$dimension['index']]);
  439. }
  440. }
  441. variable_set('googleanalytics_custom_metric', $googleanalytics_custom_metric['indexes']);
  442. }
  443. return t('Saved custom dimensions and metrics.');
  444. }
  445. /**
  446. * Remove obsolete backup variables.
  447. */
  448. function googleanalytics_update_7204() {
  449. variable_del('googleanalytics_segmentation');
  450. variable_del('googleanalytics_codesnippet_after_backup_6300');
  451. variable_del('googleanalytics_codesnippet_before_backup_6300');
  452. variable_del('googleanalytics_codesnippet_after_backup_6400');
  453. variable_del('googleanalytics_codesnippet_before_backup_6400');
  454. return t('Removed obsolete backup variables.');
  455. }
  456. /**
  457. * Update list of default file extensions.
  458. */
  459. function googleanalytics_update_7205() {
  460. if (variable_get('googleanalytics_trackfiles_extensions', '') == '7z|aac|arc|arj|asf|asx|avi|bin|csv|doc|exe|flv|gif|gz|gzip|hqx|jar|jpe?g|js|mp(2|3|4|e?g)|mov(ie)?|msi|msp|pdf|phps|png|ppt|qtm?|ra(m|r)?|sea|sit|tar|tgz|torrent|txt|wav|wma|wmv|wpd|xls|xml|z|zip') {
  461. variable_set('googleanalytics_trackfiles_extensions', '7z|aac|arc|arj|asf|asx|avi|bin|csv|doc(x|m)?|dot(x|m)?|exe|flv|gif|gz|gzip|hqx|jar|jpe?g|js|mp(2|3|4|e?g)|mov(ie)?|msi|msp|pdf|phps|png|ppt(x|m)?|pot(x|m)?|pps(x|m)?|ppam|sld(x|m)?|thmx|qtm?|ra(m|r)?|sea|sit|tar|tgz|torrent|txt|wav|wma|wmv|wpd|xls(x|m|b)?|xlt(x|m)|xlam|xml|z|zip');
  462. return t('The default extensions for download tracking have been updated.');
  463. }
  464. else {
  465. return t('Custom extensions for download tracking setting found. Update skipped!');
  466. }
  467. }