Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

693 B
Raw Blame
import * as crypto from 'crypto'

export const MOBILE_BROWSER_VARIANTS: Record<string, string> = {
  Chrome: 'Mobile Chrome',
  Firefox: 'Mobile Firefox',
  Safari: 'Mobile Safari',
}

export function normalizeNull(value: string | undefined): string | null {
  if (!value || value === '' || value === '\\N') return null
  return value
}

export function truncate(value: string | null, maxLen: number): string | null {
  if (!value) return null
  return value.length > maxLen ? value.slice(0, maxLen) : value
}

export function sessionIdToPsid(sessionId: string): string {
  return crypto
    .createHash('sha256')
    .update(sessionId)
    .digest()
    .readBigUInt64BE(0)
    .toString()
}