StartupKitstartupkit
AnalyticsUsage

useAnalytics

Hook for tracking events and identifying users

The main hook for analytics in client components.

Import

import {  } from "@repo/analytics"

Usage

"use client"

import {  } from "@repo/analytics"

export function () {
  const { , , ,  } = ()

  return (
    < ={() => ("BUTTON_CLICKED", { : "cta" })}>
      Click me
    </>
  )
}

Return Value

MethodDescription
trackTrack a custom event with optional properties
identifyAssociate events with a user identity
pageTrack a page view (automatic in Next.js)
resetClear user identity (on logout)

Example

"use client"

import {  } from "@repo/analytics"
import {  } from "@repo/auth"

export function () {
  const { ,  } = ()
  const {  } = ()

  async function () {
    ("EXPORT_CLICKED", { : "csv" })
    await exportData()
  }

  async function () {
    await ()
    ()
  }

  return (
    <>
      < ={}>Export</>
      < ={}>Sign Out</>
    </>
  )
}

On this page