Skip to content

Commit

Permalink
add a few trackign events
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobsjo committed Sep 25, 2024
1 parent 49bde64 commit b92431f
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/components/LocaleChanger.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script setup lang="ts">
import { useSettingsStore } from '../stores/useSettingsStore';
import { EventTracker } from '../util/EventTracker';
const settingsStore = useSettingsStore()
Expand All @@ -8,6 +9,7 @@ function updateUrlSearch(locale: string) {
const params = new URLSearchParams(uri)
params.set('lang', locale)
history.replaceState({}, "", "?" + params.toString())
EventTracker.track(`change_locale/${locale}`)
}
</script>
Expand Down
2 changes: 2 additions & 0 deletions src/components/MenuButtons.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { vOnClickOutside }from '@vueuse/components';
import { useSearchStore } from '../stores/useBiomeSearchStore';
import StructureDropdown from './dropdown/StructureDropdown.vue';
import { useSettingsStore } from '../stores/useSettingsStore';
import { EventTracker } from '../util/EventTracker';
const datapackStore = useDatapackStore()
const searchStore = useSearchStore()
Expand All @@ -17,6 +18,7 @@ const searchBiomeDropdownOpen = ref(false)
const structureDropdownOpen = ref(false)
function reload(event: MouseEvent){
EventTracker.track("reload")
datapackStore.$patch({})
}
Expand Down
5 changes: 5 additions & 0 deletions src/components/dropdown/OpenDropdown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { useRecentStore } from '../../stores/useRecentStore';
import { useI18n } from 'vue-i18n';
import { useSettingsStore } from '../../stores/useSettingsStore';
import { versionMetadata } from '../../util';
import { EventTracker } from '../../util/EventTracker';
const i18n = useI18n()
Expand All @@ -27,9 +28,11 @@ async function loadHandle(handle: FileSystemHandle) {
const file = await (handle as FileSystemFileHandle).getFile()
datapack = Datapack.fromZipFile(file, versionMetadata[settingsStore.mc_version].datapackFormat)
recentStore.addRecent(handle, datapack)
EventTracker.track(`add_datapack/recent/zip`)
} else {
datapack = Datapack.fromFileSystemDirectoryHandle(handle as FileSystemDirectoryHandle, versionMetadata[settingsStore.mc_version].datapackFormat)
recentStore.addRecent(handle, datapack)
EventTracker.track(`add_datapack/recent/folder`)
}
datapackStore.addDatapack(datapack)
} catch (e){
Expand All @@ -53,6 +56,7 @@ async function loadUrl(url: string) {
async function loadZip(event: MouseEvent) {
async function addZipDatapack(file: File) {
EventTracker.track(`add_datapack/zip`)
const datapack = Datapack.fromZipFile(file, versionMetadata[settingsStore.mc_version].datapackFormat)
datapackStore.addDatapack(datapack)
return datapack
Expand Down Expand Up @@ -131,6 +135,7 @@ async function loadFolder(event: MouseEvent) {
}
if (datapack !== undefined) {
EventTracker.track(`add_datapack/folder`)
datapackStore.addDatapack(datapack)
}
emit('close')
Expand Down
21 changes: 21 additions & 0 deletions src/stores/useSettingsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { defineStore } from "pinia";
import { computed, ref, watch } from "vue";
import { useI18n } from "vue-i18n";
import { useDatapackStore } from "./useDatapackStore";
import { EventTracker } from "../util/EventTracker";

export const useSettingsStore = defineStore('settings', () => {
const i18n = useI18n()
Expand All @@ -17,6 +18,26 @@ export const useSettingsStore = defineStore('settings', () => {

const datapackStore = useDatapackStore()

watch(mc_version, (new_version) => {
EventTracker.track(`change_version/${new_version}`)
})

watch(world_preset, () => {
EventTracker.track(`change_world_preset`)
})

watch(dimension, () => {
EventTracker.track(`change_dimension`)
})

watch(seed, () => {
EventTracker.track(`change_seed`)
})

watch(dev_mode, (new_dev_mode) => {
EventTracker.track(`change_dev_mode/${new_dev_mode}`)
})

datapackStore.$subscribe(async () => {
if ((await datapackStore.dimensions)?.findIndex((id) => id.equals(dimension.value)) === -1) {
dimension.value = (await datapackStore.dimensions)[0]
Expand Down
7 changes: 7 additions & 0 deletions src/util/EventTracker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export namespace EventTracker {
export function track(event: string ){
if ((window as any).beam !== undefined) {
(window as any).beam("/event/" + event)
}
}
}

0 comments on commit b92431f

Please sign in to comment.