@v-miniapp/apis 1.0.15 → 1.0.20
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.
|
@@ -1,8 +1,172 @@
|
|
|
1
1
|
import { IVsfOptionsWithCallback } from '../common';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Item ecommerce dùng chung cho các event như view_item, add_to_cart, ...
|
|
4
4
|
*/
|
|
5
|
-
export type
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
export type IVsfReportAnalyticsItem = {
|
|
6
|
+
/** Mã định danh sản phẩm */
|
|
7
|
+
item_id: string;
|
|
8
|
+
/** Tên của sản phẩm */
|
|
9
|
+
item_name: string;
|
|
10
|
+
/** Giá sản phẩm */
|
|
11
|
+
item_price?: number;
|
|
12
|
+
/** Phiên bản của sản phẩm (vd: green) */
|
|
13
|
+
item_variant?: string;
|
|
14
|
+
/** Thương hiệu của sản phẩm */
|
|
15
|
+
item_brand?: string;
|
|
16
|
+
/** Danh mục của sản phẩm */
|
|
17
|
+
item_category?: string;
|
|
18
|
+
/** Danh mục cấp 2 */
|
|
19
|
+
item_category2?: string;
|
|
20
|
+
/** Danh mục cấp 3 */
|
|
21
|
+
item_category3?: string;
|
|
22
|
+
/** Danh mục cấp 4 */
|
|
23
|
+
item_category4?: string;
|
|
24
|
+
/** Danh mục cấp 5 */
|
|
25
|
+
item_category5?: string;
|
|
26
|
+
/** Số lượng của sản phẩm */
|
|
27
|
+
quantity?: number;
|
|
28
|
+
/** Cho phép developer truyền thêm các trường tuỳ ý */
|
|
29
|
+
[key: string]: any;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Bộ tham số ecommerce dùng chung cho view_item, add_to_cart, remove_from_cart,
|
|
33
|
+
* begin_checkout.
|
|
34
|
+
*/
|
|
35
|
+
export type IVsfReportAnalyticsEcommerceProperties = {
|
|
36
|
+
/** Đơn vị tiền tệ (vd: VND) */
|
|
37
|
+
currency?: string;
|
|
38
|
+
/** Tổng giá trị các sản phẩm trong sự kiện */
|
|
39
|
+
value?: number;
|
|
40
|
+
/** Danh sách các sản phẩm liên quan đến sự kiện */
|
|
41
|
+
items?: IVsfReportAnalyticsItem[];
|
|
42
|
+
/** Cho phép developer truyền thêm các trường tuỳ ý */
|
|
43
|
+
[key: string]: any;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Map giữa event name (đã được hệ thống định nghĩa) với cấu trúc properties
|
|
47
|
+
* tương ứng. Khi truyền event name nằm trong map, properties sẽ được type-check
|
|
48
|
+
* theo cấu trúc tương ứng. Khi truyền event name khác, properties sẽ rơi về
|
|
49
|
+
* `Record<string, any> | undefined`.
|
|
50
|
+
*/
|
|
51
|
+
export type IVsfReportAnalyticsEventMap = {
|
|
52
|
+
/**
|
|
53
|
+
* SDK tự bắn khi user mở Mini App thành công (first page loaded).
|
|
54
|
+
*/
|
|
55
|
+
miniapp_open: {
|
|
56
|
+
page_path?: string;
|
|
57
|
+
page_title?: string;
|
|
58
|
+
referrer?: 'home_screen' | 'notification' | 'deeplink' | 'qr_code' | (string & {});
|
|
59
|
+
is_first_open?: boolean;
|
|
60
|
+
/** Mini app params/query */
|
|
61
|
+
app_query?: string;
|
|
62
|
+
utm_source?: string;
|
|
63
|
+
/** Cho phép developer truyền thêm các trường tuỳ ý */
|
|
64
|
+
[key: string]: any;
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* SDK tự bắn khi mini app đóng.
|
|
68
|
+
*/
|
|
69
|
+
miniapp_close: {
|
|
70
|
+
page_path?: string;
|
|
71
|
+
page_title?: string;
|
|
72
|
+
/** Cho phép developer truyền thêm các trường tuỳ ý */
|
|
73
|
+
[key: string]: any;
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* SDK tự bắn khi user navigate đến một page mới (kể cả first page).
|
|
77
|
+
*/
|
|
78
|
+
page_view: {
|
|
79
|
+
page_path: string;
|
|
80
|
+
page_title?: string;
|
|
81
|
+
/** Page trước đó */
|
|
82
|
+
referrer_page?: string;
|
|
83
|
+
/** Có phải trang đầu tiên trong session hay không */
|
|
84
|
+
is_first_page_in_session?: boolean;
|
|
85
|
+
app_query?: string;
|
|
86
|
+
/** Cho phép developer truyền thêm các trường tuỳ ý */
|
|
87
|
+
[key: string]: any;
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* SDK tự bắn khi user trả lời permission prompt.
|
|
91
|
+
*/
|
|
92
|
+
permission_request: {
|
|
93
|
+
permission_type: string;
|
|
94
|
+
permission_result: 'accept' | 'reject';
|
|
95
|
+
/** Page nơi request permission xảy ra */
|
|
96
|
+
trigger_page?: string;
|
|
97
|
+
/** Cho phép developer truyền thêm các trường tuỳ ý */
|
|
98
|
+
[key: string]: any;
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* SDK tự bắn khi user cấp quyền (vd: trong Quản lý riêng tư).
|
|
102
|
+
*/
|
|
103
|
+
permission_grant: {
|
|
104
|
+
permission_type: string;
|
|
105
|
+
trigger_source?: 'privacy_page' | (string & {});
|
|
106
|
+
/** Cho phép developer truyền thêm các trường tuỳ ý */
|
|
107
|
+
[key: string]: any;
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* SDK tự bắn khi user thu hồi quyền (vd: trong Quản lý riêng tư).
|
|
111
|
+
*/
|
|
112
|
+
permission_revoke: {
|
|
113
|
+
permission_type: string;
|
|
114
|
+
trigger_source?: 'privacy_page' | (string & {});
|
|
115
|
+
/** Cho phép developer truyền thêm các trường tuỳ ý */
|
|
116
|
+
[key: string]: any;
|
|
117
|
+
};
|
|
118
|
+
/** User xem chi tiết danh sách sản phẩm/nội dung */
|
|
119
|
+
view_item: IVsfReportAnalyticsEcommerceProperties;
|
|
120
|
+
/** User thêm sản phẩm vào giỏ */
|
|
121
|
+
add_to_cart: IVsfReportAnalyticsEcommerceProperties;
|
|
122
|
+
/** User xóa 1 mặt hàng khỏi giỏ hàng */
|
|
123
|
+
remove_from_cart: IVsfReportAnalyticsEcommerceProperties;
|
|
124
|
+
/** User bắt đầu checkout */
|
|
125
|
+
begin_checkout: IVsfReportAnalyticsEcommerceProperties;
|
|
126
|
+
/** User áp dụng voucher / promotion */
|
|
127
|
+
apply_promotion: IVsfReportAnalyticsEcommerceProperties & {
|
|
128
|
+
/** Coupon name hoặc id */
|
|
129
|
+
coupon?: string;
|
|
130
|
+
/** Phương thức thanh toán đơn hàng */
|
|
131
|
+
payment_method?: string;
|
|
132
|
+
};
|
|
133
|
+
};
|
|
134
|
+
export type IVsfReportAnalyticsKnownEvent = keyof IVsfReportAnalyticsEventMap;
|
|
135
|
+
/**
|
|
136
|
+
* Loại bỏ các event name đã được khai báo trong `IVsfReportAnalyticsEventMap`
|
|
137
|
+
* khỏi tham số `name`. Khi developer truyền một known event như `'view_item'`,
|
|
138
|
+
* type này sẽ thành `never`, buộc TypeScript chuyển sang overload có
|
|
139
|
+
* type-checking theo properties tương ứng.
|
|
140
|
+
*
|
|
141
|
+
* Lưu ý: với biến `name: string` (không phải literal), `S` là `string` nên
|
|
142
|
+
* `string extends IVsfReportAnalyticsKnownEvent` là `false`, kết quả vẫn là
|
|
143
|
+
* `string` — fallback vẫn hoạt động bình thường.
|
|
144
|
+
*/
|
|
145
|
+
export type IVsfReportAnalyticsUnknownEvent<S extends string = string> = S extends IVsfReportAnalyticsKnownEvent ? never : S;
|
|
146
|
+
/**
|
|
147
|
+
* Properties cho các event name không nằm trong `IVsfReportAnalyticsEventMap`.
|
|
148
|
+
*/
|
|
149
|
+
export type IVsfReportAnalyticsCustomProperties = Record<string, any>;
|
|
150
|
+
/**
|
|
151
|
+
* Tham số properties cho `reportAnalytics` đã hợp nhất theo event name.
|
|
152
|
+
*/
|
|
153
|
+
export type IVsfReportAnalyticsOptions<K extends string = string> = K extends IVsfReportAnalyticsKnownEvent ? IVsfReportAnalyticsEventMap[K] : IVsfReportAnalyticsCustomProperties | undefined;
|
|
154
|
+
export type IVsfReportAnalyticsOptionsWithCallback<K extends string = string> = IVsfOptionsWithCallback<IVsfReportAnalyticsOptions<K>, void>;
|
|
155
|
+
/**
|
|
156
|
+
* Callback-style signature.
|
|
157
|
+
*
|
|
158
|
+
* - Với event name nằm trong `IVsfReportAnalyticsEventMap`, `options` được
|
|
159
|
+
* type-check theo properties tương ứng.
|
|
160
|
+
* - Với event name khác, properties có type là `Record<string, any> | undefined`.
|
|
161
|
+
*/
|
|
162
|
+
export interface IVsfReportAnalytics {
|
|
163
|
+
<K extends IVsfReportAnalyticsKnownEvent>(name: K, options?: IVsfOptionsWithCallback<IVsfReportAnalyticsEventMap[K], void>): void;
|
|
164
|
+
<S extends string>(name: IVsfReportAnalyticsUnknownEvent<S>, options?: IVsfOptionsWithCallback<IVsfReportAnalyticsCustomProperties | undefined, void>): void;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Promise-style signature (tương tự `IVsfReportAnalytics` nhưng trả về Promise).
|
|
168
|
+
*/
|
|
169
|
+
export interface IVsfReportAnalyticsAsync {
|
|
170
|
+
<K extends IVsfReportAnalyticsKnownEvent>(name: K, options?: IVsfReportAnalyticsEventMap[K]): Promise<void>;
|
|
171
|
+
<S extends string>(name: IVsfReportAnalyticsUnknownEvent<S>, options?: IVsfReportAnalyticsCustomProperties | undefined): Promise<void>;
|
|
172
|
+
}
|
|
@@ -25,7 +25,7 @@ export type IVsfPaymentMethod = {
|
|
|
25
25
|
/**
|
|
26
26
|
* Kết quả trả về khi người dùng chọn phương thức thanh toán (mảng các phương thức)
|
|
27
27
|
*/
|
|
28
|
-
export type IVsfShowPaymentMethodData = IVsfPaymentMethod
|
|
28
|
+
export type IVsfShowPaymentMethodData = IVsfPaymentMethod;
|
|
29
29
|
/**
|
|
30
30
|
* Tham số để hiển thị danh sách phương thức thanh toán
|
|
31
31
|
*/
|
package/dist/types/vsf.d.ts
CHANGED
|
@@ -281,12 +281,38 @@ export type IVsf = {
|
|
|
281
281
|
*/
|
|
282
282
|
removeStorage: IVsfRemoveStorage;
|
|
283
283
|
/**
|
|
284
|
-
* Gửi dữ liệu analytics
|
|
285
|
-
*
|
|
286
|
-
*
|
|
287
|
-
*
|
|
288
|
-
*
|
|
289
|
-
*
|
|
284
|
+
* Gửi dữ liệu analytics tùy chỉnh.
|
|
285
|
+
*
|
|
286
|
+
* Các event đã được định nghĩa sẵn (type-checked):
|
|
287
|
+
* - **Auto-tracked** (SDK tự bắn, developer không cần code):
|
|
288
|
+
* `miniapp_open`, `miniapp_close`, `page_view`, `permission_request`,
|
|
289
|
+
* `permission_grant`, `permission_revoke`.
|
|
290
|
+
* - **Custom** (developer chủ động bắn):
|
|
291
|
+
* `view_item`, `add_to_cart`, `remove_from_cart`, `begin_checkout`,
|
|
292
|
+
* `apply_promotion`.
|
|
293
|
+
*
|
|
294
|
+
* Event name nằm ngoài danh sách trên vẫn được chấp nhận, nhưng `properties`
|
|
295
|
+
* sẽ có type là `Record<string, any> | undefined`.
|
|
296
|
+
*
|
|
297
|
+
* @param name - Tên event
|
|
298
|
+
* @param options - Properties của event (theo schema tương ứng) cộng với
|
|
299
|
+
* `success` / `fail` / `complete` callbacks.
|
|
300
|
+
*
|
|
301
|
+
* @example
|
|
302
|
+
* ```ts
|
|
303
|
+
* apis.reportAnalytics('view_item', {
|
|
304
|
+
* currency: 'VND',
|
|
305
|
+
* value: 150000,
|
|
306
|
+
* items: [
|
|
307
|
+
* {
|
|
308
|
+
* item_id: 'SKU_12345',
|
|
309
|
+
* item_name: 'Stan and Friends Tee',
|
|
310
|
+
* item_price: 50000,
|
|
311
|
+
* quantity: 3,
|
|
312
|
+
* },
|
|
313
|
+
* ],
|
|
314
|
+
* })
|
|
315
|
+
* ```
|
|
290
316
|
*/
|
|
291
317
|
reportAnalytics: IVsfReportAnalytics;
|
|
292
318
|
/**
|
package/package.json
CHANGED