sdk changes
This commit is contained in:
@@ -1,21 +1,46 @@
|
||||
import type { NewMixanOptions } from '@mixan/sdk';
|
||||
import { AppState, Platform } from 'react-native';
|
||||
import * as Application from 'expo-application';
|
||||
import Constants from 'expo-constants';
|
||||
import * as Network from 'expo-network';
|
||||
|
||||
import type { MixanOptions } from '@mixan/sdk';
|
||||
import { Mixan } from '@mixan/sdk';
|
||||
|
||||
export class MixanNative extends Mixan {
|
||||
constructor(options: NewMixanOptions) {
|
||||
type MixanNativeOptions = MixanOptions & {
|
||||
ipUrl?: string;
|
||||
};
|
||||
|
||||
export class MixanNative extends Mixan<MixanNativeOptions> {
|
||||
constructor(options: MixanNativeOptions) {
|
||||
super(options);
|
||||
|
||||
this.api.headers['X-Forwarded-For'] = Network.getIpAddressAsync();
|
||||
this.api.headers['User-Agent'] = Constants.getWebViewUserAgentAsync();
|
||||
|
||||
AppState.addEventListener('change', (state) => {
|
||||
if (state === 'active') {
|
||||
this.setProperties();
|
||||
}
|
||||
});
|
||||
|
||||
this.setProperties();
|
||||
}
|
||||
|
||||
init(properties?: Record<string, unknown>) {
|
||||
super.init({
|
||||
...(properties ?? {}),
|
||||
private async setProperties() {
|
||||
this.setGlobalProperties({
|
||||
version: Application.nativeApplicationVersion,
|
||||
buildNumber: Application.nativeBuildVersion,
|
||||
referrer:
|
||||
Platform.OS === 'android'
|
||||
? await Application.getInstallReferrerAsync()
|
||||
: undefined,
|
||||
});
|
||||
}
|
||||
|
||||
screenView(route: string, properties?: Record<string, unknown>): void {
|
||||
public screenView(route: string, properties?: Record<string, unknown>): void {
|
||||
super.event('screen_view', {
|
||||
...properties,
|
||||
route: route,
|
||||
path: route,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,12 @@
|
||||
"tsup": "^7.2.0",
|
||||
"typescript": "^5.2.2"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react-native": "^0.72.5",
|
||||
"expo-application": "~5.3.0",
|
||||
"expo-constants": "~14.4.2",
|
||||
"expo-network": "~5.8.0"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"root": true,
|
||||
"extends": [
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { defineConfig } from 'tsup';
|
||||
|
||||
import config from '@mixan/tsconfig/tsup.config.json' assert {
|
||||
type: 'json'
|
||||
}
|
||||
import config from '@mixan/tsconfig/tsup.config.json' assert { type: 'json' };
|
||||
|
||||
export default defineConfig(config as any);
|
||||
export default defineConfig({
|
||||
...(config as any),
|
||||
minify: false,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user