Skip to content

Split any YouTube song into stems

TypeScript

remove google analytics from the app

Daniel Ravina976ec92e4bbd
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..69470b2
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2026 Daniel Ravina
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
\ No newline at end of file
diff --git a/electron.vite.config.ts b/electron.vite.config.ts
index 9139bae..96f3aaf 100644
--- a/electron.vite.config.ts
+++ b/electron.vite.config.ts
@@ -1,20 +1,11 @@
-import { defineConfig, loadEnv } from 'electron-vite'
+import { defineConfig } from 'electron-vite'
import react from '@vitejs/plugin-react'
import tailwindcss from '@tailwindcss/vite'
-export default defineConfig(({ mode }) => {
- // .env values (and shell overrides) bake into the main bundle at build time
- const env = loadEnv(mode ?? 'production', process.cwd(), '')
- return {
- main: {
- define: {
- __STEMKIT_GA_ID__: JSON.stringify(env.STEMKIT_GA_ID ?? ''),
- __STEMKIT_GA_SECRET__: JSON.stringify(env.STEMKIT_GA_SECRET ?? '')
- }
- },
- preload: {},
- renderer: {
- plugins: [react(), tailwindcss()]
- }
+export default defineConfig({
+ main: {},
+ preload: {},
+ renderer: {
+ plugins: [react(), tailwindcss()]
}
})
diff --git a/src/main/analytics.ts b/src/main/analytics.ts
deleted file mode 100644
index 43209fc..0000000
--- a/src/main/analytics.ts
+++ /dev/null
@@ -1,134 +0,0 @@
-import { randomUUID } from 'crypto'
-import { readFileSync, writeFileSync, mkdirSync } from 'fs'
-import { release } from 'os'
-import { join } from 'path'
-import { app, net } from 'electron'
-import { userDataDir } from './env'
-import { loadSettings } from './settings'
-
-/* GA4 Measurement Protocol (server-side from the main process — the renderer
- stays CSP-isolated and nothing google ever runs in the app). Fill these in
- to enable reporting: GA4 property Measurement ID + a Measurement Protocol
- API secret (GA Admin → Data streams → stream → Measurement Protocol API
- secrets). Values are baked in at build time via STEMKIT_GA_ID /
- STEMKIT_GA_SECRET (see electron.vite.config.ts), with runtime env vars as a
- fallback. With either value missing, track() is a no-op. */
-const MEASUREMENT_ID = __STEMKIT_GA_ID__ || process.env.STEMKIT_GA_ID || ''
-const API_SECRET = __STEMKIT_GA_SECRET__ || process.env.STEMKIT_GA_SECRET || ''
-
-const OS_NAMES: Record<string, string> = {
- darwin: 'macOS',
- win32: 'Windows',
- linux: 'Linux'
-}
-
-let sessionStart = 0
-let sessionId: string | null = null
-let clientId: string | null = null
-
-function clientFile(): string {
- return join(userDataDir(), 'analytics-client.json')
-}
-
-function ensureClientId(): string {
- if (clientId) return clientId
- try {
- const raw = readFileSync(clientFile(), 'utf8')
- const data = JSON.parse(raw)
- if (typeof data.clientId === 'string' && data.clientId) clientId = data.clientId
- } catch {}
- if (!clientId) {
- clientId = randomUUID()
- try {
- mkdirSync(userDataDir(), { recursive: true })
- writeFileSync(clientFile(), JSON.stringify({ clientId }, null, 2))
- } catch {}
- }
- return clientId
-}
-
-function ensureSessionId(): string {
- // roll a new session when the app has been idle long enough to count as a
- // new visit (GA's default 30 min timeout)
- if (!sessionId || Date.now() - sessionStart > 30 * 60 * 1000) {
- sessionId = randomUUID()
- }
- sessionStart = Date.now()
- return sessionId
-}
-
-export function track(
- name: string,
- params: Record<string, string | number | boolean> = {},
- engagementMs = 100
-): void {
- if (!MEASUREMENT_ID || !API_SECRET) return
- if (!app.isReady()) return
- // consent is checked at send time so opting out takes effect immediately
- if (!loadSettings().analytics) return
-
- const flat: Record<string, string | number> = {
- session_id: ensureSessionId(),
- engagement_time_msec: engagementMs,
- app_version: app.getVersion(),
- os: OS_NAMES[process.platform] ?? process.platform,
- os_version: release(),
- arch: process.arch
- }
- for (const [k, v] of Object.entries(params)) {
- if (k.length > 40) continue
- flat[k] = typeof v === 'boolean' ? (v ? 'true' : 'false') : v
- }
-
- const body = {
- client_id: ensureClientId(),
- // user properties need a one-time registration in GA (Admin → Custom
- // definitions) before they show up as report dimensions
- user_properties: {
- app_version: { value: app.getVersion() },
- os: { value: OS_NAMES[process.platform] ?? process.platform },
- os_version: { value: release() },
- arch: { value: process.arch }
- },
- events: [{ name: name.slice(0, 40), params: flat }]
- }
-
- void net
- .fetch(
- `https://www.google-analytics.com/mp/collect?measurement_id=${encodeURIComponent(MEASUREMENT_ID)}&api_secret=${encodeURIComponent(API_SECRET)}`,
- {
- method: 'POST',
- headers: { 'content-type': 'application/json' },
- body: JSON.stringify(body),
- signal: AbortSignal.timeout(8000)
- }
- )
- .catch(() => {})
-}
-
-/* engagement beacon: GA infers session length from the timestamps between
- events, which for a desktop app with sparse events reads as ~instant. A
- 5-minute heartbeat carrying its own interval as engagement time makes
- session duration and average engagement meaningful (heartbeats also keep
- the session alive for long-running windows). track() no-ops without
- credentials or consent, so the timer is effectively free when disabled. */
-const HEARTBEAT_MS = 5 * 60 * 1000
-setInterval(() => {
- track('session_heartbeat', {}, HEARTBEAT_MS)
-}, HEARTBEAT_MS).unref()
-
-const VALID_NAME = /^[a-z][a-z0-9_]{0,39}$/
-
-// events coming from the renderer go through a strict shape check
-export function trackFromRenderer(
- name: unknown,
- params: unknown
-): void {
- if (typeof name !== 'string' || !VALID_NAME.test(name)) return
- if (params !== undefined && (params === null || typeof params !== 'object' || Array.isArray(params))) return
- const flat: Record<string, string | number | boolean> = {}
- for (const [k, v] of Object.entries(params ?? {})) {
- if (typeof v === 'string' || typeof v === 'number' || typeof v === 'boolean') flat[k] = v
- }
- track(name, flat)
-}
\ No newline at end of file
diff --git a/src/main/globals.d.ts b/src/main/globals.d.ts
deleted file mode 100644
index 4fae1a9..0000000
--- a/src/main/globals.d.ts
+++ /dev/null
@@ -1,3 +0,0 @@
-// build-time constants injected by electron.vite.config.ts (main.define)
-declare const __STEMKIT_GA_ID__: string
-declare const __STEMKIT_GA_SECRET__: string
\ No newline at end of file
diff --git a/src/main/index.ts b/src/main/index.ts
index 1fd21f7..ccec0d6 100644
--- a/src/main/index.ts
+++ b/src/main/index.ts
@@ -24,7 +24,6 @@ import { loadSongs, removeSong, stemBuffers, stemsDir, stemsFor, mixWavPath } fr
import { startJob, cancelJob, searchYouTube } from './pipeline'
import { initUpdater } from './updater'
import { runSmoke } from './smoke'
-import { track, trackFromRenderer } from './analytics'
import { getThumb, clearThumbMemo } from './thumbs'
let mainWindow: BrowserWindow | null = null
@@ -183,7 +182,6 @@ app.whenReady().then(async () => {
})
if (result.canceled || !result.filePath) return { saved: false }
copyFileSync(file, result.filePath)
- track('export', { kind: 'stem', stem })
return { saved: true, path: result.filePath }
})
@@ -211,7 +209,6 @@ app.whenReady().then(async () => {
copyFileSync(mix, join(target, `${sanitizeName(song?.title ?? 'full track')}.wav`))
count += 1
}
- track('export', { kind: 'all', stems: count })
return { saved: true, path: target, count }
})
@@ -219,19 +216,12 @@ app.whenReady().then(async () => {
ipcMain.handle('app:version', () => app.getVersion())
ipcMain.handle('settings:get', () => loadSettings())
ipcMain.handle('settings:set', (_e, patch: Partial<AppSettings>) => {
- const prev = loadSettings()
const next = saveSettings(patch)
// hideVideo flips the thumbnail source, so cached lookups must retry
clearThumbMemo()
- for (const key of Object.keys(patch) as (keyof AppSettings)[]) {
- if (prev[key] !== next[key]) track('settings_changed', { setting: key })
- }
return next
})
ipcMain.handle('thumb:get', (_e, videoId: string) => getThumb(videoId))
- ipcMain.on('analytics:track', (_e, name: unknown, params: unknown) => {
- trackFromRenderer(name, params)
- })
// the renderer confirms optional-engine downloads explicitly; nothing
// starts as a side effect of flipping a toggle
ipcMain.handle('engines:status', () => {
@@ -253,7 +243,6 @@ app.whenReady().then(async () => {
await detectTools()
await createWindow()
- track('app_launch')
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) void createWindow()
diff --git a/src/main/pipeline.ts b/src/main/pipeline.ts
index 80fbf39..b0a089b 100644
--- a/src/main/pipeline.ts
+++ b/src/main/pipeline.ts
@@ -28,9 +28,8 @@ import {
loadSongs
} from './library'
import type { JobEvent, JobStage } from '../shared/types'
-import { MODEL_DEFAULT, MODEL_EXTENDED, DEFAULT_STEMS } from '../shared/types'
+import { MODEL_DEFAULT, MODEL_EXTENDED } from '../shared/types'
import { parseVideoId } from '../shared/url'
-import { track } from './analytics'
import { cacheThumbnail } from './thumbs'
interface ActiveJob {
@@ -157,11 +156,6 @@ export async function startJob(
rmSync(songDir(videoId), { recursive: true, force: true })
}
- track('split_started', {
- model: modelTag,
- stems: stems?.length ?? DEFAULT_STEMS.length,
- gpu: useGpu
- })
mkdirSync(songDir(videoId), { recursive: true })
progress(job, 'metadata', 0, 'Reading video info')
@@ -457,7 +451,6 @@ export async function startJob(
stems: producedStems,
took
})
- track('split_completed', { model: job.model, stems: producedStems.length, took })
send({ kind: 'done', data: { videoId, song: songs[0] } })
} finally {
release()
@@ -465,7 +458,6 @@ export async function startJob(
} catch (err) {
const message = err instanceof Error ? err.message : String(err)
if (message !== 'cancelled') {
- track('split_failed', { model: job.model })
send({ kind: 'failed', data: { videoId, message } })
}
} finally {
@@ -578,7 +570,6 @@ export async function searchYouTube(query: string): Promise<
: undefined,
duration: typeof e.duration === 'number' ? Math.round(e.duration) : undefined
}))
- track('search', { results: mapped.length })
return mapped
} catch {
return []
diff --git a/src/main/settings.ts b/src/main/settings.ts
index 302b862..64b83a9 100644
--- a/src/main/settings.ts
+++ b/src/main/settings.ts
@@ -24,8 +24,7 @@ export function saveSettings(patch: Partial<AppSettings>): AppSettings {
htdemucsFt: !!merged.htdemucsFt,
roformerVocals: !!merged.roformerVocals,
gpuSplit: !!merged.gpuSplit,
- hideVideo: !!merged.hideVideo,
- analytics: !!merged.analytics
+ hideVideo: !!merged.hideVideo
}
writeFileSync(settingsFile(), JSON.stringify(next, null, 2))
for (const win of BrowserWindow.getAllWindows()) {
diff --git a/src/main/updater.ts b/src/main/updater.ts
index b58ed5a..a749fb1 100644
--- a/src/main/updater.ts
+++ b/src/main/updater.ts
@@ -1,6 +1,5 @@
import { app, BrowserWindow, ipcMain } from 'electron'
import { autoUpdater } from 'electron-updater'
-import { track } from './analytics'
function send(status: string, payload?: Record<string, unknown>): void {
for (const win of BrowserWindow.getAllWindows()) {
@@ -16,19 +15,16 @@ export function initUpdater(): void {
autoUpdater.on('checking-for-update', () => send('checking'))
autoUpdater.on('update-available', (info) => {
- track('update_available', { version: info.version })
send('available', { version: info.version })
})
autoUpdater.on('update-not-available', (info) => send('none', { version: info.version }))
autoUpdater.on('download-progress', (p) => send('progress', { pct: Math.round(p.percent) }))
autoUpdater.on('update-downloaded', (info) => {
- track('update_downloaded', { version: info.version })
send('downloaded', { version: info.version })
})
autoUpdater.on('error', () => send('error'))
ipcMain.handle('update:install', () => {
- track('update_installed')
autoUpdater.quitAndInstall()
})
ipcMain.handle('update:check', async () => {
diff --git a/src/preload/index.ts b/src/preload/index.ts
index 4a44fcd..b711641 100644
--- a/src/preload/index.ts
+++ b/src/preload/index.ts
@@ -26,7 +26,6 @@ const api: StemKitApi = {
installUpdate: () => ipcRenderer.invoke('update:install'),
getSettings: () => ipcRenderer.invoke('settings:get'),
setSettings: (patch) => ipcRenderer.invoke('settings:set', patch),
- trackEvent: (name, params) => ipcRenderer.send('analytics:track', name, params),
getThumb: (videoId) => ipcRenderer.invoke('thumb:get', videoId),
onThumbCached: (cb) => subscribe<string>('thumb:cached', cb),
enginesStatus: () => ipcRenderer.invoke('engines:status'),
diff --git a/src/renderer/src/components/Player.tsx b/src/renderer/src/components/Player.tsx
index 9e652e8..7bcbee7 100644
--- a/src/renderer/src/components/Player.tsx
+++ b/src/renderer/src/components/Player.tsx
@@ -208,7 +208,6 @@ export function Player({ song, settings }: Props): React.ReactElement {
engine.setPlaying(true, posRef.current)
hostRef.current?.play()
setPlaying(true)
- window.stemkit.trackEvent('playback_started', { video_hidden: hideVideo })
}
}, [decoding, decodeError, hideVideo])
diff --git a/src/renderer/src/components/Settings.tsx b/src/renderer/src/components/Settings.tsx
index e88bb38..796654a 100644
--- a/src/renderer/src/components/Settings.tsx
+++ b/src/renderer/src/components/Settings.tsx
@@ -350,23 +350,6 @@ export function Settings({ settings, gpu, nvidiaGpu, onChange, onClose }: Props)
/>
</div>
</section>
-
- <section className="pt-5 border-t border-white/[0.06] space-y-5">
- <SectionHeader label="Privacy" />
- <div className="flex items-start justify-between gap-4">
- <div className="min-w-0">
- <p className="text-[13px] font-medium">Anonymous usage stats</p>
- <p className="text-[11.5px] text-white/40 leading-relaxed mt-0.5">
- Helps improve StemKit with anonymous events (app version, OS,
- actions). Song titles, links and audio never leave your machine.
- </p>
- </div>
- <Toggle
- on={settings.analytics}
- onClick={() => onChange({ analytics: !settings.analytics })}
- />
- </div>
- </section>
</div>
</div>
</div>
diff --git a/src/shared/types.ts b/src/shared/types.ts
index b940d89..bf24faa 100644
--- a/src/shared/types.ts
+++ b/src/shared/types.ts
@@ -27,8 +27,6 @@ export interface AppSettings {
// hide the YouTube video while playing: stems are always played locally,
// this stops streaming the video and falls back to cached thumbnails
hideVideo: boolean
- // anonymous usage analytics (GA4 Measurement Protocol); on by default
- analytics: boolean
}
export const DEFAULT_SETTINGS: AppSettings = {
@@ -36,8 +34,7 @@ export const DEFAULT_SETTINGS: AppSettings = {
htdemucsFt: false,
roformerVocals: false,
gpuSplit: false,
- hideVideo: false,
- analytics: true
+ hideVideo: false
}
export interface EngineStatus {
@@ -122,7 +119,6 @@ export interface StemKitApi {
installUpdate(): void
getSettings(): Promise<AppSettings>
setSettings(patch: Partial<AppSettings>): Promise<AppSettings>
- trackEvent(name: string, params?: Record<string, string | number | boolean>): void
getThumb(videoId: string): Promise<string | null>
onThumbCached(cb: (videoId: string) => void): () => void
enginesStatus(): Promise<EngineStatus>