getEventCount

Analytics method to retrieve the total count of a specific event.

import { getEventCount } 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.

Example

import { getEventCount } from 'basehub/analytics'
import { IncrementViews } from './increment-views'
import { unstable_noStore } from 'next/cache'
import { draftMode } from 'next/headers'

export const ViewsFragment = async ({
  _analyticsKey,
  increment,
}: {
  _analyticsKey: string
  increment?: boolean
}) => {
  unstable_noStore()
  const { isEnabled: isDraftMode } = draftMode()
  const views = await getEventCount({ _analyticsKey, name: 'view' }) 
  return (
    <>
      {views || '0'}
      {increment && !isDraftMode && (
        <IncrementViews _analyticsKey={_analyticsKey} />
      )}
    </>
  )
}