@bytem/bytem-tracker-app 0.0.9 → 0.0.11

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.
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "@bytem/bytem-tracker-app",
3
+ "version": "0.0.11",
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
+ }
@@ -134,6 +134,23 @@ declare class BytemTracker {
134
134
  */
135
135
  trackUser(userId: string, traits?: UserTraits): Promise<void>;
136
136
  private sendUserDetails;
137
+ /**
138
+ * Clears the current user info and resets visitor ID.
139
+ */
140
+ clearUser(): Promise<void>;
141
+ /**
142
+ * Sets a custom API path for subsequent requests.
143
+ * @param path - The new API path (e.g., '/api/track').
144
+ */
145
+ setPath(path: string): void;
146
+ /**
147
+ * Resets the API path to the default value.
148
+ */
149
+ resetPath(): void;
150
+ /**
151
+ * Retrieves system/device information.
152
+ */
153
+ getSystemInfo(): Promise<Record<string, any>>;
137
154
  }
138
155
  declare const _default: BytemTracker;
139
156
  export default _default;
@@ -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 = '0.0.1'; // Should match package.json
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
@@ -570,5 +571,56 @@ class BytemTracker {
570
571
  body['user_details'] = JSON.stringify(userData);
571
572
  await this.sendRequest(this.apiPath, body, 'User Details');
572
573
  }
574
+ /**
575
+ * Clears the current user info and resets visitor ID.
576
+ */
577
+ async clearUser() {
578
+ this.ensureInitialized();
579
+ // Clear visitor ID from storage
580
+ await (0, storage_1.removeItem)(storage_1.StorageKeys.VISITOR_ID);
581
+ // Generate new visitor ID
582
+ this.visitorId = (0, device_1.generateUUID)();
583
+ await (0, storage_1.setItem)(storage_1.StorageKeys.VISITOR_ID, this.visitorId);
584
+ if (this.debug)
585
+ console.log(`[BytemTracker] User cleared, new visitor ID: ${this.visitorId}`);
586
+ }
587
+ /**
588
+ * Sets a custom API path for subsequent requests.
589
+ * @param path - The new API path (e.g., '/api/track').
590
+ */
591
+ setPath(path) {
592
+ this.apiPath = path.startsWith('/') ? path : '/' + path;
593
+ if (this.debug)
594
+ console.log(`[BytemTracker] API path set to: ${this.apiPath}`);
595
+ }
596
+ /**
597
+ * Resets the API path to the default value.
598
+ */
599
+ resetPath() {
600
+ this.apiPath = this.DEFAULT_API_PATH;
601
+ if (this.debug)
602
+ console.log(`[BytemTracker] API path reset to default: ${this.apiPath}`);
603
+ }
604
+ /**
605
+ * Retrieves system/device information.
606
+ */
607
+ async getSystemInfo() {
608
+ const info = await (0, device_1.getDeviceInfo)();
609
+ return {
610
+ platform: info.platform,
611
+ os: info.os,
612
+ os_version: info.osVersion,
613
+ model: info.model,
614
+ resolution: `${Math.round(info.screenWidth)}x${Math.round(info.screenHeight)}`,
615
+ language: info.language,
616
+ user_agent: info.userAgent,
617
+ sdk_version: this.SDK_VERSION,
618
+ app_key: this.appKey,
619
+ visitor_id: this.visitorId,
620
+ device_id_type: this.deviceIdType,
621
+ api_path: this.apiPath,
622
+ base_url: this.baseUrl,
623
+ };
624
+ }
573
625
  }
574
626
  exports.default = BytemTracker.getInstance();
@@ -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
- const os = react_native_device_info_1.default.getSystemName();
12
- const osVersion = react_native_device_info_1.default.getSystemVersion();
13
- const model = react_native_device_info_1.default.getModel();
14
- const userAgent = await react_native_device_info_1.default.getUserAgent();
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
- if (react_native_1.Platform.OS === 'ios') {
18
- const settings = (_a = react_native_1.NativeModules.SettingsManager) === null || _a === void 0 ? void 0 : _a.settings;
19
- 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';
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
- else if (react_native_1.Platform.OS === 'android') {
22
- language = ((_c = react_native_1.NativeModules.I18nManager) === null || _c === void 0 ? void 0 : _c.localeIdentifier) || 'en';
47
+ catch (e) {
48
+ // Ignore language detection errors
23
49
  }
24
50
  const { width, height } = react_native_1.Dimensions.get('window');
25
51
  return {
@@ -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
- return await async_storage_1.default.getItem(key);
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
- await async_storage_1.default.setItem(key, value);
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
- await async_storage_1.default.removeItem(key);
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,6 +1,6 @@
1
1
  {
2
2
  "name": "@bytem/bytem-tracker-app",
3
- "version": "0.0.9",
3
+ "version": "0.0.11",
4
4
  "description": "Bytem Tracker SDK for React Native",
5
5
  "main": "dist/src/index.js",
6
6
  "types": "dist/src/index.d.ts",