@bytem/bytem-tracker-app 0.0.8 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/package.json +58 -0
- package/dist/src/BytemTracker.js +2 -1
- package/dist/src/core/device.js +39 -13
- package/dist/src/core/storage.js +25 -7
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@ This is the official Bytem Tracker SDK for React Native applications.
|
|
|
7
7
|
Install the package and its peer dependencies using Yarn:
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
|
-
yarn add @bytem/bytem-tracker-app
|
|
10
|
+
yarn add @bytem/bytem-tracker-app
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
### iOS Setup
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@bytem/bytem-tracker-app",
|
|
3
|
+
"version": "0.0.10",
|
|
4
|
+
"description": "Bytem Tracker SDK for React Native",
|
|
5
|
+
"main": "dist/src/index.js",
|
|
6
|
+
"types": "dist/src/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsc",
|
|
12
|
+
"test": "jest",
|
|
13
|
+
"prepublishOnly": "npm run build",
|
|
14
|
+
"release:patch": "npm version patch && npm publish",
|
|
15
|
+
"release:minor": "npm version minor && npm publish",
|
|
16
|
+
"release:major": "npm version major && npm publish",
|
|
17
|
+
"release:beta": "npm version prerelease --preid=beta && npm publish --tag beta"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"tracker",
|
|
21
|
+
"sdk",
|
|
22
|
+
"analytics",
|
|
23
|
+
"react-native"
|
|
24
|
+
],
|
|
25
|
+
"author": "Barry",
|
|
26
|
+
"license": "ISC",
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"react": ">=16.8.0",
|
|
29
|
+
"react-native": ">=0.60.0"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"uuid": "^9.0.0",
|
|
33
|
+
"@react-native-async-storage/async-storage": "^1.19.0",
|
|
34
|
+
"react-native-device-info": "^10.8.0"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@react-native-async-storage/async-storage": "^1.19.0",
|
|
38
|
+
"@types/jest": "^30.0.0",
|
|
39
|
+
"@types/node": "^20.0.0",
|
|
40
|
+
"@types/react": "^18.0.0",
|
|
41
|
+
"@types/react-native": "^0.72.0",
|
|
42
|
+
"@types/uuid": "^9.0.0",
|
|
43
|
+
"jest": "^30.2.0",
|
|
44
|
+
"react": "18.2.0",
|
|
45
|
+
"react-native": "0.72.0",
|
|
46
|
+
"react-native-device-info": "^10.8.0",
|
|
47
|
+
"ts-jest": "^29.4.6",
|
|
48
|
+
"typescript": "^5.0.0"
|
|
49
|
+
},
|
|
50
|
+
"publishConfig": {
|
|
51
|
+
"access": "public",
|
|
52
|
+
"registry": "https://registry.npmjs.org"
|
|
53
|
+
},
|
|
54
|
+
"volta": {
|
|
55
|
+
"node": "22.12.0",
|
|
56
|
+
"yarn": "1.22.21"
|
|
57
|
+
}
|
|
58
|
+
}
|
package/dist/src/BytemTracker.js
CHANGED
|
@@ -3,11 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const types_1 = require("./types");
|
|
4
4
|
const storage_1 = require("./core/storage");
|
|
5
5
|
const device_1 = require("./core/device");
|
|
6
|
+
const package_json_1 = require("../package.json");
|
|
6
7
|
class BytemTracker {
|
|
7
8
|
constructor() {
|
|
8
9
|
// SDK Constants
|
|
9
10
|
this.SDK_NAME = 'react_native_bytem';
|
|
10
|
-
this.SDK_VERSION =
|
|
11
|
+
this.SDK_VERSION = package_json_1.version; // Should match package.json
|
|
11
12
|
this.DEFAULT_ENDPOINT = 'https://tracking.server.bytecon.com';
|
|
12
13
|
this.DEFAULT_API_PATH = '/i';
|
|
13
14
|
// Config
|
package/dist/src/core/device.js
CHANGED
|
@@ -1,25 +1,51 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.generateUUID = exports.getDeviceInfo = void 0;
|
|
7
4
|
const react_native_1 = require("react-native");
|
|
8
|
-
const react_native_device_info_1 = __importDefault(require("react-native-device-info"));
|
|
9
5
|
const getDeviceInfo = async () => {
|
|
10
6
|
var _a, _b, _c;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
7
|
+
let os = react_native_1.Platform.OS;
|
|
8
|
+
let osVersion = String(react_native_1.Platform.Version);
|
|
9
|
+
let model = 'unknown';
|
|
10
|
+
let userAgent = `BytemTracker/${react_native_1.Platform.OS}`;
|
|
11
|
+
try {
|
|
12
|
+
// Safely attempt to get native device info
|
|
13
|
+
// Use require() dynamically to avoid top-level import crashes in environments like Expo Go
|
|
14
|
+
// where react-native-device-info native module is not linked.
|
|
15
|
+
const mod = require('react-native-device-info');
|
|
16
|
+
const RNDeviceInfo = mod.default || mod;
|
|
17
|
+
if (RNDeviceInfo) {
|
|
18
|
+
if (typeof RNDeviceInfo.getSystemName === 'function') {
|
|
19
|
+
os = RNDeviceInfo.getSystemName();
|
|
20
|
+
}
|
|
21
|
+
if (typeof RNDeviceInfo.getSystemVersion === 'function') {
|
|
22
|
+
osVersion = RNDeviceInfo.getSystemVersion();
|
|
23
|
+
}
|
|
24
|
+
if (typeof RNDeviceInfo.getModel === 'function') {
|
|
25
|
+
model = RNDeviceInfo.getModel();
|
|
26
|
+
}
|
|
27
|
+
if (typeof RNDeviceInfo.getUserAgent === 'function') {
|
|
28
|
+
userAgent = await RNDeviceInfo.getUserAgent();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
catch (e) {
|
|
33
|
+
// Native module missing or failed, keep default values
|
|
34
|
+
// console.warn('[BytemTracker] Native device info not available (lazy load failed).');
|
|
35
|
+
}
|
|
15
36
|
// Try to get language
|
|
16
37
|
let language = 'en';
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
38
|
+
try {
|
|
39
|
+
if (react_native_1.Platform.OS === 'ios') {
|
|
40
|
+
const settings = (_a = react_native_1.NativeModules.SettingsManager) === null || _a === void 0 ? void 0 : _a.settings;
|
|
41
|
+
language = (settings === null || settings === void 0 ? void 0 : settings.AppleLocale) || ((_b = settings === null || settings === void 0 ? void 0 : settings.AppleLanguages) === null || _b === void 0 ? void 0 : _b[0]) || 'en';
|
|
42
|
+
}
|
|
43
|
+
else if (react_native_1.Platform.OS === 'android') {
|
|
44
|
+
language = ((_c = react_native_1.NativeModules.I18nManager) === null || _c === void 0 ? void 0 : _c.localeIdentifier) || 'en';
|
|
45
|
+
}
|
|
20
46
|
}
|
|
21
|
-
|
|
22
|
-
|
|
47
|
+
catch (e) {
|
|
48
|
+
// Ignore language detection errors
|
|
23
49
|
}
|
|
24
50
|
const { width, height } = react_native_1.Dimensions.get('window');
|
|
25
51
|
return {
|
package/dist/src/core/storage.js
CHANGED
|
@@ -1,19 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.removeItem = exports.setItem = exports.getItem = exports.StorageKeys = void 0;
|
|
7
|
-
const async_storage_1 = __importDefault(require("@react-native-async-storage/async-storage"));
|
|
8
4
|
exports.StorageKeys = {
|
|
9
5
|
VISITOR_ID: 'bytem_visitor_id',
|
|
10
6
|
DEVICE_ID: 'bytem_device_id',
|
|
11
7
|
SESSION_ID: 'bytem_session_id',
|
|
12
8
|
SESSION_START: 'bytem_session_start',
|
|
13
9
|
};
|
|
10
|
+
// Lazy load AsyncStorage to prevent "NativeModule: AsyncStorage is null" error
|
|
11
|
+
// when imported in environments where the native module is not linked or initialized immediately.
|
|
12
|
+
const getStorage = () => {
|
|
13
|
+
try {
|
|
14
|
+
const mod = require('@react-native-async-storage/async-storage');
|
|
15
|
+
return mod.default || mod;
|
|
16
|
+
}
|
|
17
|
+
catch (e) {
|
|
18
|
+
console.warn('[BytemTracker] AsyncStorage not available, falling back to no-op.');
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
14
22
|
const getItem = async (key) => {
|
|
15
23
|
try {
|
|
16
|
-
|
|
24
|
+
const storage = getStorage();
|
|
25
|
+
if (storage) {
|
|
26
|
+
return await storage.getItem(key);
|
|
27
|
+
}
|
|
28
|
+
return null;
|
|
17
29
|
}
|
|
18
30
|
catch (e) {
|
|
19
31
|
console.warn('[BytemTracker] Storage get error:', e);
|
|
@@ -23,7 +35,10 @@ const getItem = async (key) => {
|
|
|
23
35
|
exports.getItem = getItem;
|
|
24
36
|
const setItem = async (key, value) => {
|
|
25
37
|
try {
|
|
26
|
-
|
|
38
|
+
const storage = getStorage();
|
|
39
|
+
if (storage) {
|
|
40
|
+
await storage.setItem(key, value);
|
|
41
|
+
}
|
|
27
42
|
}
|
|
28
43
|
catch (e) {
|
|
29
44
|
console.warn('[BytemTracker] Storage set error:', e);
|
|
@@ -32,7 +47,10 @@ const setItem = async (key, value) => {
|
|
|
32
47
|
exports.setItem = setItem;
|
|
33
48
|
const removeItem = async (key) => {
|
|
34
49
|
try {
|
|
35
|
-
|
|
50
|
+
const storage = getStorage();
|
|
51
|
+
if (storage) {
|
|
52
|
+
await storage.removeItem(key);
|
|
53
|
+
}
|
|
36
54
|
}
|
|
37
55
|
catch (e) {
|
|
38
56
|
console.warn('[BytemTracker] Storage remove error:', e);
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bytem/bytem-tracker-app",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.10",
|
|
4
4
|
"description": "Bytem Tracker SDK for React Native",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"types": "dist/index.d.ts",
|
|
5
|
+
"main": "dist/src/index.js",
|
|
6
|
+
"types": "dist/src/index.d.ts",
|
|
7
7
|
"files": [
|
|
8
8
|
"dist"
|
|
9
9
|
],
|
|
@@ -25,13 +25,13 @@
|
|
|
25
25
|
"author": "Barry",
|
|
26
26
|
"license": "ISC",
|
|
27
27
|
"peerDependencies": {
|
|
28
|
-
"@react-native-async-storage/async-storage": "^1.0.0",
|
|
29
28
|
"react": ">=16.8.0",
|
|
30
|
-
"react-native": ">=0.60.0"
|
|
31
|
-
"react-native-device-info": "^10.0.0"
|
|
29
|
+
"react-native": ">=0.60.0"
|
|
32
30
|
},
|
|
33
31
|
"dependencies": {
|
|
34
|
-
"uuid": "^9.0.0"
|
|
32
|
+
"uuid": "^9.0.0",
|
|
33
|
+
"@react-native-async-storage/async-storage": "^1.19.0",
|
|
34
|
+
"react-native-device-info": "^10.8.0"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@react-native-async-storage/async-storage": "^1.19.0",
|