mirror of
https://github.com/misode/misode.github.io.git
synced 2026-04-23 23:27:09 +00:00
Remove legacy GA4 code
This commit is contained in:
@@ -4,44 +4,7 @@ import type { VersionId } from './services/index.js'
|
||||
export type Method = 'menu' | 'hotkey'
|
||||
|
||||
export namespace Analytics {
|
||||
|
||||
/** Universal Analytics */
|
||||
const ID_SITE = 'Site'
|
||||
const ID_GENERATOR = 'Generator'
|
||||
|
||||
const DIM_THEME = 1
|
||||
const DIM_VERSION = 3
|
||||
const DIM_LANGUAGE = 4
|
||||
const DIM_GENERATOR = 6
|
||||
const DIM_PREFERS_COLOR_SCHEME = 7
|
||||
|
||||
function event(category: string, action: string, label?: string) {
|
||||
ga('send', 'event', category, action, label)
|
||||
}
|
||||
|
||||
function dimension(index: number, value: string) {
|
||||
ga('set', `dimension${index}`, value)
|
||||
}
|
||||
|
||||
export function pageview(page: string) {
|
||||
ga('set', 'page', page)
|
||||
ga('send', 'pageview')
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
export function generatorEvent(action: string, label?: string) {
|
||||
event(ID_GENERATOR, action, label)
|
||||
}
|
||||
|
||||
function legacyMethod(method: Method) {
|
||||
return method === 'menu' ? 'Menu' : 'Hotkey'
|
||||
}
|
||||
/** END Universal Analytics 4 */
|
||||
|
||||
export function setLocale(locale: string) {
|
||||
dimension(DIM_LANGUAGE, locale)
|
||||
gtag('set', {
|
||||
locale,
|
||||
})
|
||||
@@ -49,14 +12,12 @@ export namespace Analytics {
|
||||
|
||||
export function changeLocale(prev_locale: string, locale: string) {
|
||||
setLocale(locale)
|
||||
event(ID_SITE, 'set-language', locale)
|
||||
gtag('event', 'change_locale', {
|
||||
prev_locale,
|
||||
})
|
||||
}
|
||||
|
||||
export function setTheme(theme: string) {
|
||||
dimension(DIM_THEME, theme)
|
||||
gtag('set', {
|
||||
theme,
|
||||
})
|
||||
@@ -64,14 +25,12 @@ export namespace Analytics {
|
||||
|
||||
export function changeTheme(prev_theme: string, theme: string) {
|
||||
setTheme(theme)
|
||||
event(ID_SITE, 'set-theme', theme)
|
||||
gtag('event', 'change_theme', {
|
||||
prev_theme,
|
||||
})
|
||||
}
|
||||
|
||||
export function setVersion(version: string) {
|
||||
dimension(DIM_VERSION, version)
|
||||
gtag('set', {
|
||||
version,
|
||||
})
|
||||
@@ -85,21 +44,18 @@ export namespace Analytics {
|
||||
|
||||
export function changeVersion(prev_version: string, version: string) {
|
||||
setVersion(version)
|
||||
event(ID_GENERATOR, 'set-version', version)
|
||||
gtag('event', 'change_version', {
|
||||
prev_version,
|
||||
})
|
||||
}
|
||||
|
||||
export function setGenerator(file_type: string) {
|
||||
dimension(DIM_GENERATOR, file_type)
|
||||
gtag('event', 'use_generator', {
|
||||
file_type,
|
||||
})
|
||||
}
|
||||
|
||||
export function setPrefersColorScheme(prefers_color_scheme: string) {
|
||||
dimension(DIM_PREFERS_COLOR_SCHEME, prefers_color_scheme)
|
||||
gtag('set', {
|
||||
prefers_color_scheme,
|
||||
})
|
||||
@@ -118,7 +74,6 @@ export namespace Analytics {
|
||||
}
|
||||
|
||||
export function resetGenerator(file_type: string, history: number, method: Method) {
|
||||
event(ID_GENERATOR, 'reset')
|
||||
gtag('event', 'reset_generator', {
|
||||
file_type,
|
||||
history,
|
||||
@@ -127,7 +82,6 @@ export namespace Analytics {
|
||||
}
|
||||
|
||||
export function undoGenerator(file_type: string, history: number, method: Method) {
|
||||
event(ID_GENERATOR, 'undo', legacyMethod(method))
|
||||
gtag('event', 'undo_generator', {
|
||||
file_type,
|
||||
history,
|
||||
@@ -136,7 +90,6 @@ export namespace Analytics {
|
||||
}
|
||||
|
||||
export function redoGenerator(file_type: string, history: number, method: Method) {
|
||||
event(ID_GENERATOR, 'redo', legacyMethod(method))
|
||||
gtag('event', 'redo_generator', {
|
||||
file_type,
|
||||
history,
|
||||
@@ -145,7 +98,6 @@ export namespace Analytics {
|
||||
}
|
||||
|
||||
export function loadPreset(file_type: string, file_name: string) {
|
||||
event(ID_GENERATOR, 'load-preset', file_name)
|
||||
gtag('event', 'load_generator_preset', {
|
||||
file_type,
|
||||
file_name,
|
||||
@@ -179,7 +131,6 @@ export namespace Analytics {
|
||||
}
|
||||
|
||||
export function copyOutput(file_type: string, method: Method) {
|
||||
event(ID_GENERATOR, 'copy')
|
||||
gtag('event', 'copy_generator_output', {
|
||||
file_type,
|
||||
method,
|
||||
@@ -187,7 +138,6 @@ export namespace Analytics {
|
||||
}
|
||||
|
||||
export function downloadOutput(file_type: string, method: Method) {
|
||||
event(ID_GENERATOR, 'download')
|
||||
gtag('event', 'download_generator_output', {
|
||||
file_type,
|
||||
method,
|
||||
@@ -195,7 +145,6 @@ export namespace Analytics {
|
||||
}
|
||||
|
||||
export function showOutput(file_type: string, method: Method) {
|
||||
event(ID_GENERATOR, 'toggle-output', 'visible')
|
||||
gtag('event', 'show_generator_output', {
|
||||
file_type,
|
||||
method,
|
||||
@@ -203,7 +152,6 @@ export namespace Analytics {
|
||||
}
|
||||
|
||||
export function hideOutput(file_type: string, method: Method) {
|
||||
event(ID_GENERATOR, 'toggle-output', 'hidden')
|
||||
gtag('event', 'hide_generator_output', {
|
||||
file_type,
|
||||
method,
|
||||
@@ -211,7 +159,6 @@ export namespace Analytics {
|
||||
}
|
||||
|
||||
export function showPreview(file_type: string, method: Method) {
|
||||
event(ID_GENERATOR, 'toggle-preview', 'visible')
|
||||
gtag('event', 'show_generator_preview', {
|
||||
file_type,
|
||||
method,
|
||||
@@ -219,7 +166,6 @@ export namespace Analytics {
|
||||
}
|
||||
|
||||
export function hidePreview(file_type: string, method: Method) {
|
||||
event(ID_GENERATOR, 'toggle-preview', 'hidden')
|
||||
gtag('event', 'hide_generator_preview', {
|
||||
file_type,
|
||||
method,
|
||||
@@ -227,42 +173,36 @@ export namespace Analytics {
|
||||
}
|
||||
|
||||
export function showProject(method: Method) {
|
||||
event(ID_GENERATOR, 'show-project', legacyMethod(method))
|
||||
gtag('event', 'show_project', {
|
||||
method,
|
||||
})
|
||||
}
|
||||
|
||||
export function hideProject(method: Method) {
|
||||
event(ID_GENERATOR, 'hide-project', legacyMethod(method))
|
||||
gtag('event', 'hide_project', {
|
||||
method,
|
||||
})
|
||||
}
|
||||
|
||||
export function saveProjectFile(method: Method) {
|
||||
event(ID_GENERATOR, 'save-project-file', legacyMethod(method))
|
||||
gtag('event', 'save_project_file', {
|
||||
method,
|
||||
})
|
||||
}
|
||||
|
||||
export function deleteProjectFile(method: Method) {
|
||||
event(ID_GENERATOR, 'delete-project-file', legacyMethod(method))
|
||||
gtag('event', 'delete_project_file', {
|
||||
method,
|
||||
})
|
||||
}
|
||||
|
||||
export function renameProjectFile(method: Method) {
|
||||
event(ID_GENERATOR, 'rename-project-file', legacyMethod(method))
|
||||
gtag('event', 'rename_project_file', {
|
||||
method,
|
||||
})
|
||||
}
|
||||
|
||||
export function deleteProject(method: Method) {
|
||||
event(ID_GENERATOR, 'delete-project', legacyMethod(method))
|
||||
gtag('event', 'delete_project', {
|
||||
method,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user