@bytem/bytem-tracker-app 0.0.1 → 0.0.2

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/dist/env.js CHANGED
@@ -1,3 +1,6 @@
1
- export function isExpoRuntime() {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isExpoRuntime = isExpoRuntime;
4
+ function isExpoRuntime() {
2
5
  return typeof globalThis !== 'undefined' && !!globalThis.__expo;
3
6
  }
package/dist/index.js CHANGED
@@ -1,3 +1,6 @@
1
- import { BytemTracker } from './tracker';
2
- export default BytemTracker.instance;
3
- export { BytemTracker };
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BytemTracker = void 0;
4
+ const tracker_1 = require("./tracker");
5
+ Object.defineProperty(exports, "BytemTracker", { enumerable: true, get: function () { return tracker_1.BytemTracker; } });
6
+ exports.default = tracker_1.BytemTracker.instance;
package/dist/tracker.js CHANGED
@@ -1,7 +1,22 @@
1
- import AsyncStorage from '@react-native-async-storage/async-storage';
2
- import { Dimensions, Platform } from 'react-native';
3
- import { generateUUID } from './uuid';
4
- export class BytemTracker {
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.BytemTracker = void 0;
16
+ const async_storage_1 = __importDefault(require("@react-native-async-storage/async-storage"));
17
+ const react_native_1 = require("react-native");
18
+ const uuid_1 = require("./uuid");
19
+ class BytemTracker {
5
20
  static get instance() {
6
21
  if (!this._instance) {
7
22
  this._instance = new BytemTracker();
@@ -15,71 +30,79 @@ export class BytemTracker {
15
30
  this._deviceId = null;
16
31
  this._visitorId = null;
17
32
  }
18
- async init(options) {
19
- var _a;
20
- this._appKey = options.appKey;
21
- this._debug = (_a = options.debug) !== null && _a !== void 0 ? _a : false;
22
- if (options.baseUrl) {
23
- this._baseUrl = options.baseUrl;
24
- }
25
- if (options.deviceId) {
26
- this._deviceId = options.deviceId;
27
- await AsyncStorage.setItem(BytemTracker._storageDeviceIdKey, this._deviceId);
28
- }
29
- else {
30
- await this._loadOrCreateDeviceId();
31
- }
32
- await this._loadOrCreateVisitorId();
33
- this._log('init', {
34
- deviceId: this._deviceId,
35
- visitorId: this._visitorId,
33
+ init(options) {
34
+ return __awaiter(this, void 0, void 0, function* () {
35
+ var _a;
36
+ this._appKey = options.appKey;
37
+ this._debug = (_a = options.debug) !== null && _a !== void 0 ? _a : false;
38
+ if (options.baseUrl) {
39
+ this._baseUrl = options.baseUrl;
40
+ }
41
+ if (options.deviceId) {
42
+ this._deviceId = options.deviceId;
43
+ yield async_storage_1.default.setItem(BytemTracker._storageDeviceIdKey, this._deviceId);
44
+ }
45
+ else {
46
+ yield this._loadOrCreateDeviceId();
47
+ }
48
+ yield this._loadOrCreateVisitorId();
49
+ this._log('init', {
50
+ deviceId: this._deviceId,
51
+ visitorId: this._visitorId,
52
+ });
36
53
  });
37
54
  }
38
- async track(eventKey, params = {}) {
39
- if (!this._appKey || !this._deviceId || !this._visitorId) {
40
- this._log('track skipped: not initialized');
41
- return;
42
- }
43
- const payload = {
44
- app_key: this._appKey,
45
- device_id: this._deviceId,
46
- visitor_id: this._visitorId,
47
- event_key: eventKey,
48
- params,
49
- sdk: BytemTracker._sdkName,
50
- sdk_version: BytemTracker._sdkVersion,
51
- platform: Platform.OS,
52
- timestamp: Date.now(),
53
- screen: this._getScreenInfo(),
54
- };
55
- this._log('track', payload);
56
- try {
57
- await fetch(`${this._baseUrl}/track`, {
58
- method: 'POST',
59
- headers: { 'Content-Type': 'application/json' },
60
- body: JSON.stringify(payload),
61
- });
62
- }
63
- catch (e) {
64
- this._log('track error', e);
65
- }
55
+ track(eventKey_1) {
56
+ return __awaiter(this, arguments, void 0, function* (eventKey, params = {}) {
57
+ if (!this._appKey || !this._deviceId || !this._visitorId) {
58
+ this._log('track skipped: not initialized');
59
+ return;
60
+ }
61
+ const payload = {
62
+ app_key: this._appKey,
63
+ device_id: this._deviceId,
64
+ visitor_id: this._visitorId,
65
+ event_key: eventKey,
66
+ params,
67
+ sdk: BytemTracker._sdkName,
68
+ sdk_version: BytemTracker._sdkVersion,
69
+ platform: react_native_1.Platform.OS,
70
+ timestamp: Date.now(),
71
+ screen: this._getScreenInfo(),
72
+ };
73
+ this._log('track', payload);
74
+ try {
75
+ yield fetch(`${this._baseUrl}/track`, {
76
+ method: 'POST',
77
+ headers: { 'Content-Type': 'application/json' },
78
+ body: JSON.stringify(payload),
79
+ });
80
+ }
81
+ catch (e) {
82
+ this._log('track error', e);
83
+ }
84
+ });
66
85
  }
67
- async _loadOrCreateDeviceId() {
68
- const stored = await AsyncStorage.getItem(BytemTracker._storageDeviceIdKey);
69
- this._deviceId = stored !== null && stored !== void 0 ? stored : generateUUID();
70
- if (!stored && this._deviceId) {
71
- await AsyncStorage.setItem(BytemTracker._storageDeviceIdKey, this._deviceId);
72
- }
86
+ _loadOrCreateDeviceId() {
87
+ return __awaiter(this, void 0, void 0, function* () {
88
+ const stored = yield async_storage_1.default.getItem(BytemTracker._storageDeviceIdKey);
89
+ this._deviceId = stored !== null && stored !== void 0 ? stored : (0, uuid_1.generateUUID)();
90
+ if (!stored && this._deviceId) {
91
+ yield async_storage_1.default.setItem(BytemTracker._storageDeviceIdKey, this._deviceId);
92
+ }
93
+ });
73
94
  }
74
- async _loadOrCreateVisitorId() {
75
- const stored = await AsyncStorage.getItem(BytemTracker._storageVisitorIdKey);
76
- this._visitorId = stored !== null && stored !== void 0 ? stored : generateUUID();
77
- if (!stored && this._visitorId) {
78
- await AsyncStorage.setItem(BytemTracker._storageVisitorIdKey, this._visitorId);
79
- }
95
+ _loadOrCreateVisitorId() {
96
+ return __awaiter(this, void 0, void 0, function* () {
97
+ const stored = yield async_storage_1.default.getItem(BytemTracker._storageVisitorIdKey);
98
+ this._visitorId = stored !== null && stored !== void 0 ? stored : (0, uuid_1.generateUUID)();
99
+ if (!stored && this._visitorId) {
100
+ yield async_storage_1.default.setItem(BytemTracker._storageVisitorIdKey, this._visitorId);
101
+ }
102
+ });
80
103
  }
81
104
  _getScreenInfo() {
82
- const { width, height } = Dimensions.get('window');
105
+ const { width, height } = react_native_1.Dimensions.get('window');
83
106
  return { width, height };
84
107
  }
85
108
  _log(...args) {
@@ -88,6 +111,7 @@ export class BytemTracker {
88
111
  }
89
112
  }
90
113
  }
114
+ exports.BytemTracker = BytemTracker;
91
115
  BytemTracker._instance = null;
92
116
  BytemTracker._sdkName = 'bytemTrackerReact';
93
117
  BytemTracker._sdkVersion = '0.0.1';
package/dist/types.js CHANGED
@@ -1 +1,2 @@
1
- export {};
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/dist/uuid.js CHANGED
@@ -1,4 +1,7 @@
1
- import { v4 as uuidv4 } from 'uuid';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateUUID = generateUUID;
4
+ const uuid_1 = require("uuid");
2
5
  function jsUUIDv4() {
3
6
  return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
4
7
  const r = (Math.random() * 16) | 0;
@@ -6,11 +9,11 @@ function jsUUIDv4() {
6
9
  return v.toString(16);
7
10
  });
8
11
  }
9
- export function generateUUID() {
12
+ function generateUUID() {
10
13
  try {
11
- return uuidv4();
14
+ return (0, uuid_1.v4)();
12
15
  }
13
- catch {
16
+ catch (_a) {
14
17
  return jsUUIDv4();
15
18
  }
16
19
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bytem/bytem-tracker-app",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": ["dist"],
@@ -9,8 +9,7 @@
9
9
  "author": "Barry",
10
10
  "scripts": {
11
11
  "build": "tsc",
12
- "prepublishOnly": "npm run build",
13
- "publish": "npm publish"
12
+ "prepublishOnly": "npm run build"
14
13
  },
15
14
  "peerDependencies": {
16
15
  "react-native": ">=0.60.0"