feat: migrate analytics

This commit is contained in:
Haoyu Xu
2024-12-20 00:16:43 +08:00
parent 41bab8d693
commit 8b1e3d465d
12 changed files with 50 additions and 147 deletions

View File

@@ -39,9 +39,8 @@ export default class Settings {
#scale = this.#defaultScale
#logoX = this.#defaultLogoX
#logoY = this.#defaultLogoY
#isInsightsInited = false
#isInsightInited = false
#doNotTrack = false
#lastFunctionInsights = null
#useStartAnimation = true
constructor(el, logoEl) {
@@ -71,51 +70,41 @@ export default class Settings {
success() {
this.loadViewport()
this.insights(false, false)
this.insight(false, false)
this.#updateOptions("animation_selection", this.spinePlayer.skeleton.data.animations.map(e => e.name))
if ((new URLSearchParams(window.location.search)).has("settings") || import.meta.env.MODE === 'development') {
this.open()
}
}
insights(isWallpaperEngine, doNotTrack) {
insight(isWallpaperEngine, doNotTrack) {
console.log(1)
this.isWallpaperEngine = isWallpaperEngine
if (this.#isInsightsInited || import.meta.env.MODE === 'development') return
this.#isInsightsInited = true
if (this.#isInsightInited || import.meta.env.MODE === 'development') return
console.log(2)
this.#isInsightInited = true
this.#doNotTrack = doNotTrack
if (this.#doNotTrack) return
console.log(3)
try {
window.umami?.track(props => ({
...props,
url: `/${import.meta.env.VITE_LINK}${isWallpaperEngine ? "?steam" : ""}`
}));
window.counterscale = {
q: [["set", "siteId", `aklive2d-${import.meta.env.VITE_LINK}`], ["trackPageview"]],
};
console.log(4)
window.counterscaleOnDemandTrack();
console.log(5)
} catch(e) {
console.warn && console.warn(e.message)
}
}
functionInsights(functionName, toSkip = false) {
if (!this.#isInsightsInited || this.#doNotTrack || import.meta.env.MODE === 'development' || functionName === this.#lastFunctionInsights || toSkip) return
try {
window.umami?.track(props => ({
...props,
name: `${functionName}`,
url: `/${import.meta.env.VITE_LINK}${this.isWallpaperEngine ? "?steam" : ""}`
}));
} catch (e) {
console.warn && console.warn(e.message)
}
}
setFPS(value) {
this.#fps = value
this.spinePlayer.setFps(value)
this.functionInsights("setFPS", this.isWallpaperEngine)
}
setLogoDisplay(flag) {
this.#logoEl.hidden = flag;
this.functionInsights("setLogoDisplay", this.isWallpaperEngine)
}
#resize(_this, value) {
@@ -136,7 +125,6 @@ export default class Settings {
this.#logoEl.src = src
this.#resize()
this.#setLogoInvertFilter(invert_filter)
this.functionInsights("setLogo", this.isWallpaperEngine)
}
#readFile(e, callback = () => { }) {
@@ -163,18 +151,15 @@ export default class Settings {
setLogoRatio(value) {
this.#ratio = value
this.#resize(this, value)
this.functionInsights("setLogoRatio", this.isWallpaperEngine)
}
setLogoOpacity(value) {
this.#logoEl.style.opacity = value / 100
this.#opacity = value
this.functionInsights("setLogoOpacity", this.isWallpaperEngine)
}
setBackgoundImage(v, skipInsights = false) {
setBackgoundImage(v) {
document.body.style.backgroundImage = v
if (!skipInsights) this.functionInsights("setBackgoundImage", this.isWallpaperEngine);
}
get currentBackground() {
@@ -187,9 +172,8 @@ export default class Settings {
setDefaultBackground(e) {
this.#defaultBackgroundImage = `url("${import.meta.env.BASE_URL}assets/${import.meta.env.VITE_BACKGROUND_FOLDER}/${e}")`
if (document.getElementById("custom_background_clear").disabled && !document.body.style.backgroundImage.startsWith("url(\"file:")) {
this.setBackgoundImage(this.#defaultBackgroundImage, true)
this.setBackgoundImage(this.#defaultBackgroundImage)
}
this.functionInsights("setDefaultBackground", this.isWallpaperEngine)
}
setBackground(e) {
@@ -247,7 +231,6 @@ export default class Settings {
break;
}
this.loadViewport()
this.functionInsights("positionPadding", this.isWallpaperEngine)
}
positionReset() {
@@ -297,7 +280,6 @@ export default class Settings {
break;
}
this.elementPosition(this.#logoEl, this.#logoX, this.#logoY)
this.functionInsights("logoPadding", this.isWallpaperEngine)
}
logoReset() {

View File

@@ -67,7 +67,6 @@ export default class Voice {
set useSubtitle(show) {
this.#useSubtitle = show
this.#el.hidden = !show
window.settings.functionInsights("useSubtitle", window.settings.isWallpaperEngine)
}
get useSubtitle() {
@@ -78,7 +77,6 @@ export default class Voice {
* @param {boolean} show
*/
set useVoice(show) {
window.settings.functionInsights("useVoice", window.settings.isWallpaperEngine)
this.#useVoice = show
this.#playEntryVoice()
if (!show && this.#isPlaying) {
@@ -96,7 +94,6 @@ export default class Voice {
set useVoiceActor(show) {
this.#useVoiceActor = show
document.getElementById('voice_actor_box').hidden = !show
window.settings.functionInsights("useVoiceActor", window.settings.isWallpaperEngine)
}
get useVoiceActor() {
@@ -112,7 +109,6 @@ export default class Voice {
} else {
this.#subtitleLang = this.#defaultRegion
}
window.settings.functionInsights("subtitleLanguage", window.settings.isWallpaperEngine)
}
get subtitleLanguage() {
@@ -149,7 +145,6 @@ export default class Voice {
#updateSubtitlePosition() {
window.settings.elementPosition(this.#el, this.#subtitleX, this.#subtitleY)
window.settings.functionInsights("subtitlePosition", window.settings.isWallpaperEngine)
}
/**
@@ -161,7 +156,6 @@ export default class Voice {
} else {
this.#voiceLang = this.#defaultVoiceLang
}
window.settings.functionInsights("language", window.settings.isWallpaperEngine)
const availableSubtitleLang = this.#getSubtitleLanguages()
if (!availableSubtitleLang.includes(this.#subtitleLang)) {
this.#subtitleLang = availableSubtitleLang[0]
@@ -185,7 +179,6 @@ export default class Voice {
this.#idleDuration = duration * 60 * 1000
this.#initIdleVoiceTimer()
}
window.settings.functionInsights("idleDuration", window.settings.isWallpaperEngine)
}
get idleDuration() {
@@ -201,7 +194,6 @@ export default class Voice {
this.#nextDuration = duration * 60 * 1000
this.#initNextVoiceTimer()
}
window.settings.functionInsights("nextDuration", window.settings.isWallpaperEngine)
}
get nextDuration() {