@bytem/bytem-tracker-app 0.0.6 → 0.0.8
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 +4 -48
- package/dist/src/BytemTracker.d.ts +129 -8
- package/dist/src/BytemTracker.js +526 -87
- package/dist/src/types.d.ts +36 -0
- package/dist/src/types.js +13 -0
- package/dist/test/BytemTracker.test.js +231 -57
- package/dist/test/debug.test.js +37 -5
- package/dist/test/setup.js +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -16,50 +16,6 @@ Don't forget to install pods for iOS:
|
|
|
16
16
|
cd ios && pod install
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
-
## Development
|
|
20
|
-
|
|
21
|
-
This project uses **Yarn** for dependency management.
|
|
22
|
-
|
|
23
|
-
### Setup
|
|
24
|
-
|
|
25
|
-
```bash
|
|
26
|
-
yarn install
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
### Running Tests
|
|
30
|
-
|
|
31
|
-
```bash
|
|
32
|
-
yarn test
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
### Build
|
|
36
|
-
|
|
37
|
-
```bash
|
|
38
|
-
yarn build
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
## Release & Publish
|
|
42
|
-
|
|
43
|
-
Automate version bump and publish via npm scripts:
|
|
44
|
-
|
|
45
|
-
```bash
|
|
46
|
-
# Patch release (1.0.0 -> 1.0.1)
|
|
47
|
-
npm run release:patch
|
|
48
|
-
|
|
49
|
-
# Minor release (1.0.0 -> 1.1.0)
|
|
50
|
-
npm run release:minor
|
|
51
|
-
|
|
52
|
-
# Major release (1.0.0 -> 2.0.0)
|
|
53
|
-
npm run release:major
|
|
54
|
-
|
|
55
|
-
# Beta prerelease (1.0.0 -> 1.0.1-beta.0)
|
|
56
|
-
npm run release:beta
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
Notes:
|
|
60
|
-
- These scripts bump package.json version and publish to npm.
|
|
61
|
-
- `prepublishOnly` builds the package before publishing.
|
|
62
|
-
- Configure auth via user-level `~/.npmrc`. Do not commit tokens in the repo.
|
|
63
19
|
## Usage
|
|
64
20
|
|
|
65
21
|
### Initialization
|
|
@@ -93,7 +49,7 @@ Track user identification when a user logs in or updates their profile.
|
|
|
93
49
|
|
|
94
50
|
```typescript
|
|
95
51
|
// Signature: trackUser(userId: string, traits?: object)
|
|
96
|
-
BytemTracker.trackUser('user_12345', {
|
|
52
|
+
await BytemTracker.trackUser('user_12345', {
|
|
97
53
|
email: 'user@example.com',
|
|
98
54
|
age: 25,
|
|
99
55
|
membership: 'gold'
|
|
@@ -104,7 +60,7 @@ BytemTracker.trackUser('user_12345', {
|
|
|
104
60
|
Track when a user views a product details page.
|
|
105
61
|
|
|
106
62
|
```typescript
|
|
107
|
-
BytemTracker.trackViewProduct({
|
|
63
|
+
await BytemTracker.trackViewProduct({
|
|
108
64
|
productId: 'prod_001',
|
|
109
65
|
name: 'Awesome Gadget',
|
|
110
66
|
price: 99.99,
|
|
@@ -117,7 +73,7 @@ BytemTracker.trackViewProduct({
|
|
|
117
73
|
Track when a user initiates checkout.
|
|
118
74
|
|
|
119
75
|
```typescript
|
|
120
|
-
BytemTracker.trackCheckOutOrder({
|
|
76
|
+
await BytemTracker.trackCheckOutOrder({
|
|
121
77
|
orderId: 'order_abc123',
|
|
122
78
|
total: 150.00,
|
|
123
79
|
currency: 'USD',
|
|
@@ -132,7 +88,7 @@ BytemTracker.trackCheckOutOrder({
|
|
|
132
88
|
Track when a user completes a payment.
|
|
133
89
|
|
|
134
90
|
```typescript
|
|
135
|
-
BytemTracker.trackPayOrder({
|
|
91
|
+
await BytemTracker.trackPayOrder({
|
|
136
92
|
orderId: 'order_abc123',
|
|
137
93
|
total: 150.00,
|
|
138
94
|
currency: 'USD',
|
|
@@ -1,18 +1,139 @@
|
|
|
1
1
|
import { TrackerConfig, Product, Order, UserTraits } from './types';
|
|
2
2
|
declare class BytemTracker {
|
|
3
3
|
private static instance;
|
|
4
|
-
private
|
|
5
|
-
private
|
|
6
|
-
private visitorId;
|
|
4
|
+
private readonly SDK_NAME;
|
|
5
|
+
private readonly SDK_VERSION;
|
|
7
6
|
private readonly DEFAULT_ENDPOINT;
|
|
7
|
+
private readonly DEFAULT_API_PATH;
|
|
8
|
+
private appKey;
|
|
9
|
+
private baseUrl;
|
|
10
|
+
private debug;
|
|
11
|
+
private visitorId;
|
|
12
|
+
private deviceIdType;
|
|
13
|
+
private appScheme;
|
|
14
|
+
private apiPath;
|
|
15
|
+
private isInitialized;
|
|
16
|
+
private sessionStarted;
|
|
17
|
+
private useSessionCookie;
|
|
18
|
+
private sessionCookieTimeout;
|
|
19
|
+
private lastBeat;
|
|
20
|
+
private trackTime;
|
|
21
|
+
private storedDuration;
|
|
22
|
+
private lastViewTime;
|
|
23
|
+
private lastViewStoredDuration;
|
|
8
24
|
private constructor();
|
|
9
25
|
static getInstance(): BytemTracker;
|
|
26
|
+
/**
|
|
27
|
+
* Initializes the BytemTracker SDK with the provided configuration.
|
|
28
|
+
* This method must be called before any other tracking methods.
|
|
29
|
+
*
|
|
30
|
+
* @param config - The configuration object for the tracker.
|
|
31
|
+
* @returns A promise that resolves when initialization is complete.
|
|
32
|
+
*/
|
|
10
33
|
init(config: TrackerConfig): Promise<void>;
|
|
11
|
-
private
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
34
|
+
private ensureInitialized;
|
|
35
|
+
/**
|
|
36
|
+
* Begins a new user session.
|
|
37
|
+
* Handles session cookie logic to prevent excessive session starts if one is already active.
|
|
38
|
+
*
|
|
39
|
+
* @param force - If true, forces a new session start request even if the session cookie is valid.
|
|
40
|
+
*/
|
|
41
|
+
beginSession(force?: boolean): Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
* Reports session duration to the server.
|
|
44
|
+
* Usually called internally or when app state changes.
|
|
45
|
+
*
|
|
46
|
+
* @param sec - The duration in seconds to report.
|
|
47
|
+
*/
|
|
48
|
+
sessionDuration(sec: number): Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* Ends the current user session.
|
|
51
|
+
*
|
|
52
|
+
* @param sec - Optional duration of the session in seconds. If not provided, it's calculated from the last beat.
|
|
53
|
+
* @param force - If true, forces the end session request even if using session cookies.
|
|
54
|
+
*/
|
|
55
|
+
endSession(sec?: number, force?: boolean): Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* Manually tracks or extends a session.
|
|
58
|
+
* If a session is active, it reports duration. If not, it begins a new session.
|
|
59
|
+
*/
|
|
60
|
+
trackSessions(): Promise<void>;
|
|
61
|
+
/**
|
|
62
|
+
* Resumes time tracking for session duration.
|
|
63
|
+
*/
|
|
64
|
+
startTime(): void;
|
|
65
|
+
/**
|
|
66
|
+
* Pauses time tracking for session duration.
|
|
67
|
+
*/
|
|
68
|
+
stopTime(): void;
|
|
69
|
+
/**
|
|
70
|
+
* Tracks a custom event.
|
|
71
|
+
*
|
|
72
|
+
* @param eventKey - The unique key/name for the event.
|
|
73
|
+
* @param segmentation - Optional key-value pairs to attach to the event.
|
|
74
|
+
* @param count - The number of times this event occurred (default: 1).
|
|
75
|
+
* @param sum - Optional numeric value associated with the event (e.g., purchase amount).
|
|
76
|
+
* @param duration - Optional duration associated with the event.
|
|
77
|
+
*/
|
|
78
|
+
trackEvent(eventKey: string, segmentation?: Record<string, any>, count?: number, sum?: number, duration?: number): Promise<void>;
|
|
79
|
+
/**
|
|
80
|
+
* Tracks a page view.
|
|
81
|
+
* Automatically handles reporting the duration of the previous page view.
|
|
82
|
+
*
|
|
83
|
+
* @param current - The name or path of the current page.
|
|
84
|
+
* @param referrer - Optional name or path of the previous page.
|
|
85
|
+
*/
|
|
86
|
+
trackPageview(current: string, referrer?: string): Promise<void>;
|
|
87
|
+
/**
|
|
88
|
+
* Tracks a click on a product/goods item.
|
|
89
|
+
*
|
|
90
|
+
* @param params - The parameters for the goods click event.
|
|
91
|
+
*/
|
|
92
|
+
trackGoodsClick(params: {
|
|
93
|
+
gid?: string;
|
|
94
|
+
skuid?: string;
|
|
95
|
+
url: string;
|
|
96
|
+
source?: string;
|
|
97
|
+
position?: string;
|
|
98
|
+
current?: string;
|
|
99
|
+
referrer?: string;
|
|
100
|
+
}): Promise<void>;
|
|
101
|
+
private reportViewDuration;
|
|
102
|
+
private getRealDeviceId;
|
|
103
|
+
private getMetrics;
|
|
104
|
+
private buildBaseRequestParams;
|
|
105
|
+
private extendSession;
|
|
106
|
+
private sendRequest;
|
|
107
|
+
/**
|
|
108
|
+
* Tracks a product view event.
|
|
109
|
+
* Maps the product details to a 'view_product' event.
|
|
110
|
+
*
|
|
111
|
+
* @param product - The product object to track.
|
|
112
|
+
*/
|
|
113
|
+
trackViewProduct(product: Product): Promise<void>;
|
|
114
|
+
/**
|
|
115
|
+
* Tracks a checkout order event.
|
|
116
|
+
* Automatically splits product lists into parallel arrays (gids, prices, quantities)
|
|
117
|
+
* to match the backend requirement.
|
|
118
|
+
*
|
|
119
|
+
* @param order - The order object containing products to checkout.
|
|
120
|
+
*/
|
|
121
|
+
trackCheckOutOrder(order: Order): Promise<void>;
|
|
122
|
+
/**
|
|
123
|
+
* Tracks a payment order event.
|
|
124
|
+
* Maps product list to a 'goods' array structure expected by the backend.
|
|
125
|
+
*
|
|
126
|
+
* @param order - The order object that was paid for.
|
|
127
|
+
*/
|
|
128
|
+
trackPayOrder(order: Order): Promise<void>;
|
|
129
|
+
/**
|
|
130
|
+
* Tracks user details/profile updates.
|
|
131
|
+
*
|
|
132
|
+
* @param userId - The unique identifier for the user.
|
|
133
|
+
* @param traits - Additional user properties (email, name, custom fields).
|
|
134
|
+
*/
|
|
135
|
+
trackUser(userId: string, traits?: UserTraits): Promise<void>;
|
|
136
|
+
private sendUserDetails;
|
|
16
137
|
}
|
|
17
138
|
declare const _default: BytemTracker;
|
|
18
139
|
export default _default;
|