Files
stats/packages/sdks/react-native/index.ts
Carl-Gerhard Lindesvärd 4483e464d1 fix: optimize event buffer (#278)
* fix: how we fetch profiles in the buffer

* perf: optimize event buffer

* remove unused file

* fix

* wip

* wip: try groupmq 2

* try simplified event buffer with duration calculation on the fly instead
2026-03-16 13:29:40 +01:00

52 lines
1.4 KiB
TypeScript

import type { OpenPanelOptions, TrackProperties } from '@openpanel/sdk';
import { OpenPanel as OpenPanelBase } from '@openpanel/sdk';
import * as Application from 'expo-application';
import Constants from 'expo-constants';
import { AppState, Platform } from 'react-native';
export * from '@openpanel/sdk';
export class OpenPanel extends OpenPanelBase {
private lastPath = '';
constructor(public options: OpenPanelOptions) {
super({
...options,
sdk: 'react-native',
sdkVersion: process.env.REACT_NATIVE_VERSION!,
});
this.api.addHeader('User-Agent', Constants.getWebViewUserAgentAsync());
AppState.addEventListener('change', (state) => {
if (state === 'active') {
this.setDefaultProperties();
}
});
this.setDefaultProperties();
}
private async setDefaultProperties() {
this.setGlobalProperties({
__version: Application.nativeApplicationVersion,
__buildNumber: Application.nativeBuildVersion,
__referrer:
Platform.OS === 'android'
? await Application.getInstallReferrerAsync()
: undefined,
});
}
track(name: string, properties?: TrackProperties) {
return super.track(name, { ...properties, __path: this.lastPath });
}
screenView(route: string, properties?: TrackProperties): void {
this.lastPath = route;
super.track('screen_view', {
...properties,
__path: route,
});
}
}