initial for v1

This commit is contained in:
Carl-Gerhard Lindesvärd
2024-07-28 00:05:32 +02:00
committed by Carl-Gerhard Lindesvärd
parent c770634e73
commit 15e997129a
23 changed files with 1019 additions and 528 deletions

View File

@@ -2,28 +2,31 @@ import { AppState, Platform } from 'react-native';
import * as Application from 'expo-application';
import Constants from 'expo-constants';
import type { OpenpanelSdkOptions, PostEventPayload } from '@openpanel/sdk';
import { OpenpanelSdk } from '@openpanel/sdk';
import type { OpenPanelOptions, TrackProperties } from '@openpanel/sdk';
import { OpenPanel as OpenPanelBase } from '@openpanel/sdk';
export * from '@openpanel/sdk';
export type OpenpanelOptions = OpenpanelSdkOptions;
export class Openpanel extends OpenpanelSdk<OpenpanelOptions> {
constructor(options: OpenpanelOptions) {
super(options);
export class OpenPanel extends OpenPanelBase {
constructor(public options: OpenPanelOptions) {
super({
...options,
sdk: 'react-native',
sdkVersion: process.env.REACT_NATIVE_VERSION!,
});
this.api.headers['User-Agent'] = Constants.getWebViewUserAgentAsync();
this.api.addHeader('User-Agent', Constants.getWebViewUserAgentAsync());
AppState.addEventListener('change', (state) => {
if (state === 'active') {
this.setProperties();
this.setDefaultProperties();
}
});
this.setProperties();
this.setDefaultProperties();
}
private async setProperties() {
private async setDefaultProperties() {
this.setGlobalProperties({
__version: Application.nativeApplicationVersion,
__buildNumber: Application.nativeBuildVersion,
@@ -34,11 +37,8 @@ export class Openpanel extends OpenpanelSdk<OpenpanelOptions> {
});
}
public screenView(
route: string,
properties?: PostEventPayload['properties']
): void {
super.event('screen_view', {
public screenView(route: string, properties?: TrackProperties): void {
super.track('screen_view', {
...properties,
__path: route,
});

View File

@@ -15,15 +15,16 @@
"@openpanel/eslint-config": "workspace:*",
"@openpanel/prettier-config": "workspace:*",
"@openpanel/tsconfig": "workspace:*",
"@types/node": "^20.14.12",
"eslint": "^8.48.0",
"prettier": "^3.0.3",
"tsup": "^7.2.0",
"typescript": "^5.2.2"
},
"peerDependencies": {
"react-native": "0.73 - 0.74",
"expo-application": "^5",
"expo-constants": "14 - 16"
"expo-constants": "14 - 16",
"react-native": "0.73 - 0.74"
},
"eslintConfig": {
"root": true,

View File

@@ -2,4 +2,6 @@ import { defineConfig } from 'tsup';
import config from '@openpanel/tsconfig/tsup.config.json' assert { type: 'json' };
export default defineConfig(config as any);
export default defineConfig({
...(config as any),
});