googleanalytics.install 23 KB

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