@uxda/appkit 4.2.93 → 4.2.94

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,239 @@
1
+ /**
2
+ * 埋点数据结构示例
3
+ * 展示新版数据结构的实际输出
4
+ */
5
+
6
+ import type { TrackingMainData } from '../tracking-sdk'
7
+
8
+ /**
9
+ * 示例1: 页面访问埋点
10
+ * 当用户访问商品详情页时自动生成
11
+ */
12
+ export const pageViewExample: TrackingMainData = {
13
+ log_id: '1732181400000_abc123def',
14
+ log_time: 1732181400000,
15
+ log_type: 'page',
16
+ tenant_id: '1',
17
+ user_id: 'user_123456',
18
+ source: 'H5',
19
+ session_id: 'session_abc123def456',
20
+ log_data: {
21
+ page: {
22
+ page_name: '商品详情页',
23
+ page_url: 'https://example.com/products/123',
24
+ page_referrer: 'https://example.com/home',
25
+ previous_page_name: '首页',
26
+ page_start_time: '2024-11-21T09:25:00Z',
27
+ page_duration: 0, // 刚进入页面,停留时间为0
28
+ },
29
+ },
30
+ }
31
+
32
+ /**
33
+ * 示例2: 点击事件埋点
34
+ * 当用户点击"加入购物车"按钮时触发
35
+ */
36
+ export const clickEventExample: TrackingMainData = {
37
+ log_id: '1732181405000_def456ghi',
38
+ log_time: 1732181405000,
39
+ log_type: 'page/event',
40
+ tenant_id: '1',
41
+ user_id: 'user_123456',
42
+ source: 'H5',
43
+ session_id: 'session_abc123def456',
44
+ log_data: {
45
+ page: {
46
+ page_name: '商品详情页',
47
+ page_url: 'https://example.com/products/123',
48
+ },
49
+ event: {
50
+ event_type: 'click',
51
+ event_name: '加入购物车按钮点击',
52
+ element_id: 'add_to_cart_btn',
53
+ },
54
+ },
55
+ }
56
+
57
+ /**
58
+ * 示例3: 自定义业务事件埋点
59
+ * 当用户完成购买时触发
60
+ */
61
+ export const customBusinessEventExample: TrackingMainData = {
62
+ log_id: '1732181410000_ghi789jkl',
63
+ log_time: 1732181410000,
64
+ log_type: 'event/',
65
+ tenant_id: '1',
66
+ user_id: 'user_123456',
67
+ source: 'H5',
68
+ session_id: 'session_abc123def456',
69
+ log_data: {
70
+ event: {
71
+ event_type: 'custom',
72
+ event_name: 'purchase_complete',
73
+ },
74
+ },
75
+ }
76
+
77
+ /**
78
+ * 示例4: 带性能数据的页面埋点
79
+ * 记录页面加载性能
80
+ */
81
+ export const performanceExample: TrackingMainData = {
82
+ log_id: '1732181415000_jkl012mno',
83
+ log_time: 1732181415000,
84
+ log_type: 'performance',
85
+ tenant_id: '1',
86
+ user_id: 'user_123456',
87
+ source: 'H5',
88
+ session_id: 'session_abc123def456',
89
+ log_data: {
90
+ performance: {
91
+ page_load_time: 1250, // 页面加载时间1.25秒
92
+ response_time: 320, // API响应时间320毫秒
93
+ fps: 60, // 帧率60fps
94
+ memory_usage: 45.2, // 内存使用45.2%
95
+ battery_usage: 15.8, // 电池使用15.8%
96
+ network_latency: 120, // 网络延迟120毫秒
97
+ crash_rate: 0.1, // 崩溃率0.1%
98
+ },
99
+ },
100
+ }
101
+
102
+ /**
103
+ * 示例5: 带错误信息的埋点
104
+ * 记录API调用失败
105
+ */
106
+ export const errorExample: TrackingMainData = {
107
+ log_id: '1732181420000_mno345pqr',
108
+ log_time: 1732181420000,
109
+ log_type: 'error',
110
+ tenant_id: '1',
111
+ user_id: 'user_123456',
112
+ source: 'H5',
113
+ session_id: 'session_abc123def456',
114
+ log_data: {
115
+ error: {
116
+ error_code: 'TIMEOUT',
117
+ error_message: '请求超时:接口 /api/products/123 响应时间超过3秒',
118
+ stack_trace:
119
+ 'Error: Request timeout\n at fetchProduct (api.ts:45)\n at ProductDetail.vue:123',
120
+ error_level: 'error',
121
+ error_context: JSON.stringify({
122
+ api: '/api/products/123',
123
+ method: 'GET',
124
+ timeout: 3000,
125
+ }),
126
+ },
127
+ },
128
+ }
129
+
130
+ /**
131
+ * 示例6: 完整的埋点数据
132
+ * 包含所有可能的字段
133
+ */
134
+ export const completeExample: TrackingMainData = {
135
+ log_id: '1732181425000_pqr678stu',
136
+ log_time: 1732181425000,
137
+ log_type: 'page/event/app/device/performance/error',
138
+ tenant_id: '1',
139
+ user_id: 'user_123456',
140
+ source: 'H5',
141
+ session_id: 'session_abc123def456',
142
+ log_data: {
143
+ page: {
144
+ page_name: '商品详情页',
145
+ page_url: 'https://example.com/products/123',
146
+ page_referrer: 'https://example.com/home',
147
+ previous_page_name: '首页',
148
+ page_start_time: '2024-11-21T09:25:00Z',
149
+ page_duration: 300000,
150
+ },
151
+ event: {
152
+ event_type: 'click',
153
+ event_name: '加入购物车按钮点击',
154
+ element_id: 'add_to_cart_btn',
155
+ },
156
+ app: {
157
+ app_version: '3.2.1',
158
+ package_name: 'com.example.app',
159
+ app_channel: 'H5',
160
+ },
161
+ device: {
162
+ device_type: 'mobile',
163
+ os: 'iOS',
164
+ os_version: '16.5',
165
+ brand: 'Apple',
166
+ model: 'iPhone 14 Pro',
167
+ network_type: '5G',
168
+ },
169
+ performance: {
170
+ page_load_time: 1250,
171
+ response_time: 320,
172
+ fps: 60,
173
+ memory_usage: 45.2,
174
+ battery_usage: 15.8,
175
+ network_latency: 120,
176
+ crash_rate: 0.1,
177
+ },
178
+ error: {
179
+ error_code: '',
180
+ error_message: '',
181
+ stack_trace: '',
182
+ error_level: 'info',
183
+ error_context: '',
184
+ },
185
+ },
186
+ }
187
+
188
+ /**
189
+ * 使用示例代码
190
+ */
191
+ export const usageExamples = {
192
+ // 1. 基本点击事件
193
+ async trackButtonClick() {
194
+ const { trackClick } = await import('../tracking-sdk')
195
+ await trackClick('submit_btn', '提交按钮')
196
+ },
197
+
198
+ // 2. 自定义业务事件
199
+ async trackPurchase(orderId: string, amount: number) {
200
+ const { trackCustom } = await import('../tracking-sdk')
201
+ await trackCustom('purchase_complete', {
202
+ order_id: orderId,
203
+ amount,
204
+ currency: 'CNY',
205
+ })
206
+ },
207
+
208
+ // 3. 带性能数据的埋点
209
+ async trackPagePerformance(loadTime: number, responseTime: number) {
210
+ const { trackCustom } = await import('../tracking-sdk')
211
+ await trackCustom('page_performance', {
212
+ performance: {
213
+ page_load_time: loadTime,
214
+ response_time: responseTime,
215
+ fps: 60,
216
+ },
217
+ })
218
+ },
219
+
220
+ // 4. 带错误信息的埋点
221
+ async trackError(error: Error, context: string) {
222
+ const { trackCustom } = await import('../tracking-sdk')
223
+ await trackCustom('error_occurred', {
224
+ error: {
225
+ error_code: error.name,
226
+ error_message: error.message,
227
+ stack_trace: error.stack,
228
+ error_level: 'error',
229
+ error_context: context,
230
+ },
231
+ })
232
+ },
233
+
234
+ // 5. 页面访问埋点
235
+ async trackPageVisit(pageTitle: string) {
236
+ const { trackPageView } = await import('../tracking-sdk')
237
+ await trackPageView(pageTitle)
238
+ },
239
+ }
@@ -0,0 +1,202 @@
1
+ <template>
2
+ <view class="directive-tracking-example">
3
+ <view class="header">
4
+ <text class="title">埋点指令使用示例</text>
5
+ </view>
6
+
7
+ <!-- 页面访问埋点示例 -->
8
+ <view class="section">
9
+ <text class="section-title">页面访问埋点</text>
10
+ <view class="content">
11
+ <view v-track-page="'指令页面访问示例'">
12
+ <text>此区域已启用页面访问埋点</text>
13
+ </view>
14
+
15
+ <view v-track-page="{ pageTitle: '自定义页面标题', customData: { pageType: 'example' } }">
16
+ <text>此区域使用自定义配置的页面访问埋点</text>
17
+ </view>
18
+ </view>
19
+ </view>
20
+
21
+ <!-- 点击埋点示例 -->
22
+ <view class="section">
23
+ <text class="section-title">点击埋点</text>
24
+ <view class="content">
25
+ <!-- 基础点击埋点 -->
26
+ <button v-track-click="'basic_click'" class="btn">基础点击埋点</button>
27
+
28
+ <!-- 带数据的点击埋点 -->
29
+ <button
30
+ v-track-click="{
31
+ event: 'custom_click',
32
+ data: { buttonType: 'primary', value: 123 },
33
+ }"
34
+ class="btn">
35
+ 自定义数据点击埋点
36
+ </button>
37
+
38
+ <!-- 带元素信息的点击埋点 -->
39
+ <button
40
+ id="custom-btn"
41
+ v-track-click="{
42
+ event: 'element_click',
43
+ elementId: 'custom-btn',
44
+ elementText: '自定义元素信息',
45
+ data: { action: 'submit' },
46
+ }"
47
+ class="btn btn-secondary">
48
+ 自定义元素信息点击埋点
49
+ </button>
50
+ </view>
51
+ </view>
52
+
53
+ <!-- 滚动埋点示例 -->
54
+ <view class="section">
55
+ <text class="section-title">滚动埋点</text>
56
+ <view class="content">
57
+ <!-- 基础滚动埋点 -->
58
+ <view v-track-scroll="true" class="scroll-demo">
59
+ <text>滚动到此区域会触发埋点</text>
60
+ </view>
61
+
62
+ <!-- 自定义滚动埋点 -->
63
+ <view
64
+ v-track-scroll="{
65
+ threshold: 0.3,
66
+ data: { section: 'custom_scroll' },
67
+ trackDirection: true,
68
+ }"
69
+ class="scroll-demo">
70
+ <text>自定义配置的滚动埋点(阈值30%)</text>
71
+ </view>
72
+ </view>
73
+ </view>
74
+
75
+ <!-- 组合使用示例 -->
76
+ <view class="section">
77
+ <text class="section-title">组合使用示例</text>
78
+ <view class="content">
79
+ <view v-track-page="{ pageTitle: '组合示例页面' }" v-track-scroll="{ threshold: 0.5 }">
80
+ <button
81
+ v-track-click="{
82
+ event: 'combo_click',
83
+ data: { combo: true },
84
+ }"
85
+ class="btn">
86
+ 组合埋点按钮
87
+ </button>
88
+ </view>
89
+ </view>
90
+ </view>
91
+
92
+ <!-- 指令说明 -->
93
+ <view class="section">
94
+ <text class="section-title">指令说明</text>
95
+ <view class="content">
96
+ <text class="instruction">v-track-page: 页面访问埋点,支持页面标题和自定义数据</text>
97
+ <text class="instruction">v-track-click: 点击埋点,支持事件名称、元素信息和自定义数据</text>
98
+ <text class="instruction">v-track-scroll: 滚动埋点,支持滚动阈值和方向跟踪</text>
99
+ </view>
100
+ </view>
101
+ </view>
102
+ </template>
103
+
104
+ <script setup lang="ts">
105
+ import { onMounted } from 'vue'
106
+ import { trackingSDK } from '../tracking-sdk'
107
+
108
+ // 页面挂载时的处理
109
+ onMounted(() => {
110
+ // 发送页面访问埋点
111
+ trackingSDK.trackPageView('埋点指令使用示例页面')
112
+ })
113
+ </script>
114
+
115
+ <style scoped>
116
+ .directive-tracking-example {
117
+ padding: 20px;
118
+ background-color: #f5f5f5;
119
+ min-height: 100vh;
120
+ }
121
+
122
+ .header {
123
+ text-align: center;
124
+ margin-bottom: 30px;
125
+ }
126
+
127
+ .title {
128
+ font-size: 24px;
129
+ font-weight: bold;
130
+ color: #333;
131
+ }
132
+
133
+ .section {
134
+ margin-bottom: 30px;
135
+ background-color: white;
136
+ border-radius: 8px;
137
+ padding: 20px;
138
+ box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
139
+ }
140
+
141
+ .section-title {
142
+ font-size: 18px;
143
+ font-weight: bold;
144
+ color: #333;
145
+ margin-bottom: 15px;
146
+ display: block;
147
+ }
148
+
149
+ .content {
150
+ display: flex;
151
+ flex-direction: column;
152
+ gap: 15px;
153
+ }
154
+
155
+ .btn {
156
+ background-color: #007aff;
157
+ color: white;
158
+ border: none;
159
+ border-radius: 6px;
160
+ padding: 12px 20px;
161
+ font-size: 16px;
162
+ cursor: pointer;
163
+ transition: background-color 0.3s;
164
+ }
165
+
166
+ .btn:hover {
167
+ background-color: #0056cc;
168
+ }
169
+
170
+ .btn:active {
171
+ background-color: #004499;
172
+ }
173
+
174
+ .btn-secondary {
175
+ background-color: #6c757d;
176
+ }
177
+
178
+ .btn-secondary:hover {
179
+ background-color: #545b62;
180
+ }
181
+
182
+ .scroll-demo {
183
+ height: 200px;
184
+ background-color: #e8f4fd;
185
+ border: 2px dashed #007aff;
186
+ border-radius: 6px;
187
+ display: flex;
188
+ align-items: center;
189
+ justify-content: center;
190
+ text-align: center;
191
+ color: #007aff;
192
+ font-weight: bold;
193
+ }
194
+
195
+ .instruction {
196
+ color: #666;
197
+ font-size: 14px;
198
+ line-height: 1.5;
199
+ display: block;
200
+ margin-bottom: 8px;
201
+ }
202
+ </style>
@@ -0,0 +1,25 @@
1
+ <template>
2
+ <view>
3
+ <!-- 使用全局埋点方法 -->
4
+ <button @click="handleClick">点击按钮</button>
5
+ </view>
6
+ </template>
7
+
8
+ <script setup lang="ts">
9
+ // 使用全局埋点方法(已在app.ts中注册)
10
+ const handleClick = () => {
11
+ // 使用全局 $track 方法
12
+ this.$track('button_click', {
13
+ buttonId: 'submit',
14
+ page: 'example',
15
+ })
16
+
17
+ // 使用全局 $trackPage 方法
18
+ this.$trackPage('页面标题', {
19
+ customData: 'value',
20
+ })
21
+
22
+ // 使用全局 $trackClick 方法
23
+ this.$trackClick('button-id', '按钮文本')
24
+ }
25
+ </script>
@@ -0,0 +1,27 @@
1
+ <template>
2
+ <view>
3
+ <!-- 你的页面内容 -->
4
+ </view>
5
+ </template>
6
+
7
+ <script setup lang="ts">
8
+ // 导入自动埋点组合式函数
9
+ import { usePageTracking } from '~/composables/useAutoTracking'
10
+
11
+ // 启用页面级自动埋点
12
+ const tracking = usePageTracking({
13
+ pageTitle: '页面标题', // 自定义页面标题
14
+ customData: {
15
+ pageType: 'example', // 自定义页面类型
16
+ // 其他自定义数据
17
+ },
18
+ })
19
+
20
+ // 可选:手动埋点示例
21
+ const handleCustomEvent = () => {
22
+ tracking.trackEvent('custom_button_click', {
23
+ buttonType: 'primary',
24
+ action: 'submit',
25
+ })
26
+ }
27
+ </script>
@@ -0,0 +1,33 @@
1
+ <template>
2
+ <view>
3
+ <!-- 页面内容 -->
4
+ </view>
5
+ </template>
6
+
7
+ <script setup lang="ts">
8
+ import { trackingSDK, TrackingEventType } from '../tracking-sdk'
9
+
10
+ // 页面访问埋点
11
+ trackingSDK.trackPageView('示例页面')
12
+
13
+ // 自定义事件埋点
14
+ const handleCustomEvent = () => {
15
+ trackingSDK.trackCustom('custom_event', {
16
+ action: 'click',
17
+ element: 'button',
18
+ })
19
+ }
20
+
21
+ // 业务事件埋点
22
+ const handleBusinessEvent = () => {
23
+ trackingSDK.trackBusiness(TrackingEventType.CUSTOM, {
24
+ businessType: 'order',
25
+ action: 'create',
26
+ })
27
+ }
28
+
29
+ // 点击事件埋点
30
+ const handleClick = () => {
31
+ trackingSDK.trackClick('button-id', '按钮文本')
32
+ }
33
+ </script>
@@ -0,0 +1,5 @@
1
+ import { usePageTracking } from './useAutoTracking'
2
+ import { trackingSDK } from './tracking-sdk'
3
+ import { initTracking, installTrackingPlugin } from './tracking-init'
4
+
5
+ export { usePageTracking, trackingSDK, initTracking, installTrackingPlugin }