LEFT | RIGHT |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | 2 # -*- coding: utf-8 -*- |
3 # | 3 # |
4 # Copyright 2011 Google Inc. All Rights Reserved. | 4 # Copyright 2012 Google Inc. All Rights Reserved. |
5 # | 5 # |
6 # Licensed under the Apache License, Version 2.0 (the "License"); | 6 # Licensed under the Apache License, Version 2.0 (the "License"); |
7 # you may not use this file except in compliance with the License. | 7 # you may not use this file except in compliance with the License. |
8 # You may obtain a copy of the License at | 8 # You may obtain a copy of the License at |
9 # | 9 # |
10 # http://www.apache.org/licenses/LICENSE-2.0 | 10 # http://www.apache.org/licenses/LICENSE-2.0 |
11 # | 11 # |
12 # Unless required by applicable law or agreed to in writing, software | 12 # Unless required by applicable law or agreed to in writing, software |
13 # distributed under the License is distributed on an "AS IS" BASIS, | 13 # distributed under the License is distributed on an "AS IS" BASIS, |
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
(...skipping 10 matching lines...) Expand all Loading... |
25 Google Analytics Management hiearchy. It first retrieves and prints all the | 25 Google Analytics Management hiearchy. It first retrieves and prints all the |
26 authorized user's accounts, next it prints all the web properties for the | 26 authorized user's accounts, next it prints all the web properties for the |
27 first account, then all the profiles for the first web property and finally | 27 first account, then all the profiles for the first web property and finally |
28 all the goals for the first profile. The sample then prints all the | 28 all the goals for the first profile. The sample then prints all the |
29 user's advanced segments. | 29 user's advanced segments. |
30 | 30 |
31 To read an indepth discussion on how this file works, check out the Management | 31 To read an indepth discussion on how this file works, check out the Management |
32 API Python Getting Started guide here: | 32 API Python Getting Started guide here: |
33 http://code.google.com/apis/analytics/docs/mgmt/v3/mgmtPython.html | 33 http://code.google.com/apis/analytics/docs/mgmt/v3/mgmtPython.html |
34 | 34 |
35 Usage: | 35 Before You Begin: |
36 | 36 |
37 Before you begin, you should register your application as an installed | 37 Update the client_secrets.json file |
38 application to get your own Project / OAUth2 Client ID / Secret: | 38 |
39 https://code.google.com/apis/console | 39 You must update the clients_secrets.json file with a client id, client |
40 | 40 secret, and the redirect uri. You get these values by creating a new project |
41 Learn more about registering your Analytics Application here: | 41 in the Google APIs console and registering for OAuth2.0 for installed |
42 http://code.google.com/apis/analytics/docs/mgmt/v3/mgmtPython.html#authorize | 42 applications: https://code.google.com/apis/console |
43 | 43 |
44 $ python analytics.py | 44 Learn more about registering your analytics application here: |
| 45 http://code.google.com/apis/analytics/docs/gdata/v3/gdataAuthorization.html |
| 46 |
| 47 Sample Usage: |
| 48 |
| 49 $ python management_v3_reference.py |
45 | 50 |
46 Also you can also get help on all the command-line flags the program | 51 Also you can also get help on all the command-line flags the program |
47 understands by running: | 52 understands by running: |
48 | 53 |
49 $ python analytics.py --help | 54 $ python management_v3_reference.py --help |
50 """ | 55 """ |
51 | 56 |
52 __author__ = 'api.nickm@ (Nick Mihailovski)' | 57 __author__ = 'api.nickm@gmail.com (Nick Mihailovski)' |
53 | 58 |
54 import sys | 59 import sys |
55 | 60 import sample_utils |
56 from apiclient.discovery import build | 61 |
57 from apiclient.errors import HttpError | 62 from apiclient.errors import HttpError |
58 | |
59 import gflags | |
60 import httplib2 | |
61 | |
62 from oauth2client.client import AccessTokenRefreshError | 63 from oauth2client.client import AccessTokenRefreshError |
63 from oauth2client.client import OAuth2WebServerFlow | |
64 from oauth2client.file import Storage | |
65 from oauth2client.tools import run | |
66 | |
67 FLAGS = gflags.FLAGS | |
68 | |
69 | |
70 # Remember to get your own client_id / client_secret in the | |
71 # Google API developer console: https://code.google.com/apis/console | |
72 FLOW = OAuth2WebServerFlow( | |
73 client_id='INSERT_YOUR_CLIENT_ID_HERE', | |
74 client_secret='INSERT_YOUR_CLIENT_SECRET_HERE', | |
75 scope='https://www.googleapis.com/auth/analytics.readonly', | |
76 user_agent='analytics-api-v3-awesomeness') | |
77 | |
78 TOKEN_FILE_NAME = 'analytics.dat' | |
79 | 64 |
80 | 65 |
81 def main(argv): | 66 def main(argv): |
82 # Let the gflags module process the command-line arguments | 67 sample_utils.process_flags(argv) |
83 try: | 68 |
84 argv = FLAGS(argv) | 69 # Authenticate and construct service. |
85 except gflags.FlagsError, e: | 70 service = sample_utils.initialize_service() |
86 print '%s\\nUsage: %s ARGS\\n%s' % (e, argv[0], FLAGS) | 71 |
87 sys.exit(1) | 72 # Traverse the Management hiearchy and print results or handle errors. |
88 | |
89 # Manage re-using tokens. | |
90 storage = Storage(TOKEN_FILE_NAME) | |
91 credentials = storage.get() | |
92 if not credentials or credentials.invalid: | |
93 # Get a new token. | |
94 credentials = run(FLOW, storage) | |
95 | |
96 # Build an authorized service object. | |
97 http = httplib2.Http() | |
98 http = credentials.authorize(http) | |
99 service = build('analytics', 'v3', http=http) | |
100 | |
101 # Traverse the Management hiearchy and print results. | |
102 try: | 73 try: |
103 traverse_hiearchy(service) | 74 traverse_hiearchy(service) |
104 | 75 |
| 76 except TypeError, error: |
| 77 # Handle errors in constructing a query. |
| 78 print ('There was an error in constructing your query : %s' % error) |
| 79 |
105 except HttpError, error: | 80 except HttpError, error: |
106 print ('Arg, there was an API error : %s %s : %s' % | 81 # Handle API errors. |
107 (error.resp.status, error.resp.reason, error._get_reason())) | 82 print ('Arg, there was an API error : %s : %s' % |
| 83 (error.resp.status, error._get_reason())) |
108 | 84 |
109 except AccessTokenRefreshError: | 85 except AccessTokenRefreshError: |
110 print ('The credentials have been revoked or expired, please re-run' | 86 print ('The credentials have been revoked or expired, please re-run' |
111 'the application to re-authorize') | 87 'the application to re-authorize') |
112 | 88 |
113 | 89 |
114 def traverse_hiearchy(service): | 90 def traverse_hiearchy(service): |
115 """Traverses the management API hiearchy and prints results. | 91 """Traverses the management API hiearchy and prints results. |
116 | 92 |
117 This retrieves and prints the authorized user's accounts. It then | 93 This retrieves and prints the authorized user's accounts. It then |
118 retrieves and prints all the web properties for the first account, | 94 retrieves and prints all the web properties for the first account, |
119 retrieves and prints all the profiles for the first web property, | 95 retrieves and prints all the profiles for the first web property, |
120 and retrieves and prints all the goals for the first profile. | 96 and retrieves and prints all the goals for the first profile. |
121 | 97 |
122 Args: | 98 Args: |
123 service: The service object built by the Google API Python client library. | 99 service: The service object built by the Google API Python client library. |
124 | 100 |
125 Raises: | 101 Raises: |
126 HttpError: If an error occured when accessing the API. | 102 HttpError: If an error occured when accessing the API. |
127 AccessTokenRefreshError: If the current token was invalid. | 103 AccessTokenRefreshError: If the current token was invalid. |
128 """ | 104 """ |
129 view = View() | |
130 | 105 |
131 accounts = service.management().accounts().list().execute() | 106 accounts = service.management().accounts().list().execute() |
132 | 107 print_accounts(accounts) |
133 view.print_accounts(accounts) | |
134 | 108 |
135 if accounts.get('items'): | 109 if accounts.get('items'): |
136 firstAccountId = accounts.get('items')[0].get('id') | 110 firstAccountId = accounts.get('items')[0].get('id') |
137 webproperties = service.management().webproperties().list( | 111 webproperties = service.management().webproperties().list( |
138 accountId=firstAccountId).execute() | 112 accountId=firstAccountId).execute() |
139 | 113 |
140 view.print_webproperties(webproperties) | 114 print_webproperties(webproperties) |
141 | 115 |
142 if webproperties.get('items'): | 116 if webproperties.get('items'): |
143 firstWebpropertyId = webproperties.get('items')[0].get('id') | 117 firstWebpropertyId = webproperties.get('items')[0].get('id') |
144 profiles = service.management().profiles().list( | 118 profiles = service.management().profiles().list( |
145 accountId=firstAccountId, | 119 accountId=firstAccountId, |
146 webPropertyId=firstWebpropertyId).execute() | 120 webPropertyId=firstWebpropertyId).execute() |
147 | 121 |
148 view.print_profiles(profiles) | 122 print_profiles(profiles) |
149 | 123 |
150 if profiles.get('items'): | 124 if profiles.get('items'): |
151 firstProfileId = profiles.get('items')[0].get('id') | 125 firstProfileId = profiles.get('items')[0].get('id') |
152 goals = service.management().goals().list( | 126 goals = service.management().goals().list( |
153 accountId=firstAccountId, | 127 accountId=firstAccountId, |
154 webPropertyId=firstWebpropertyId, | 128 webPropertyId=firstWebpropertyId, |
155 profileId=firstProfileId).execute() | 129 profileId=firstProfileId).execute() |
156 | 130 |
157 view.print_goals(goals) | 131 print_goals(goals) |
158 | 132 |
159 view.print_segments(service.management().segments().list().execute()) | 133 print_segments(service.management().segments().list().execute()) |
160 | 134 |
161 | 135 |
162 class View(object): | 136 def print_accounts(accounts_response): |
163 """Utility class to print various Management API collections.""" | 137 """Prints all the account info in the Accounts Collection. |
164 | 138 |
165 def print_accounts(self, accounts_list): | 139 Args: |
166 """Prints all the account info in the Accounts Collection.""" | 140 accounts_response: The response object returned from querying the Accounts |
167 | 141 collection. |
168 print '------ Account Collection -------' | 142 """ |
169 self.print_pagination_info(accounts_list) | 143 |
| 144 print '------ Account Collection -------' |
| 145 print_pagination_info(accounts_response) |
| 146 print |
| 147 |
| 148 for account in accounts_response.get('items', []): |
| 149 print 'Account ID = %s' % account.get('id') |
| 150 print 'Kind = %s' % account.get('kind') |
| 151 print 'Self Link = %s' % account.get('selfLink') |
| 152 print 'Account Name = %s' % account.get('name') |
| 153 print 'Created = %s' % account.get('created') |
| 154 print 'Updated = %s' % account.get('updated') |
| 155 |
| 156 child_link = account.get('childLink') |
| 157 print 'Child link href = %s' % child_link.get('href') |
| 158 print 'Child link type = %s' % child_link.get('type') |
170 print | 159 print |
171 | 160 else: |
172 for account in accounts_list.get('items'): | 161 print 'No accounts found.\n' |
173 print 'Account ID = %s' % account.get('id') | 162 |
174 print 'Kind = %s' % account.get('kind') | 163 |
175 print 'Self Link = %s' % account.get('selfLink') | 164 def print_webproperties(webproperties_response): |
176 print 'Account Name = %s' % account.get('name') | 165 """Prints all the web property info in the WebProperties collection. |
177 print 'Created = %s' % account.get('created') | 166 |
178 print 'Updated = %s' % account.get('updated') | 167 Args: |
179 | 168 webproperties_response: The response object returned from querying the |
180 child_link = account.get('childLink') | 169 Webproperties collection. |
181 print 'Child link href = %s' % child_link.get('href') | 170 """ |
182 print 'Child link type = %s' % child_link.get('type') | 171 |
183 print | 172 print '------ Web Properties Collection -------' |
184 | 173 print_pagination_info(webproperties_response) |
185 def print_webproperties(self, webproperties_list): | 174 print |
186 """Prints all the web property info in the WebProperties Collection.""" | 175 |
187 | 176 for webproperty in webproperties_response.get('items', []): |
188 print '------ Web Properties Collection -------' | 177 print 'Kind = %s' % webproperty.get('kind') |
189 self.print_pagination_info(webproperties_list) | 178 print 'Account ID = %s' % webproperty.get('accountId') |
| 179 print 'Web Property ID = %s' % webproperty.get('id') |
| 180 print ('Internal Web Property ID = %s' % |
| 181 webproperty.get('internalWebPropertyId')) |
| 182 |
| 183 print 'Website URL = %s' % webproperty.get('websiteUrl') |
| 184 print 'Created = %s' % webproperty.get('created') |
| 185 print 'Updated = %s' % webproperty.get('updated') |
| 186 |
| 187 print 'Self Link = %s' % webproperty.get('selfLink') |
| 188 parent_link = webproperty.get('parentLink') |
| 189 print 'Parent link href = %s' % parent_link.get('href') |
| 190 print 'Parent link type = %s' % parent_link.get('type') |
| 191 child_link = webproperty.get('childLink') |
| 192 print 'Child link href = %s' % child_link.get('href') |
| 193 print 'Child link type = %s' % child_link.get('type') |
190 print | 194 print |
191 | 195 else: |
192 for webproperty in webproperties_list.get('items'): | 196 print 'No webproperties found.\n' |
193 print 'Kind = %s' % webproperty.get('kind') | 197 |
194 print 'Account ID = %s' % webproperty.get('accountId') | 198 |
195 print 'Web Property ID = %s' % webproperty.get('id') | 199 def print_profiles(profiles_response): |
196 print ('Internal Web Property ID = %s' % | 200 """Prints all the profile info in the Profiles Collection. |
197 webproperty.get('internalWebPropertyId')) | 201 |
198 | 202 Args: |
199 print 'Website URL = %s' % webproperty.get('websiteUrl') | 203 profiles_response: The response object returned from querying the |
200 print 'Created = %s' % webproperty.get('created') | 204 Profiles collection. |
201 print 'Updated = %s' % webproperty.get('updated') | 205 """ |
202 | 206 |
203 print 'Self Link = %s' % webproperty.get('selfLink') | 207 print '------ Profiles Collection -------' |
204 parent_link = webproperty.get('parentLink') | 208 print_pagination_info(profiles_response) |
205 print 'Parent link href = %s' % parent_link.get('href') | 209 print |
206 print 'Parent link type = %s' % parent_link.get('type') | 210 |
207 child_link = webproperty.get('childLink') | 211 for profile in profiles_response.get('items', []): |
208 print 'Child link href = %s' % child_link.get('href') | 212 print 'Kind = %s' % profile.get('kind') |
209 print 'Child link type = %s' % child_link.get('type') | 213 print 'Account ID = %s' % profile.get('accountId') |
210 print | 214 print 'Web Property ID = %s' % profile.get('webPropertyId') |
211 | 215 print ('Internal Web Property ID = %s' % |
212 def print_profiles(self, profiles_list): | 216 profile.get('internalWebPropertyId')) |
213 """Prints all the profile info in the Profiles Collection.""" | 217 print 'Profile ID = %s' % profile.get('id') |
214 | 218 print 'Profile Name = %s' % profile.get('name') |
215 print '------ Profiles Collection -------' | 219 |
216 self.print_pagination_info(profiles_list) | 220 print 'Currency = %s' % profile.get('currency') |
| 221 print 'Timezone = %s' % profile.get('timezone') |
| 222 print 'Default Page = %s' % profile.get('defaultPage') |
| 223 |
| 224 print ('Exclude Query Parameters = %s' % |
| 225 profile.get('excludeQueryParameters')) |
| 226 print ('Site Search Category Parameters = %s' % |
| 227 profile.get('siteSearchCategoryParameters')) |
| 228 print ('Site Search Query Parameters = %s' % |
| 229 profile.get('siteSearchQueryParameters')) |
| 230 |
| 231 print 'Created = %s' % profile.get('created') |
| 232 print 'Updated = %s' % profile.get('updated') |
| 233 |
| 234 print 'Self Link = %s' % profile.get('selfLink') |
| 235 parent_link = profile.get('parentLink') |
| 236 print 'Parent link href = %s' % parent_link.get('href') |
| 237 print 'Parent link type = %s' % parent_link.get('type') |
| 238 child_link = profile.get('childLink') |
| 239 print 'Child link href = %s' % child_link.get('href') |
| 240 print 'Child link type = %s' % child_link.get('type') |
217 print | 241 print |
218 | 242 else: |
219 for profile in profiles_list.get('items'): | 243 print 'No profiles found.\n' |
220 print 'Kind = %s' % profile.get('kind') | 244 |
221 print 'Account ID = %s' % profile.get('accountId') | 245 |
222 print 'Web Property ID = %s' % profile.get('webPropertyId') | 246 def print_goals(goals_response): |
223 print ('Internal Web Property ID = %s' % | 247 """Prints all the goal info in the Goals collection. |
224 profile.get('internalWebPropertyId')) | 248 |
225 print 'Profile ID = %s' % profile.get('id') | 249 Args: |
226 print 'Profile Name = %s' % profile.get('name') | 250 goals_response: The response object returned from querying the Goals |
227 | 251 collection |
228 print 'Currency = %s' % profile.get('currency') | 252 """ |
229 print 'Timezone = %s' % profile.get('timezone') | 253 |
230 print 'Default Page = %s' % profile.get('defaultPage') | 254 print '------ Goals Collection -------' |
231 | 255 print_pagination_info(goals_response) |
232 print ('Exclude Query Parameters = %s' % | 256 print |
233 profile.get('excludeQueryParameters')) | 257 |
234 print ('Site Search Category Parameters = %s' % | 258 for goal in goals_response.get('items', []): |
235 profile.get('siteSearchCategoryParameters')) | 259 print 'Goal ID = %s' % goal.get('id') |
236 print ('Site Search Query Parameters = %s' % | 260 print 'Kind = %s' % goal.get('kind') |
237 profile.get('siteSearchQueryParameters')) | 261 print 'Self Link = %s' % goal.get('selfLink') |
238 | 262 |
239 print 'Created = %s' % profile.get('created') | 263 print 'Account ID = %s' % goal.get('accountId') |
240 print 'Updated = %s' % profile.get('updated') | 264 print 'Web Property ID = %s' % goal.get('webPropertyId') |
241 | 265 print ('Internal Web Property ID = %s' % |
242 print 'Self Link = %s' % profile.get('selfLink') | 266 goal.get('internalWebPropertyId')) |
243 parent_link = profile.get('parentLink') | 267 print 'Profile ID = %s' % goal.get('profileId') |
244 print 'Parent link href = %s' % parent_link.get('href') | 268 |
245 print 'Parent link type = %s' % parent_link.get('type') | 269 print 'Goal Name = %s' % goal.get('name') |
246 child_link = profile.get('childLink') | 270 print 'Goal Value = %s' % goal.get('value') |
247 print 'Child link href = %s' % child_link.get('href') | 271 print 'Goal Active = %s' % goal.get('active') |
248 print 'Child link type = %s' % child_link.get('type') | 272 print 'Goal Type = %s' % goal.get('type') |
249 print | 273 |
250 | 274 print 'Created = %s' % goal.get('created') |
251 def print_goals(self, goals_list): | 275 print 'Updated = %s' % goal.get('updated') |
252 """Prints all the goal info in the Goals Collection.""" | 276 |
253 | 277 parent_link = goal.get('parentLink') |
254 print '------ Goals Collection -------' | 278 print 'Parent link href = %s' % parent_link.get('href') |
255 self.print_pagination_info(goals_list) | 279 print 'Parent link type = %s' % parent_link.get('type') |
| 280 |
| 281 # Print the goal details depending on the type of goal. |
| 282 if goal.get('urlDestinationDetails'): |
| 283 print_url_destination_goal_details( |
| 284 goal.get('urlDestinationDetails')) |
| 285 |
| 286 elif goal.get('visitTimeOnSiteDetails'): |
| 287 print_visit_time_on_site_goal_details( |
| 288 goal.get('visitTimeOnSiteDetails')) |
| 289 |
| 290 elif goal.get('visitNumPagesDetails'): |
| 291 print_visit_num_pages_goal_details( |
| 292 goal.get('visitNumPagesDetails')) |
| 293 |
| 294 elif goal.get('eventDetails'): |
| 295 print_event_goal_details(goal.get('eventDetails')) |
| 296 |
256 print | 297 print |
257 | 298 else: |
258 for goal in goals_list.get('items'): | 299 print 'No goals found.\n' |
259 print 'Goal ID = %s' % goal.get('id') | 300 |
260 print 'Kind = %s' % goal.get('kind') | 301 |
261 print 'Self Link = %s' % goal.get('selfLink') | 302 def print_url_destination_goal_details(goal_details): |
262 | 303 """Prints all the URL Destination goal type info. |
263 print 'Account ID = %s' % goal.get('accountId') | 304 |
264 print 'Web Property ID = %s' % goal.get('webPropertyId') | 305 Args: |
265 print ('Internal Web Property ID = %s' % | 306 goal_details: The details portion of the goal response. |
266 goal.get('internalWebPropertyId')) | 307 """ |
267 print 'Profile ID = %s' % goal.get('profileId') | 308 |
268 | 309 print '------ Url Destination Goal -------' |
269 print 'Goal Name = %s' % goal.get('name') | 310 print 'Goal URL = %s' % goal_details.get('url') |
270 print 'Goal Value = %s' % goal.get('value') | 311 print 'Case Sensitive = %s' % goal_details.get('caseSensitive') |
271 print 'Goal Active = %s' % goal.get('active') | 312 print 'Match Type = %s' % goal_details.get('matchType') |
272 print 'Goal Type = %s' % goal.get('type') | 313 print 'First Step Required = %s' % goal_details.get('firstStepRequired') |
273 | 314 |
274 print 'Created = %s' % goal.get('created') | 315 print '------ Url Destination Goal Steps -------' |
275 print 'Updated = %s' % goal.get('updated') | 316 for goal_step in goal_details.get('steps', []): |
276 | 317 print 'Step Number = %s' % goal_step.get('number') |
277 parent_link = goal.get('parentLink') | 318 print 'Step Name = %s' % goal_step.get('name') |
278 print 'Parent link href = %s' % parent_link.get('href') | 319 print 'Step URL = %s' % goal_step.get('url') |
279 print 'Parent link type = %s' % parent_link.get('type') | 320 else: |
280 | 321 print 'No Steps Configured' |
281 # Print the goal details depending on the type of goal. | 322 |
282 if goal.get('urlDestinationDetails'): | 323 |
283 self.print_url_destination_goal_details( | 324 def print_visit_time_on_site_goal_details(goal_details): |
284 goal.get('urlDestinationDetails')) | 325 """Prints all the Visit Time On Site goal type info. |
285 | 326 |
286 elif goal.get('visitTimeOnSiteDetails'): | 327 Args: |
287 self.print_visit_time_on_site_goal_details( | 328 goal_details: The details portion of the goal response. |
288 goal.get('visitTimeOnSiteDetails')) | 329 """ |
289 | 330 |
290 elif goal.get('visitNumPagesDetails'): | 331 print '------ Visit Time On Site Goal -------' |
291 self.print_visit_num_pages_goal_details( | 332 print 'Comparison Type = %s' % goal_details.get('comparisonType') |
292 goal.get('visitNumPagesDetails')) | 333 print 'comparison Value = %s' % goal_details.get('comparisonValue') |
293 | 334 |
294 elif goal.get('eventDetails'): | 335 |
295 self.print_event_goal_details(goal.get('eventDetails')) | 336 def print_visit_num_pages_goal_details(goal_details): |
296 | 337 """Prints all the Visit Num Pages goal type info. |
297 print | 338 |
298 | 339 Args: |
299 def print_url_destination_goal_details(self, goal_details): | 340 goal_details: The details portion of the goal response. |
300 """Prints all the URL Destination goal type info.""" | 341 """ |
301 | 342 |
302 print '------ Url Destination Goal -------' | 343 print '------ Visit Num Pages Goal -------' |
303 print 'Goal URL = %s' % goal_details.get('url') | 344 print 'Comparison Type = %s' % goal_details.get('comparisonType') |
304 print 'Case Sensitive = %s' % goal_details.get('caseSensitive') | 345 print 'comparison Value = %s' % goal_details.get('comparisonValue') |
305 print 'Match Type = %s' % goal_details.get('matchType') | 346 |
306 print 'First Step Required = %s' % goal_details.get('firstStepRequired') | 347 |
307 | 348 def print_event_goal_details(goal_details): |
308 print '------ Url Destination Goal Steps -------' | 349 """Prints all the Event goal type info. |
309 if goal_details.get('steps'): | 350 |
310 for goal_step in goal_details.get('steps'): | 351 Args: |
311 print 'Step Number = %s' % goal_step.get('number') | 352 goal_details: The details portion of the goal response. |
312 print 'Step Name = %s' % goal_step.get('name') | 353 """ |
313 print 'Step URL = %s' % goal_step.get('url') | 354 |
314 else: | 355 print '------ Event Goal -------' |
315 print 'No Steps Configured' | 356 print 'Use Event Value = %s' % goal_details.get('useEventValue') |
316 | 357 |
317 def print_visit_time_on_site_goal_details(self, goal_details): | 358 for event_condition in goal_details.get('eventConditions', []): |
318 """Prints all the Visit Time On Site goal type info.""" | 359 event_type = event_condition.get('type') |
319 | 360 print 'Type = %s' % event_type |
320 print '------ Visit Time On Site Goal -------' | 361 |
321 print 'Comparison Type = %s' % goal_details.get('comparisonType') | 362 if event_type in ('CATEGORY', 'ACTION', 'LABEL'): |
322 print 'comparison Value = %s' % goal_details.get('comparisonValue') | 363 print 'Match Type = %s' % event_condition.get('matchType') |
323 | 364 print 'Expression = %s' % event_condition.get('expression') |
324 def print_visit_num_pages_goal_details(self, goal_details): | 365 else: # VALUE type. |
325 """Prints all the Visit Num Pages goal type info.""" | 366 print 'Comparison Type = %s' % event_condition.get('comparisonType') |
326 | 367 print 'Comparison Value = %s' % event_condition.get('comparisonValue') |
327 print '------ Visit Num Pages Goal -------' | 368 |
328 print 'Comparison Type = %s' % goal_details.get('comparisonType') | 369 |
329 print 'comparison Value = %s' % goal_details.get('comparisonValue') | 370 def print_segments(segments_response): |
330 | 371 """Prints all the segment info in the Segments collection. |
331 def print_event_goal_details(self, goal_details): | 372 |
332 """Prints all the Event goal type info.""" | 373 Args: |
333 | 374 segments_response: The response object returned from querying the |
334 print '------ Event Goal -------' | 375 Segments collection. |
335 print 'Use Event Value = %s' % goal_details.get('useEventValue') | 376 """ |
336 | 377 |
337 for event_condition in goal_details.get('eventConditions'): | 378 print '------ Segments Collection -------' |
338 event_type = event_condition.get('type') | 379 print_pagination_info(segments_response) |
339 print 'Type = %s' % event_type | 380 print |
340 | 381 |
341 if event_type in ('CATEGORY', 'ACTION', 'LABEL'): | 382 for segment in segments_response.get('items', []): |
342 print 'Match Type = %s' % event_condition.get('matchType') | 383 print 'Segment ID = %s' % segment.get('id') |
343 print 'Expression = %s' % event_condition.get('expression') | 384 print 'Kind = %s' % segment.get('kind') |
344 else: # VALUE type. | 385 print 'Self Link = %s' % segment.get('selfLink') |
345 print 'Comparison Type = %s' % event_condition.get('comparisonType') | 386 print 'Name = %s' % segment.get('name') |
346 print 'Comparison Value = %s' % event_condition.get('comparisonValue') | 387 print 'Definition = %s' % segment.get('definition') |
347 | 388 print 'Created = %s' % segment.get('created') |
348 def print_segments(self, segments_list): | 389 print 'Updated = %s' % segment.get('updated') |
349 """Prints all the segment info in the Segments Collection.""" | |
350 | |
351 print '------ Segments Collection -------' | |
352 self.print_pagination_info(segments_list) | |
353 print | 390 print |
354 | 391 |
355 for segment in segments_list.get('items'): | 392 |
356 print 'Segment ID = %s' % segment.get('id') | 393 def print_pagination_info(management_response): |
357 print 'Kind = %s' % segment.get('kind') | 394 """Prints common pagination details. |
358 print 'Self Link = %s' % segment.get('selfLink') | 395 |
359 print 'Name = %s' % segment.get('name') | 396 Args: |
360 print 'Definition = %s' % segment.get('definition') | 397 management_response: The common reponse object for each collection in the |
361 print 'Created = %s' % segment.get('created') | 398 Management API. |
362 print 'Updated = %s' % segment.get('updated') | 399 """ |
363 print | 400 |
364 | 401 print 'Items per page = %s' % management_response.get('itemsPerPage') |
365 def print_pagination_info(self, mgmt_list): | 402 print 'Total Results = %s' % management_response.get('totalResults') |
366 """Prints common pagination details.""" | 403 print 'Start Index = %s' % management_response.get('startIndex') |
367 | 404 |
368 print 'Items per page = %s' % mgmt_list.get('itemsPerPage') | 405 # These only have values if other result pages exist. |
369 print 'Total Results = %s' % mgmt_list.get('totalResults') | 406 if management_response.get('previousLink'): |
370 print 'Start Index = %s' % mgmt_list.get('startIndex') | 407 print 'Previous Link = %s' % management_response.get('previousLink') |
371 | 408 if management_response.get('nextLink'): |
372 # These only have values if other result pages exist. | 409 print 'Next Link = %s' % management_response.get('nextLink') |
373 if mgmt_list.get('previousLink'): | |
374 print 'Previous Link = %s' % mgmt_list.get('previousLink') | |
375 if mgmt_list.get('nextLink'): | |
376 print 'Next Link = %s' % mgmt_list.get('nextLink') | |
377 | 410 |
378 | 411 |
379 if __name__ == '__main__': | 412 if __name__ == '__main__': |
380 main(sys.argv) | 413 main(sys.argv) |
381 | 414 |
LEFT | RIGHT |