@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 +4 -1
- package/dist/index.js +6 -3
- package/dist/tracker.js +87 -63
- package/dist/types.js +2 -1
- package/dist/uuid.js +7 -4
- package/package.json +2 -3
package/dist/env.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
|
|
39
|
-
|
|
40
|
-
this.
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
package/dist/uuid.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
12
|
+
function generateUUID() {
|
|
10
13
|
try {
|
|
11
|
-
return
|
|
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.
|
|
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"
|