|
162 | 162 | <paper-toast id="errorToast" duration="5000"></paper-toast>
|
163 | 163 | <paper-toast id="offlineToast" class="offline-toast" text="You are now offline. Can't make new requests."></paper-toast>
|
164 | 164 | <search-bar id="content-search-bar" on-iron-overlay-opened="textSearchBarOpened"></search-bar>
|
165 |
| - <app-analytics tracking-id="UA-18021184-6" app-name="ARC-electon" app-id="[[appId]]" app-version="[[appVersion]]" disable-tracking="{{analyticsDisabled}}" data-source="electron-app"> |
166 |
| - <template is="dom-repeat" items="[[gaCustomMetrics]]"> |
167 |
| - <app-analytics-custom type="metric" index="[[item.index]]" value="[[item.value]]"></app-analytics-custom> |
168 |
| - </template> |
169 |
| - <template is="dom-repeat" items="[[gaCustomDimensions]]"> |
170 |
| - <app-analytics-custom type="dimension" index="[[item.index]]" value="[[item.value]]"></app-analytics-custom> |
171 |
| - </template> |
172 |
| - </app-analytics> |
173 |
| - <app-analytics tracking-id="UA-18021184-14" app-name="ARC" app-id="[[appId]]" app-version="[[appVersion]]" data-source="electron-app" disable-tracking="{{analyticsDisabled}}"> |
174 |
| - <template is="dom-repeat" items="[[gaCustomMetrics]]"> |
175 |
| - <app-analytics-custom type="metric" index="[[item.index]]" value="[[item.value]]"></app-analytics-custom> |
176 |
| - </template> |
177 |
| - <template is="dom-repeat" items="[[gaCustomDimensions]]"> |
178 |
| - <app-analytics-custom type="dimension" index="[[item.index]]" value="[[item.value]]"></app-analytics-custom> |
179 |
| - </template> |
180 |
| - </app-analytics> |
181 |
| - <app-analytics tracking-id="UA-71458341-2" app-name="ARC" app-id="[[appId]]" app-version="[[appVersion]]" data-source="electron-app" disable-tracking="{{analyticsDisabled}}"> |
182 |
| - <template is="dom-repeat" items="[[gaCustomMetrics]]"> |
183 |
| - <app-analytics-custom type="metric" index="[[item.index]]" value="[[item.value]]"></app-analytics-custom> |
184 |
| - </template> |
185 |
| - <template is="dom-repeat" items="[[gaCustomDimensions]]"> |
186 |
| - <app-analytics-custom type="dimension" index="[[item.index]]" value="[[item.value]]"></app-analytics-custom> |
187 |
| - </template> |
188 |
| - </app-analytics> |
| 165 | + <template is="dom-if" if="[[telemetry]]" restamp="true"> |
| 166 | + <app-analytics tracking-id="UA-18021184-6" app-name="ARC-electon" app-id="[[appId]]" app-version="[[appVersion]]" disable-tracking="{{analyticsDisabled}}" data-source="electron-app"> |
| 167 | + <template is="dom-repeat" items="[[gaCustomMetrics]]"> |
| 168 | + <app-analytics-custom type="metric" index="[[item.index]]" value="[[item.value]]"></app-analytics-custom> |
| 169 | + </template> |
| 170 | + <template is="dom-repeat" items="[[gaCustomDimensions]]"> |
| 171 | + <app-analytics-custom type="dimension" index="[[item.index]]" value="[[item.value]]"></app-analytics-custom> |
| 172 | + </template> |
| 173 | + </app-analytics> |
| 174 | + <app-analytics tracking-id="UA-18021184-14" app-name="ARC" app-id="[[appId]]" app-version="[[appVersion]]" data-source="electron-app" disable-tracking="{{analyticsDisabled}}"> |
| 175 | + <template is="dom-repeat" items="[[gaCustomMetrics]]"> |
| 176 | + <app-analytics-custom type="metric" index="[[item.index]]" value="[[item.value]]"></app-analytics-custom> |
| 177 | + </template> |
| 178 | + <template is="dom-repeat" items="[[gaCustomDimensions]]"> |
| 179 | + <app-analytics-custom type="dimension" index="[[item.index]]" value="[[item.value]]"></app-analytics-custom> |
| 180 | + </template> |
| 181 | + </app-analytics> |
| 182 | + <app-analytics tracking-id="UA-71458341-2" app-name="ARC" app-id="[[appId]]" app-version="[[appVersion]]" data-source="electron-app" disable-tracking="{{analyticsDisabled}}"> |
| 183 | + <template is="dom-repeat" items="[[gaCustomMetrics]]"> |
| 184 | + <app-analytics-custom type="metric" index="[[item.index]]" value="[[item.value]]"></app-analytics-custom> |
| 185 | + </template> |
| 186 | + <template is="dom-repeat" items="[[gaCustomDimensions]]"> |
| 187 | + <app-analytics-custom type="dimension" index="[[item.index]]" value="[[item.value]]"></app-analytics-custom> |
| 188 | + </template> |
| 189 | + </app-analytics> |
| 190 | + </template> |
189 | 191 | <app-logger></app-logger>
|
190 | 192 | <arc-definitions></arc-definitions>
|
191 | 193 | <variables-evaluator no-before-request></variables-evaluator>
|
|
245 | 247 | _drawerInitTransition: Number,
|
246 | 248 | accessToken: String,
|
247 | 249 | // Latest update event data
|
248 |
| - updateState: Array |
| 250 | + updateState: Array, |
| 251 | + /** |
| 252 | + * Overrides analytics element behavior. |
| 253 | + * This setting is now in main application settings. |
| 254 | + * |
| 255 | + * TODO: Remove state setting from the element. This should be |
| 256 | + * controlled from the outside. |
| 257 | + */ |
| 258 | + analyticsDisabled: { |
| 259 | + type: Boolean, |
| 260 | + value: false |
| 261 | + }, |
| 262 | + /** |
| 263 | + * Sets Google Analytics state. If this is not set or falsy, then Google |
| 264 | + * Analytics is diosabled (element is removed from the DOM). |
| 265 | + */ |
| 266 | + telemetry: Boolean |
249 | 267 | },
|
250 | 268 |
|
251 | 269 | created: function() {
|
|
273 | 291 | 'google-autorize': '_googleOauthTokenRequested',
|
274 | 292 | 'on-process-incoming-data': '_processIcomingData',
|
275 | 293 | 'pick-google-drive-item': 'openDrivePicker',
|
276 |
| - 'open-drive-selector': 'openDrivePicker' |
| 294 | + 'open-drive-selector': 'openDrivePicker', |
| 295 | + 'settings-changed': '_settingChanged' |
277 | 296 | },
|
278 | 297 |
|
279 | 298 | observers: [
|
|
297 | 316 | this._requestAuthToken(false);
|
298 | 317 | this.setupAnalytics();
|
299 | 318 | },
|
300 |
| - |
| 319 | + /** |
| 320 | + * Reads current settings and enables Google Analytics if it's not |
| 321 | + * disabled by the uers. |
| 322 | + */ |
301 | 323 | setupAnalytics: function() {
|
| 324 | + var event = this.fire('settings-read', {}, { |
| 325 | + composed: true, |
| 326 | + cancelable: true |
| 327 | + }); |
| 328 | + if (!event.defaultPrevented) { |
| 329 | + throw new Error('Settings provided not found.'); |
| 330 | + } |
| 331 | + return event.detail.result.then(settings => { |
| 332 | + if (settings.telemetry === false) { |
| 333 | + this._analyticsDisabled(); |
| 334 | + } else { |
| 335 | + this._analyticsEnabled(); |
| 336 | + } |
| 337 | + }); |
| 338 | + }, |
| 339 | + /** |
| 340 | + * Enables Google Analytics. |
| 341 | + * |
| 342 | + * Until settings status is checked Google Analytics components is not |
| 343 | + * even in the DOM. Once the `telemetry` flag is set analytics elements |
| 344 | + * are attached to the DOM and start handling events. |
| 345 | + * |
| 346 | + * This can be disabled by calling `_analyticsDisabled` or by sending |
| 347 | + * `settings-changed` custom event with `telemetry` key. |
| 348 | + */ |
| 349 | + _analyticsEnabled: function() { |
| 350 | + this.telemetry = true; |
| 351 | + if (this.gaCustomDimensions) { |
| 352 | + return; |
| 353 | + } |
302 | 354 | this.gaCustomDimensions = [];
|
303 | 355 | this.push('gaCustomDimensions', {
|
304 | 356 | index: 1,
|
|
313 | 365 | value: 'stable'
|
314 | 366 | });
|
315 | 367 | },
|
| 368 | + // To be called if GA is disabled to remove GA elements from the DOM. |
| 369 | + _analyticsDisabled: function() { |
| 370 | + this.telemetry = false; |
| 371 | + // no need to clean up custom dimensions |
| 372 | + // since it is removed from DOM anyway. |
| 373 | + }, |
| 374 | + /** |
| 375 | + * Handles settings change event. |
| 376 | + * If changed setting is `telemetry` then it upodates GA state. |
| 377 | + */ |
| 378 | + _settingChanged: function(e) { |
| 379 | + if (e.cancelable) { |
| 380 | + return; // request for change |
| 381 | + } |
| 382 | + // Here we just care about `telemetry` |
| 383 | + if (e.detail.name !== 'telemetry') { |
| 384 | + return; |
| 385 | + } |
| 386 | + var value = e.detail.value; |
| 387 | + if (typeof value !== 'boolean') { |
| 388 | + value = value === 'false' ? false : true; |
| 389 | + } |
| 390 | + if (value) { |
| 391 | + this._analyticsEnabled(); |
| 392 | + } else { |
| 393 | + this._analyticsDisabled(); |
| 394 | + } |
| 395 | + }, |
316 | 396 |
|
317 | 397 | _setupRequestRoute: function(record) {
|
318 | 398 | var params = record && record.base;
|
|
0 commit comments