basic telemetry

This commit is contained in:
Jeffrey Morgan
2023-07-06 17:32:48 -04:00
parent 8681ba0ee2
commit b9a186c820
4 changed files with 334 additions and 37 deletions

View File

@@ -3,6 +3,8 @@ import { app, autoUpdater, dialog, Tray, Menu, nativeTheme } from 'electron'
import * as path from 'path'
import * as fs from 'fs'
import { analytics, id } from './telemetry'
require('@electron/remote/main').initialize()
let tray: Tray | null = null
@@ -172,9 +174,20 @@ autoUpdater.setFeedURL({
url: `https://ollama.ai/api/update?os=${process.platform}&arch=${process.arch}&version=${app.getVersion()}`,
})
async function heartbeat() {
analytics.track({
anonymousId: id(),
event: 'heartbeat',
})
}
heartbeat()
if (app.isPackaged) {
heartbeat()
autoUpdater.checkForUpdates()
setInterval(() => {
heartbeat()
autoUpdater.checkForUpdates()
}, 60000)
}

19
app/src/telemetry.ts Normal file
View File

@@ -0,0 +1,19 @@
import { Analytics } from '@segment/analytics-node'
import { v4 as uuidv4 } from 'uuid'
const Store = require('electron-store')
const store = new Store()
export const analytics = new Analytics({ writeKey: process.env.TELEMETRY_WRITE_KEY })
export function id(): string {
const id = store.get('id')
if (id) {
return id
}
const uuid = uuidv4()
store.set('id', uuid)
return uuid
}