| 4 | import { isDestroying, isDestroyed } from '@ember/destroyable'; |
| 5 | |
| 6 | export default class ApplicationRoute extends Route { |
| 7 | @service |
| 8 | headData; |
| 9 | |
| 10 | @service |
| 11 | legacyModuleMappings; |
| 12 | |
| 13 | @service |
| 14 | router; |
| 15 | |
| 16 | @service |
| 17 | prerender; |
| 18 | |
| 19 | @service |
| 20 | metrics; |
| 21 | |
| 22 | @service |
| 23 | routerScroll; |
| 24 | |
| 25 | @service |
| 26 | shoebox; |
| 27 | |
| 28 | constructor() { |
| 29 | super(...arguments); |
| 30 | if (!this.prerender.isPrerendering) { |
| 31 | this.router.on('routeDidChange', this.trackPage); |
| 32 | |
| 33 | /* Hax from https://github.com/DockYard/ember-router-scroll/issues/263 |
| 34 | to handle router scroll behavior when the page was initially served |
| 35 | pre-rendered |
| 36 | */ |
| 37 | this.routerScroll.set('preserveScrollPosition', true); |
| 38 | |
| 39 | setTimeout(() => { |
| 40 | if (!isDestroying(this) && !isDestroyed(this)) { |
| 41 | this.routerScroll.set('preserveScrollPosition', false); |
| 42 | } |
| 43 | }, 1000); |
| 44 | } |
| 45 | |
| 46 | if (this.prerender.isPrerendering) { |
| 47 | this.router.on('routeDidChange', this.storeShoebox); |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | storeShoebox = () => { |
| 52 | this.shoebox.store(); |
| 53 | }; |
| 54 | |
| 55 | trackPage = () => { |
| 56 | // this is constant for this app and is only used to identify page views in the GA dashboard |
| 57 | const hostname = ENV.APP.domain.replace(/(http|https)?:?\/\//g, ''); |
| 58 | |
| 59 | const page = this.router.currentURL; |
| 60 | const title = this.router.currentRouteName ?? 'unknown'; |