sendEvent

The analytics method to send any event through BaseHub. Flexible, scoped by block.

import { sendEvent } from 'basehub/analytics'

Parameters

Key

Type

Description

name

string

Required. The event unique name, it can be any string.

_analyticsKey

string

Required. The targeted block analytics key.

metadata

Record<string, unknown>

Optional metadata, can be any valid JSON object. It won’t be displayed in the current analytics implementation, but it’s stored in the event object in the background.

Example

'use client'
import { sendEvent } from 'basehub/analytics'
import { Card, IconButton } from '@radix-ui/themes'
import { ThumbsDown, ThumbsUp } from 'lucide-react'
import * as React from 'react'

export const Feedback = ({
  analyticsKey: _analyticsKey,
}: {
  analyticsKey: string
}) => {
  const [sentFeedback, setSentFeedback] = React.useState<
    'positive' | 'negative' | null
  >(null)

  const handleFeedback = (type: 'positive' | 'negative') => {
    if (sentFeedback === type) return
    sendEvent({ _analyticsKey, name: `feedback:${type}` }) 

    setSentFeedback(type)
  }

  return (
    <Card variant="classic" size="3">
      <IconButton onClick={() => handleFeedback('negative')}>
        <ThumbsDown fill={sentFeedback === 'negative' ? 'var(--accent-12)' : 'none'} />
      </IconButton>
      <IconButton onClick={() => handleFeedback('positive')}>
        <ThumbsUp fill={sentFeedback === 'positive' ? 'var(--accent-12)' : 'none'} />
      </IconButton>
    </Card>
  )
}