Skip to content

Commit e0ffeca

Browse files
committed
ga changes
1 parent d46d572 commit e0ffeca

3 files changed

Lines changed: 28 additions & 7 deletions

File tree

ui/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ui",
3-
"version": "1.3.0",
3+
"version": "1.3.4",
44
"scripts": {
55
"lint": "npx eslint .",
66
"start": "ng serve --port 8080 --host 0.0.0.0 --disable-host-check",

ui/src/app/app.component.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ export class AppComponent implements OnInit, AfterContentInit {
4747
await this.sync()
4848
await this.fixUIMode()
4949
this.analytics.send()
50+
setInterval(() => {
51+
this.analytics.ping()
52+
}, 1000 * 60)
5053
}
5154

5255
async ngAfterContentInit () {

ui/src/app/services/analytics.service.ts

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,27 @@ export class AnalyticsService {
1212
public app: ApplicationService
1313
) {}
1414

15-
public async load () {
16-
await this.utils.waitForProperty(window, 'ga')
17-
await this.utils.delay(1000)
18-
await this.utils.waitForProperty(ga, 'getAll')
19-
return ga.getAll()[0]
15+
private _tracker: UniversalAnalytics.Tracker
16+
17+
public get tracker () {
18+
return new Promise<UniversalAnalytics.Tracker>(async (resolve, reject) => {
19+
try {
20+
if (!this._tracker) {
21+
await this.utils.waitForProperty(window, 'ga')
22+
await this.utils.delay(1000)
23+
await this.utils.waitForProperty(ga, 'getAll')
24+
this._tracker = ga.getAll()[0]
25+
}
26+
resolve(this._tracker)
27+
} catch (err) {
28+
reject(err)
29+
}
30+
})
2031
}
2132

2233
async send () {
2334
const [ tracker, info ] = await Promise.all([
24-
this.load(),
35+
this.tracker,
2536
this.app.getInfo()
2637
])
2738
const data = {
@@ -32,4 +43,11 @@ export class AnalyticsService {
3243
}
3344
tracker.send('screenview', data)
3445
}
46+
47+
async ping () {
48+
const tracker = await this.tracker
49+
tracker.send('screenview', {
50+
screenview: 'Home'
51+
})
52+
}
3553
}

0 commit comments

Comments
 (0)