Upgraded to D7
[project/google_analytics.git] / googleanalytics.install
1 <?php
2 // $Id$
3
4 /**
5 * @file
6 * Installation file for Google Analytics module.
7 */
8
9 function googleanalytics_install() {
10 variable_set('googleanalytics_visibility', 0);
11
12 // Remove tracking from all administrative pages, see http://drupal.org/node/34970.
13 $pages = array(
14 'admin',
15 'admin/*',
16 'user/*/*',
17 'node/add*',
18 'node/*/*',
19 );
20 variable_set('googleanalytics_pages', implode("\n", $pages));
21 }
22
23 function googleanalytics_uninstall() {
24 variable_del('googleanalytics_account');
25 variable_del('googleanalytics_codesnippet_before');
26 variable_del('googleanalytics_codesnippet_after');
27 variable_del('googleanalytics_segmentation');
28 variable_del('googleanalytics_trackoutgoing');
29 variable_del('googleanalytics_trackmailto');
30 variable_del('googleanalytics_trackfiles');
31 variable_del('googleanalytics_trackfiles_extensions');
32 variable_del('googleanalytics_cache');
33 variable_del('googleanalytics_last_cache');
34 variable_del('googleanalytics_site_search');
35 variable_del('googleanalytics_js_scope');
36 variable_del('googleanalytics_custom');
37 variable_del('googleanalytics_roles');
38 variable_del('googleanalytics_visibility');
39 variable_del('googleanalytics_pages');
40 variable_del('googleanalytics_translation_set');
41 }
42
43 /**
44 * Remove cache directory if module is disabled (or uninstalled).
45 */
46 function googleanalytics_disable() {
47 $path = file_directory_path() . '/googleanalytics';
48 if (file_exists($path)) {
49 file_directory_path($path . '/ga.js');
50 rmdir($path);
51 }
52 }
53
54
55 function googleanalytics_update_6000() {
56 $ret = array();
57
58 variable_set('googleanalytics_trackfiles_extensions', variable_get('googleanalytics_trackfiles', GA_TRACKFILES_EXTENSIONS));
59 $trackfiles = variable_get('googleanalytics_trackfiles', GA_TRACKFILES_EXTENSIONS) ? TRUE : FALSE;
60 variable_set('googleanalytics_trackfiles', $trackfiles);
61 $ret[] = array('success' => TRUE, 'query' => 'Updated download tracking settings.');
62
63 return $ret;
64 }
65
66 function googleanalytics_update_6001() {
67 $ret = array();
68
69 variable_set('googleanalytics_visibility', 0);
70
71 // Remove tracking from all administrative pages, see http://drupal.org/node/34970.
72 $pages = array(
73 'admin*',
74 'user*',
75 'node/add*',
76 'node/*/*',
77 );
78 variable_set('googleanalytics_pages', implode("\n", $pages));
79 $ret[] = array('success' => TRUE, 'query' => 'Added page tracking to every page except the listed pages: '. implode(', ', $pages));
80
81 return $ret;
82 }
83
84 /**
85 * Upgrade role settings and per user tracking settings
86 * of "User 1" and remove outdated tracking variables.
87 */
88 function googleanalytics_update_6002() {
89 $ret = array();
90
91 // Upgrade enabled/disabled roles to new logic (correct for upgrades from 5.x-1.4 and 6.x-1.0).
92 $roles = array();
93 foreach (user_roles() as $rid => $name) {
94 if (variable_get('googleanalytics_track_'. $rid, FALSE)) {
95 // Role ID is activated for user tracking.
96 $roles[$rid] = $rid;
97 $ret[] = array('success' => TRUE, 'query' => 'Enabled page tracking for role: ' . $name);
98 }
99 else {
100 $ret[] = array('success' => TRUE, 'query' => 'Disabled page tracking for role: ' . $name);
101 }
102 }
103 variable_set('googleanalytics_roles', $roles);
104
105 // Upgrade disabled tracking of "user 1" to new logic.
106 if (!$track_user1 = variable_get('googleanalytics_track__user1', 1)) {
107 variable_set('googleanalytics_custom', 1);
108
109 // Load user 1 object, set appropiate value and save new user settings back.
110 $account = user_load(array('uid' => 1));
111 $account = user_save($account, array('googleanalytics' => array('custom' => 0)), 'account');
112 $ret[] = array('success' => TRUE, 'query' => 'Disabled user specific page tracking for website administrator.');
113 }
114
115 // Delete outdated tracking settings.
116 $ret[] = update_sql("DELETE FROM {variable} WHERE name LIKE 'googleanalytics_track_%'");
117
118 return $ret;
119 }
120
121 /**
122 * #262468: Clear menu cache to solve stale menu data in 5.x-1.5 and 6.x-1.1
123 */
124 function googleanalytics_update_6003() {
125 $ret = array();
126 menu_rebuild();
127 return $ret;
128 }
129
130 /**
131 * Change visibility setting for path "user/*".
132 */
133 function googleanalytics_update_6004() {
134 $ret = array();
135
136 // Orginal pages setting.
137 $pages = array(
138 'admin*',
139 'user*',
140 'node/add*',
141 'node/*/*',
142 );
143
144 $diff = array_diff($pages, preg_split('/(\r\n?|\n)/', variable_get('googleanalytics_pages', implode("\n", $pages))));
145 if (empty($diff)) {
146 // No diff to original settings found. Update with new settings.
147 $pages = array(
148 'admin*',
149 'user/*/*',
150 'node/add*',
151 'node/*/*',
152 );
153 variable_set('googleanalytics_pages', implode("\n", $pages));
154 $ret[] = array('success' => TRUE, 'query' => 'Path visibility filter setting changed from "user*" to "user/*/*".');
155 }
156 else {
157 $ret[] = array('success' => TRUE, 'query' => 'Custom path visibility filter setting found. Update skipped!');
158 }
159
160 return $ret;
161 }
162
163 /**
164 * Change visibility setting for path "admin*".
165 */
166 function googleanalytics_update_6005() {
167 $ret = array();
168
169 // Orginal pages setting.
170 $pages = array(
171 'admin*',
172 'user/*/*',
173 'node/add*',
174 'node/*/*',
175 );
176
177 $diff = array_diff($pages, preg_split('/(\r\n?|\n)/', variable_get('googleanalytics_pages', implode("\n", $pages))));
178 if (empty($diff)) {
179 // No diff to original settings found. Update with new settings.
180 $pages = array(
181 'admin',
182 'admin/*',
183 'user/*/*',
184 'node/add*',
185 'node/*/*',
186 );
187 variable_set('googleanalytics_pages', implode("\n", $pages));
188 $ret[] = array('success' => TRUE, 'query' => 'Path visibility filter setting changed from "admin*" to "admin" and "admin/*".');
189 }
190 else {
191 $ret[] = array('success' => TRUE, 'query' => 'Custom path visibility filter setting found. Update skipped!');
192 }
193
194 return $ret;
195 }
196
197 /**
198 * Upgrade custom javascript settings.
199 */
200 function googleanalytics_update_6006() {
201 $ret = array();
202
203 variable_set('googleanalytics_codesnippet_before', variable_get('googleanalytics_codesnippet', ''));
204 variable_del('googleanalytics_codesnippet');
205 $ret[] = array('success' => TRUE, 'query' => 'Upgraded custom javascript codesnippet setting.');
206
207 return $ret;
208 }
209
210 /**
211 * Remove "User identifier" and "User name" from segmentation fields.
212 *
213 * This is a data protection and privacy law change. For more information see Google Analytics
214 * terms of use section 8.1 (http://www.google.com/analytics/en-GB/tos.html).
215 */
216 function googleanalytics_update_6007() {
217 $ret = array();
218
219 $profile_fields = variable_get('googleanalytics_segmentation', array());
220 unset($profile_fields['uid']);
221 unset($profile_fields['name']);
222 variable_set('googleanalytics_segmentation', $profile_fields);
223 $ret[] = array('success' => TRUE, 'query' => 'Removed "User identifier" and "User name" from segmentation fields.');
224
225 return $ret;
226 }
227
228 /**
229 * Remove outdated legacy support variables and files.
230 */
231 function googleanalytics_update_6200() {
232 $ret = array();
233
234 $path = file_directory_path() .'/googleanalytics';
235 if (file_exists($path)) {
236 file_delete($path .'/urchin.js');
237 }
238 variable_del('googleanalytics_legacy_version');
239
240 $ret[] = array('success' => TRUE, 'query' => 'Removed legacy support.');
241
242 return $ret;
243 }