Plugin system

Plugin Analytics

Learn how to use the Analytics plugin in Orama.

This plugin relies on Orama Cloud (free plan).

Installation

First of all, install it via npm (or any other package manager of your choice):

npm install @orama/plugin-analytics

Then, add it to your Orama configuration:

import { Orama } from '@orama/core';
import { pluginAnalytics } from '@orama/plugin-analytics';

const db = create({
  schema: { name: 'string' } as const,
  plugins: [
    pluginAnalytics({
      apiKey: 'your-api-key',
      indexId: 'your-index-id',
    })
  ]
})

insertMultiple(db, [
  { name: 'foo' },
  { name: 'bar' },
  { name: 'baz' },
])

// Collects anonymous analytics data and sends it to Orama Cloud
search(db, { term: 'foo' })

Disabling Analytics

By default, Orama is shipped without analytics plugin. If you want to enable it, you need to explicitly add it to your configuration as described above.

Anyway, you can disable it by passing enabled: false to the pluginAnalytics function in your configuration, like this:

import { Orama } from '@orama/core';
import { pluginAnalytics } from '@orama/plugin-analytics';

const db = create({
  schema: { name: 'string' } as const,
  plugins: [
    pluginAnalytics({
      apiKey: 'your-api-key',
      indexId: 'your-index-id',
      enabled: false, // <--- disable analytics
    })
  ]
})

This flag is useful when you want to disable analytics in development environment, for example.

Last updated on