googleanalytics.install 23 KB

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