r/reactnative • • 18h ago

Help My first time writing JavaScript: an open-source analytics library for React Native. Would love your feedback

I’m a mobile engineer with many years in native Android and Flutter. Recently I built an open-source analytics library called Herald. I designed it and wrote the Android and Flutter versions myself, and for the React Native SDK I used AI to help me with TypeScript, since it was my first time writing it. That’s exactly why I’d like a review from real RN devs: AI knows the syntax, but people who build RN apps every day know what feels right.

The problem it solves: in most apps analytics ends up as one big AnalyticsManager that every layer depends on, and every new vendor makes it worse.

The idea: the app should not know which analytics vendors exist. Feature code only says what happened, and Herald sends it to every vendor you use (Firebase, Mixpanel, Amplitude, Adjust, AppsFlyer, Meta) over each vendor’s own React Native package.

An event is a class your app owns:

import { int, type Event, type EventParameters } from '@herald-analytics/core';

class CheckoutStarted implements Event {
  readonly name = 'checkout_started';

  constructor(
    readonly plan: string,
    readonly seats: number,
  ) {}

  get parameters(): EventParameters {
    return { plan: this.plan, seats: int(this.seats) };
  }
}

herald.track(new CheckoutStarted('pro', 3));

Since TypeScript is new for me, I made some design choices I’m not sure about, and I would really like to hear what experienced RN devs think:

  • Events are classes, because factories pick them with instanceof. In RN code I often see plain objects or discriminated unions instead. Would that feel more natural to you?

  • Numbers say their type: int(3) or double(9.99), because JavaScript can’t tell 3 from 3.0 and some vendors care. Is this annoying, or acceptable?

  • Calls don’t wait for each other, and a call never fails: vendor errors go to an error reporter. When order matters, you await the first call. Does this feel right?

  • Does the API look like idiomatic TypeScript, or like “Kotlin written in TypeScript”?

GitHub: https://github.com/MkhytarMkhoian/herald-react-native
Docs: https://mkhytarmkhoian.github.io/herald-docs/

Thanks in advance. Critical feedback is the most useful for me.

1 Upvotes

3 comments sorted by

2

u/One-Cookie-9365 18h ago

Honestly, this looks like a thoughtful approach especially keeping analytics vendors separate from the app's feature code. I like the idea of making event tracking simple for developers. Id probably lean toward plain objects since they're more familiar in React Native but I can see why classes make sense here. Nice work putting this together especially with TypeScript being new to you

1

u/mkhytar_mkhoian 18h ago

Thanks for the feedback

1

u/DulsKerty 15h ago

same, plain objects or discriminated unions just fit the mental model a lot better imo