mirror of
https://github.com/WowUp/WowUp.git
synced 2026-05-19 12:04:50 -04:00
Use firebase analytics
This commit is contained in:
@@ -118,6 +118,7 @@
|
||||
"electron-log": "4.2.4",
|
||||
"electron-store": "6.0.1",
|
||||
"electron-updater": "4.3.5",
|
||||
"firebase": "7.24.0",
|
||||
"fs-extra": "9.0.1",
|
||||
"globrex": "0.1.2",
|
||||
"lodash": "4.17.20",
|
||||
|
||||
@@ -52,10 +52,10 @@ export class AppComponent implements AfterViewInit {
|
||||
}
|
||||
|
||||
this.onAutoUpdateInterval();
|
||||
// this._autoUpdateInterval = window.setInterval(
|
||||
// this.onAutoUpdateInterval,
|
||||
// AUTO_UPDATE_PERIOD_MS
|
||||
// );
|
||||
this._autoUpdateInterval = window.setInterval(
|
||||
this.onAutoUpdateInterval,
|
||||
AUTO_UPDATE_PERIOD_MS
|
||||
);
|
||||
}
|
||||
|
||||
openDialog(): void {
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import { Component, Input, OnDestroy, OnInit } from "@angular/core";
|
||||
import { TranslateService } from "@ngx-translate/core";
|
||||
import { AddonViewModel } from "app/business-objects/my-addon-list-item";
|
||||
import { WowClientType } from "app/models/warcraft/wow-client-type";
|
||||
import { AddonInstallState } from "app/models/wowup/addon-install-state";
|
||||
import { AddonService } from "app/services/addons/addon.service";
|
||||
import { filter } from "rxjs/operators";
|
||||
import { AnalyticsService } from "app/services/analytics/analytics.service";
|
||||
import { getEnumName } from "app/utils/enum.utils";
|
||||
|
||||
@Component({
|
||||
selector: "app-addon-update-button",
|
||||
@@ -15,14 +17,18 @@ export class AddonUpdateButtonComponent implements OnInit, OnDestroy {
|
||||
|
||||
constructor(
|
||||
private _addonService: AddonService,
|
||||
private _analyticsService: AnalyticsService,
|
||||
private _translateService: TranslateService
|
||||
) {}
|
||||
|
||||
ngOnInit(): void {
|
||||
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
ngOnInit(): void {}
|
||||
|
||||
ngOnDestroy(): void {}
|
||||
|
||||
public get actionLabel() {
|
||||
return `${getEnumName(WowClientType, this.listItem?.addon?.clientType)}|${
|
||||
this.listItem?.addon.providerName
|
||||
}|${this.listItem?.addon.externalId}|${this.listItem?.addon.name}`;
|
||||
}
|
||||
|
||||
public get installProgress() {
|
||||
@@ -39,7 +45,7 @@ export class AddonUpdateButtonComponent implements OnInit, OnDestroy {
|
||||
public get isButtonDisabled() {
|
||||
return (
|
||||
this.listItem?.isUpToDate ||
|
||||
this.listItem?.installState < AddonInstallState.Unknown
|
||||
this.listItem?.installState < AddonInstallState.Unknown
|
||||
);
|
||||
}
|
||||
|
||||
@@ -52,6 +58,12 @@ export class AddonUpdateButtonComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
public onInstallUpdateClick() {
|
||||
this._analyticsService.trackUserAction(
|
||||
"addons",
|
||||
"update_addon",
|
||||
this.actionLabel
|
||||
);
|
||||
|
||||
this._addonService.installAddon(
|
||||
this.listItem.addon.id,
|
||||
this.onInstallUpdate
|
||||
|
||||
@@ -12,7 +12,6 @@ export class UserActionTrackerDirective {
|
||||
@Input() label: string;
|
||||
|
||||
@HostListener('click', ['$event']) onClick($event) {
|
||||
this._analyticsService.trackUserAction(this.category, this.action, this.label);
|
||||
}
|
||||
|
||||
constructor(private _analyticsService: AnalyticsService) { }
|
||||
|
||||
@@ -64,8 +64,10 @@
|
||||
<th mat-header-cell mat-sort-header *matHeaderCellDef>
|
||||
{{'PAGES.GET_ADDONS.TABLE.RELEASED_AT_COLUMN_HEADER' | translate}}
|
||||
</th>
|
||||
<td mat-cell *matCellDef="let element">
|
||||
{{element | getAddonListItemFileProp:'releaseDate':defaultAddonChannel | date:'short'}}
|
||||
<td mat-cell *matCellDef="let element" >
|
||||
<div matTooltip="TEST">
|
||||
{{element | getAddonListItemFileProp:'releaseDate':defaultAddonChannel | date:'short'}}
|
||||
</div>
|
||||
</td>
|
||||
</ng-container>
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import { TocService } from "../toc/toc.service";
|
||||
import { AddonUpdateEvent } from "app/models/wowup/addon-update-event";
|
||||
import { AddonProviderFactory } from "./addon.provider.factory";
|
||||
import { AnalyticsService } from "../analytics/analytics.service";
|
||||
import { getEnumName } from "app/utils/enum.utils";
|
||||
|
||||
interface InstallQueueItem {
|
||||
addonId: string;
|
||||
@@ -84,8 +85,8 @@ export class AddonService {
|
||||
var searchResults = await Promise.all(searchTasks);
|
||||
|
||||
await this._analyticsService.trackUserAction(
|
||||
"Addons",
|
||||
"Search",
|
||||
"addons",
|
||||
"search",
|
||||
`${clientType}|${query}`
|
||||
);
|
||||
|
||||
@@ -268,10 +269,13 @@ export class AddonService {
|
||||
|
||||
this._addonStorage.set(addon.id, addon);
|
||||
|
||||
await this._analyticsService.trackUserAction(
|
||||
"Addons",
|
||||
"InstallById",
|
||||
`${addon.clientType}|${addon.name}`
|
||||
const actionLabel = `${getEnumName(WowClientType, addon.clientType)}|${
|
||||
addon.providerName
|
||||
}|${addon.externalId}|${addon.name}`;
|
||||
this._analyticsService.trackUserAction(
|
||||
"addons",
|
||||
"install_by_id",
|
||||
actionLabel
|
||||
);
|
||||
|
||||
queueItem.completion.resolve();
|
||||
@@ -557,10 +561,8 @@ export class AddonService {
|
||||
if (
|
||||
!result ||
|
||||
!latestFile ||
|
||||
(
|
||||
latestFile.version === addon.latestVersion &&
|
||||
latestFile.releaseDate === addon.releasedAt
|
||||
)
|
||||
(latestFile.version === addon.latestVersion &&
|
||||
latestFile.releaseDate === addon.releasedAt)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
@@ -755,7 +757,7 @@ export class AddonService {
|
||||
autoUpdateEnabled: this._wowUpService.getDefaultAutoUpdate(clientType),
|
||||
releasedAt: latestFile.releaseDate,
|
||||
summary: searchResult.summary,
|
||||
screenshotUrls: searchResult.screenshotUrls
|
||||
screenshotUrls: searchResult.screenshotUrls,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import { ErrorHandler, Injectable } from "@angular/core";
|
||||
import { Injectable } from "@angular/core";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import { PreferenceStorageService } from "../storage/preference-storage.service";
|
||||
import { AppConfig } from "environments/environment";
|
||||
import { HttpClient, HttpParams } from "@angular/common/http";
|
||||
import { ElectronService } from "../electron/electron.service";
|
||||
import { BehaviorSubject } from "rxjs";
|
||||
import * as firebase from "firebase/app";
|
||||
import "firebase/analytics";
|
||||
|
||||
@Injectable({
|
||||
providedIn: "root",
|
||||
@@ -16,6 +18,9 @@ export class AnalyticsService {
|
||||
private readonly _appVersion: string;
|
||||
private readonly _telemetryEnabledSrc = new BehaviorSubject(false);
|
||||
|
||||
private _firebaseApp?: firebase.app.App;
|
||||
private _firebaseAnalytics?: firebase.analytics.Analytics;
|
||||
|
||||
public readonly telemetryPromptUsedKey = "telemetry_prompt_sent";
|
||||
public readonly telemetryEnabledKey = "telemetry_enabled";
|
||||
public readonly telemetryEnabled$ = this._telemetryEnabledSrc.asObservable();
|
||||
@@ -24,6 +29,22 @@ export class AnalyticsService {
|
||||
return this._installId;
|
||||
}
|
||||
|
||||
private startFirebase() {
|
||||
if (this._firebaseApp) {
|
||||
return;
|
||||
}
|
||||
|
||||
console.log("Firebase setup");
|
||||
|
||||
this._firebaseApp = firebase.initializeApp(AppConfig.firebaseConfig);
|
||||
this._firebaseAnalytics = firebase.analytics(this._firebaseApp);
|
||||
this._firebaseAnalytics.setUserId(this.installId);
|
||||
}
|
||||
|
||||
private setFirebaseAnalyticsEnabled(enabled: boolean) {
|
||||
this._firebaseAnalytics?.setAnalyticsCollectionEnabled(enabled);
|
||||
}
|
||||
|
||||
public get shouldPromptTelemetry() {
|
||||
return (
|
||||
this._preferenceStorageService.get(this.telemetryEnabledKey) === undefined
|
||||
@@ -34,7 +55,14 @@ export class AnalyticsService {
|
||||
const preference = this._preferenceStorageService.findByKey(
|
||||
this.telemetryEnabledKey
|
||||
);
|
||||
return preference === true.toString();
|
||||
const isEnabled = preference === true.toString();
|
||||
|
||||
this.setFirebaseAnalyticsEnabled(isEnabled);
|
||||
if (isEnabled) {
|
||||
this.startFirebase();
|
||||
}
|
||||
|
||||
return isEnabled;
|
||||
}
|
||||
|
||||
public set telemetryEnabled(value: boolean) {
|
||||
@@ -44,70 +72,70 @@ export class AnalyticsService {
|
||||
|
||||
constructor(
|
||||
private _electronService: ElectronService,
|
||||
private _httpClient: HttpClient,
|
||||
private _preferenceStorageService: PreferenceStorageService
|
||||
) {
|
||||
this._appVersion = _electronService.remote.app.getVersion();
|
||||
this._appVersion = this._electronService.remote.app.getVersion();
|
||||
this._installId = this.loadInstallId();
|
||||
this._telemetryEnabledSrc.next(this.telemetryEnabled);
|
||||
console.log("installId", this._installId);
|
||||
}
|
||||
|
||||
public async trackStartup() {
|
||||
await this.track((params) => {
|
||||
params.set("t", "pageview");
|
||||
params.set("dp", "app/startup");
|
||||
});
|
||||
public trackStartup() {
|
||||
this._firebaseAnalytics.logEvent("app_startup");
|
||||
}
|
||||
|
||||
public async trackUserAction(
|
||||
public trackUserAction(
|
||||
category: string,
|
||||
action: string,
|
||||
label: string = null
|
||||
) {
|
||||
await this.track((params) => {
|
||||
params.set("t", "event");
|
||||
params.set("ec", category);
|
||||
params.set("ea", action);
|
||||
params.set("el", label);
|
||||
this.trackEvent(category, {
|
||||
[action]: label,
|
||||
});
|
||||
}
|
||||
|
||||
private async track(action: (params: HttpParams) => void = undefined) {
|
||||
private trackEvent(eventName: string, params: { [key: string]: any }) {
|
||||
if (!this.telemetryEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
var url = `${this.analyticsUrl}/collect`;
|
||||
|
||||
try {
|
||||
let params = new URLSearchParams();
|
||||
params.set("v", "1");
|
||||
params.set("tid", AppConfig.googleAnalyticsId);
|
||||
params.set("cid", this._installId);
|
||||
params.set("ua", window.navigator.userAgent);
|
||||
params.set("an", "WowUp Client");
|
||||
params.set("av", this._appVersion);
|
||||
|
||||
action?.call(this, params);
|
||||
|
||||
const fullUrl = `${url}?${params}`;
|
||||
|
||||
const response = await this._httpClient
|
||||
.post(
|
||||
fullUrl,
|
||||
{},
|
||||
{
|
||||
responseType: "text",
|
||||
}
|
||||
)
|
||||
.toPromise();
|
||||
} catch (e) {
|
||||
// eat
|
||||
console.error(e);
|
||||
}
|
||||
this._firebaseAnalytics.logEvent(eventName, params);
|
||||
}
|
||||
|
||||
// private async track(action: (params: HttpParams) => void = undefined) {
|
||||
// if (!this.telemetryEnabled) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// var url = `${this.analyticsUrl}/collect`;
|
||||
|
||||
// try {
|
||||
// let params = new URLSearchParams();
|
||||
// params.set("v", "1");
|
||||
// params.set("tid", AppConfig.googleAnalyticsId);
|
||||
// params.set("cid", this._installId);
|
||||
// params.set("ua", window.navigator.userAgent);
|
||||
// params.set("an", "WowUp Client");
|
||||
// params.set("av", this._appVersion);
|
||||
|
||||
// action?.call(this, params);
|
||||
|
||||
// const fullUrl = `${url}?${params}`;
|
||||
|
||||
// const response = await this._httpClient
|
||||
// .post(
|
||||
// fullUrl,
|
||||
// {},
|
||||
// {
|
||||
// responseType: "text",
|
||||
// }
|
||||
// )
|
||||
// .toPromise();
|
||||
// } catch (e) {
|
||||
// // eat
|
||||
// console.error(e);
|
||||
// }
|
||||
// }
|
||||
|
||||
private loadInstallId() {
|
||||
let installId = this._preferenceStorageService.findByKey(
|
||||
this.installIdPreferenceKey
|
||||
|
||||
@@ -10,4 +10,5 @@ export const AppConfig = {
|
||||
wowUpHubUrl: "https://hub.dev.wowup.io",
|
||||
rollbarAccessKey: "d01c11314a064572b11acee18d880650",
|
||||
googleAnalyticsId: "UA-92563227-4",
|
||||
|
||||
};
|
||||
|
||||
@@ -5,4 +5,14 @@ export const AppConfig = {
|
||||
wowUpHubUrl: "https://hub.wowup.io",
|
||||
rollbarAccessKey: "d01c11314a064572b11acee18d880650",
|
||||
googleAnalyticsId: "UA-92563227-4",
|
||||
firebaseConfig: {
|
||||
apiKey: "AIzaSyBvZ1_ldinsxeh-iRI53REm8j1CPcQuIBw",
|
||||
authDomain: "wowup-893c6.firebaseapp.com",
|
||||
databaseURL: "https://wowup-893c6.firebaseio.com",
|
||||
projectId: "wowup-893c6",
|
||||
storageBucket: "wowup-893c6.appspot.com",
|
||||
messagingSenderId: "914166112595",
|
||||
appId: "1:914166112595:web:cdb02d231e5f9802b541a6",
|
||||
measurementId: "G-V646RWJ5NK",
|
||||
},
|
||||
};
|
||||
|
||||
@@ -5,4 +5,14 @@ export const AppConfig = {
|
||||
wowUpHubUrl: "https://hub.dev.wowup.io",
|
||||
rollbarAccessKey: "d01c11314a064572b11acee18d880650",
|
||||
googleAnalyticsId: "UA-92563227-4",
|
||||
firebaseConfig: {
|
||||
apiKey: "AIzaSyBvZ1_ldinsxeh-iRI53REm8j1CPcQuIBw",
|
||||
authDomain: "wowup-893c6.firebaseapp.com",
|
||||
databaseURL: "https://wowup-893c6.firebaseio.com",
|
||||
projectId: "wowup-893c6",
|
||||
storageBucket: "wowup-893c6.appspot.com",
|
||||
messagingSenderId: "914166112595",
|
||||
appId: "1:914166112595:web:cdb02d231e5f9802b541a6",
|
||||
measurementId: "G-V646RWJ5NK",
|
||||
},
|
||||
};
|
||||
|
||||
@@ -10,4 +10,5 @@ export const AppConfig = {
|
||||
wowUpHubUrl: "https://hub.dev.wowup.io",
|
||||
rollbarAccessKey: "d01c11314a064572b11acee18d880650",
|
||||
googleAnalyticsId: "UA-92563227-4",
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user