mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-03-09 15:40:26 +00:00
feat: add download analytics
This commit is contained in:
parent
42e0df29ee
commit
b82840df3b
3 changed files with 38 additions and 0 deletions
|
@ -9,6 +9,7 @@ import { createGame } from "@main/services/library-sync";
|
|||
import { steamUrlBuilder } from "@shared";
|
||||
import { dataSource } from "@main/data-source";
|
||||
import { DownloadQueue, Game } from "@main/entity";
|
||||
import { HydraAnalytics } from "@main/services/hydra-analytics";
|
||||
|
||||
const startGameDownload = async (
|
||||
_event: Electron.IpcMainInvokeEvent,
|
||||
|
@ -90,6 +91,8 @@ const startGameDownload = async (
|
|||
logger.error("Failed to create game download", err);
|
||||
});
|
||||
|
||||
HydraAnalytics.postDownload(payload.uri).catch(() => {});
|
||||
|
||||
await DownloadManager.cancelDownload(updatedGame!.id);
|
||||
await DownloadManager.startDownload(updatedGame!);
|
||||
|
||||
|
|
34
src/main/services/hydra-analytics.ts
Normal file
34
src/main/services/hydra-analytics.ts
Normal file
|
@ -0,0 +1,34 @@
|
|||
import { userSubscriptionRepository } from "@main/repository";
|
||||
import axios from "axios";
|
||||
import { appVersion } from "@main/constants";
|
||||
|
||||
export class HydraAnalytics {
|
||||
private static instance = axios.create({
|
||||
baseURL: import.meta.env.MAIN_VITE_ANALYTICS_API_URL,
|
||||
headers: { "User-Agent": `Hydra Launcher v${appVersion}` },
|
||||
});
|
||||
|
||||
private static async hasActiveSubscription() {
|
||||
const userSubscription = await userSubscriptionRepository.findOne({
|
||||
where: { id: 1 },
|
||||
});
|
||||
|
||||
return (
|
||||
userSubscription?.expiresAt && userSubscription.expiresAt > new Date()
|
||||
);
|
||||
}
|
||||
|
||||
static async postDownload(hash: string) {
|
||||
const hasSubscription = await this.hasActiveSubscription();
|
||||
|
||||
return this.instance
|
||||
.post("/track", {
|
||||
event: "download",
|
||||
attributes: {
|
||||
hash,
|
||||
hasSubscription,
|
||||
},
|
||||
})
|
||||
.then((response) => response.data);
|
||||
}
|
||||
}
|
1
src/main/vite-env.d.ts
vendored
1
src/main/vite-env.d.ts
vendored
|
@ -3,6 +3,7 @@
|
|||
interface ImportMetaEnv {
|
||||
readonly MAIN_VITE_STEAMGRIDDB_API_KEY: string;
|
||||
readonly MAIN_VITE_API_URL: string;
|
||||
readonly MAIN_VITE_ANALYTICS_API_URL: string;
|
||||
readonly MAIN_VITE_AUTH_URL: string;
|
||||
readonly MAIN_VITE_CHECKOUT_URL: string;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue