#convex-analytics

3 messages · Page 1 of 1 (latest)

graceful bear
#

Hey, I released the first version of convex-analytics, a lightweight package for integrating any analytics tool and admin notification system into your Convex backend.

What it does:

  • Call analytics.track() from your actions/mutations to register events.
  • Register processors at installation to handle those events however you want.
  • 2 prebuilt processors included: Discord webhooks & PostHog (more coming soon).
  • Build custom processors to fit your specific needs.

What's planned:

  • Improved typing of events names and content.
  • Automatic retries on processor failures.
  • Post-processing hooks (cleanup, archiving, etc).
  • More built-in processors.
  • And more...

To try it out: https://github.com/raideno/convex-analytics

Still early stage, so expect things to evolve. If you try it out, I'd love your feedback, suggestions, or bug reports. Check out the repo and demo app to get started.

GitHub

Contribute to raideno/convex-analytics development by creating an account on GitHub.

#
import { internalConvexAnalytics } from "@raideno/convex-analytics/server";
import { DiscordProcessorFactory } from "@raideno/convex-analytics/processors/discord";
import { PosthogProcessorFactory } from "@raideno/convex-analytics/processors/posthog";

import configuration from "./analytics.config";

export const { store, analytics, process } = internalConvexAnalytics({
    processors: [
        /*
         * Will only capture events named "demo_perform_action".
         */
        DiscordProcessorFactory({
            url: process.env.DISCORD_WEBHOOK_URL!,
            events: ["demo_perform_action"],
        }),
        /*
         * Will capture all events.
         */
        PosthogProcessorFactory({
            key: process.env.POSTHOG_KEY!,
            host: "https://us.i.posthog.com",
            events: ["*"],
        }),
    ],
    processEveryK: 1,
});

Then inside of an action or a mutation you can do:

analytics.track(context, {
  name: "demo_perform_action",
  distinctId: "<your-user-id>",
  properties: {}
});

Your processors will be automatically waken up to process this event and do whatever you want with it.

lament bramble
#

Wild timing! I was just considering building my own posthog integration from scratch!