From a3fd70573acbfd0ee6cc44d83bfa3a469c893768 Mon Sep 17 00:00:00 2001 From: Jeremy Scheff Date: Thu, 3 Oct 2024 10:24:38 -0400 Subject: [PATCH] log_event.php failing should not break the game --- TODO | 6 ++++ src/common/analyticsEventLocal.ts | 20 +++++++++++ src/ui/views/NewLeague/index.tsx | 13 ++------ src/worker/core/phase/newPhaseBeforeDraft.ts | 35 ++++++++------------ 4 files changed, 42 insertions(+), 32 deletions(-) create mode 100644 src/common/analyticsEventLocal.ts diff --git a/TODO b/TODO index bb72450400..2f427c9ba6 100644 --- a/TODO +++ b/TODO @@ -1,3 +1,9 @@ +customize number of pitchers in rotation https://discord.com/channels/290013534023057409/944392892905037885/1291306004495204363 +- use this to set the max pFatigue value in play.ts +- use in UI for how many starting pitchers are shown in depth chart +- use in getStartingPitcher +- use in auto sorting pitcher depth chart + best teams option in legends mode - iterate over teams, compute ovr, drop ones who don't make the top 30 - is this too slow? diff --git a/src/common/analyticsEventLocal.ts b/src/common/analyticsEventLocal.ts new file mode 100644 index 0000000000..a80a86df82 --- /dev/null +++ b/src/common/analyticsEventLocal.ts @@ -0,0 +1,20 @@ +import { ACCOUNT_API_URL } from "./constants"; +import fetchWrapper from "./fetchWrapper"; + +export const analyticsEventLocal = async ( + type: "new_league" | "completed_season", +) => { + try { + await fetchWrapper({ + url: `${ACCOUNT_API_URL}/log_event.php`, + method: "POST", + data: { + sport: process.env.SPORT, + type, + }, + credentials: "include", + }); + } catch (error) { + console.error(error); + } +}; diff --git a/src/ui/views/NewLeague/index.tsx b/src/ui/views/NewLeague/index.tsx index 2e9ca60752..db6462cbb3 100644 --- a/src/ui/views/NewLeague/index.tsx +++ b/src/ui/views/NewLeague/index.tsx @@ -13,8 +13,6 @@ import { WEBSITE_ROOT, unwrapGameAttribute, LEAGUE_DATABASE_VERSION, - ACCOUNT_API_URL, - fetchWrapper, } from "../../../common"; import { ActionButton, @@ -54,6 +52,7 @@ import type { Settings } from "../../../worker/views/settings"; import type { BasicInfo } from "../../../worker/api/leagueFileUpload"; import { SelectSeasonRange } from "./SelectSeasonRange"; import { orderBy } from "../../../common/utils"; +import { analyticsEventLocal } from "../../../common/analyticsEventLocal"; const animationVariants = { visible: { @@ -888,15 +887,7 @@ const NewLeague = (props: View<"newLeague">) => { league_id: lid, }); if (window.enableLogging) { - fetchWrapper({ - url: `${ACCOUNT_API_URL}/log_event.php`, - method: "POST", - data: { - sport: process.env.SPORT, - type: "new_league", - }, - credentials: "include", - }); + analyticsEventLocal("new_league"); } realtimeUpdate([], `/l/${lid}`); diff --git a/src/worker/core/phase/newPhaseBeforeDraft.ts b/src/worker/core/phase/newPhaseBeforeDraft.ts index ede616154d..43fc109bfc 100644 --- a/src/worker/core/phase/newPhaseBeforeDraft.ts +++ b/src/worker/core/phase/newPhaseBeforeDraft.ts @@ -1,4 +1,4 @@ -import { ACCOUNT_API_URL, PLAYER, fetchWrapper } from "../../../common"; +import { PLAYER } from "../../../common"; import { draft, player, season, team, league } from ".."; import { idb } from "../../db"; import { @@ -25,6 +25,7 @@ import type { import setGameAttributes from "../league/setGameAttributes"; import { doExpand, doRelocate } from "./relocateExpand"; import addAward from "../player/addAward"; +import { analyticsEventLocal } from "../../../common/analyticsEventLocal"; const INFLATION_GAME_ATTRIBUTES = [ "salaryCap", @@ -559,27 +560,19 @@ const newPhaseBeforeDraft = async ( riggedLottery: undefined, }); - toUI( - "analyticsEvent", - [ - "completed_season", - { - season: g.get("season"), - league_id: g.get("lid"), - }, - ], - conditions, - ); if (env.enableLogging) { - fetchWrapper({ - url: `${ACCOUNT_API_URL}/log_event.php`, - method: "POST", - data: { - sport: process.env.SPORT, - type: "completed_season", - }, - credentials: "include", - }); + toUI( + "analyticsEvent", + [ + "completed_season", + { + season: g.get("season"), + league_id: g.get("lid"), + }, + ], + conditions, + ); + analyticsEventLocal("completed_season"); } return {