@macroui/event-tracker 1.3.0

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.
Files changed (71) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +343 -0
  3. package/bin/event-tracker-suggest.mjs +141 -0
  4. package/bin/event-tracker.mjs +157 -0
  5. package/dist/event-tracker.cjs +3449 -0
  6. package/dist/event-tracker.js +3455 -0
  7. package/dist/event-tracker.min.js +1 -0
  8. package/dist/event-tracker.mjs +3402 -0
  9. package/dist/plugin/auto-track.cjs +201 -0
  10. package/dist/plugin/auto-track.mjs +199 -0
  11. package/dist/plugin/debug-sender.cjs +214 -0
  12. package/dist/plugin/debug-sender.mjs +211 -0
  13. package/dist/plugin/encrypt.cjs +284 -0
  14. package/dist/plugin/encrypt.mjs +275 -0
  15. package/dist/plugin/exposure.cjs +121 -0
  16. package/dist/plugin/exposure.mjs +119 -0
  17. package/dist/plugin/indexeddb-sender.cjs +94 -0
  18. package/dist/plugin/indexeddb-sender.mjs +92 -0
  19. package/dist/plugin/pageleave.cjs +74 -0
  20. package/dist/plugin/pageleave.mjs +72 -0
  21. package/dist/plugin/pageload.cjs +198 -0
  22. package/dist/plugin/pageload.mjs +196 -0
  23. package/dist/plugin/session-event.cjs +142 -0
  24. package/dist/plugin/session-event.mjs +140 -0
  25. package/dist/plugin/webview-bridge.cjs +111 -0
  26. package/dist/plugin/webview-bridge.mjs +109 -0
  27. package/dist/types/core/env.d.ts +10 -0
  28. package/dist/types/core/errors.d.ts +76 -0
  29. package/dist/types/core/failed-queue.d.ts +24 -0
  30. package/dist/types/core/identity-api.d.ts +6 -0
  31. package/dist/types/core/identity.d.ts +39 -0
  32. package/dist/types/core/instance-channel.d.ts +34 -0
  33. package/dist/types/core/lifecycle.d.ts +26 -0
  34. package/dist/types/core/logger.d.ts +13 -0
  35. package/dist/types/core/plugin.d.ts +60 -0
  36. package/dist/types/core/profile-api.d.ts +6 -0
  37. package/dist/types/core/profile-store.d.ts +23 -0
  38. package/dist/types/core/register-api.d.ts +22 -0
  39. package/dist/types/core/retry-policy.d.ts +33 -0
  40. package/dist/types/core/send-pipeline.d.ts +55 -0
  41. package/dist/types/core/signed-identity.d.ts +29 -0
  42. package/dist/types/core/stage.d.ts +48 -0
  43. package/dist/types/core/track-api.d.ts +6 -0
  44. package/dist/types/core/tracker.d.ts +130 -0
  45. package/dist/types/core/uuid.d.ts +4 -0
  46. package/dist/types/index.d.ts +40 -0
  47. package/dist/types/plugins/auto-track/index.d.ts +21 -0
  48. package/dist/types/plugins/debug-sender/index.d.ts +24 -0
  49. package/dist/types/plugins/encrypt/index.d.ts +56 -0
  50. package/dist/types/plugins/exposure/index.d.ts +18 -0
  51. package/dist/types/plugins/indexeddb-sender/index.d.ts +15 -0
  52. package/dist/types/plugins/pageleave/index.d.ts +12 -0
  53. package/dist/types/plugins/pageload/index.d.ts +14 -0
  54. package/dist/types/plugins/session-event/index.d.ts +14 -0
  55. package/dist/types/plugins/webview-bridge/index.d.ts +33 -0
  56. package/dist/types/presets/preset-properties.d.ts +25 -0
  57. package/dist/types/send/ajax-sender.d.ts +11 -0
  58. package/dist/types/send/batch-sender.d.ts +17 -0
  59. package/dist/types/send/beacon-sender.d.ts +10 -0
  60. package/dist/types/send/encode.d.ts +8 -0
  61. package/dist/types/send/image-sender.d.ts +10 -0
  62. package/dist/types/send/sender.d.ts +20 -0
  63. package/dist/types/storage/indexeddb-store.d.ts +14 -0
  64. package/dist/types/storage/store.d.ts +56 -0
  65. package/dist/types/types/common.d.ts +26 -0
  66. package/dist/types/types/config.d.ts +117 -0
  67. package/dist/types/types/constants.d.ts +110 -0
  68. package/dist/types/types/index.d.ts +25 -0
  69. package/dist/types/types.test-d.d.ts +5 -0
  70. package/dist/types.test-d.ts +103 -0
  71. package/package.json +218 -0
@@ -0,0 +1,201 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * 浏览器端辅助方法
5
+ */
6
+ function isBrowser() {
7
+ return typeof window !== 'undefined' && typeof window.document !== 'undefined';
8
+ }
9
+
10
+ /**
11
+ * SDK 预置事件名与预置属性 key(v1.1:完整对齐神策)
12
+ * 命名风格对齐神策,方便跨平台对接
13
+ */
14
+ /** 预置事件名 */
15
+ var PresetEvent = {
16
+ PageView: '$pageview',
17
+ WebClick: '$WebClick',
18
+ WebStay: '$WebStay'};
19
+ /** 预置属性 key */
20
+ var PresetProperty = {
21
+ URLPath: '$url_path',
22
+ Title: '$title',
23
+ Referrer: '$referrer',
24
+ // 全埋点元素属性
25
+ ElementSelector: '$element_selector',
26
+ ElementType: '$element_type',
27
+ ElementId: '$element_id',
28
+ ElementClassName: '$element_class_name',
29
+ ElementContent: '$element_content',
30
+ EventDuration: '$event_duration'};
31
+
32
+ /**
33
+ * auto-track 插件
34
+ * - $pageview: 路由变化时自动 track
35
+ * - $WebClick: 监听 click,自动 track
36
+ * - $WebStay: 页面离开时上报停留时长
37
+ * - $scrolldepth: 25/50/75/100% 触发
38
+ */
39
+ function autoTrack(opts) {
40
+ var _a;
41
+ if (opts === void 0) { opts = {}; }
42
+ var sdkRef = null;
43
+ var enterTime = Date.now();
44
+ var reachedThresholds = new Set();
45
+ var thresholds = (_a = opts.scrollThresholds) !== null && _a !== void 0 ? _a : [25, 50, 75, 100];
46
+ function fire(event, properties) {
47
+ if (properties === void 0) { properties = {}; }
48
+ if (!sdkRef)
49
+ return;
50
+ sdkRef.track(event, properties);
51
+ }
52
+ function path() {
53
+ try {
54
+ return location.pathname + location.search + location.hash;
55
+ }
56
+ catch (_a) {
57
+ return '';
58
+ }
59
+ }
60
+ function setupPageview() {
61
+ var send = function () {
62
+ var _a;
63
+ fire(PresetEvent.PageView, (_a = {},
64
+ _a[PresetProperty.URLPath] = path(),
65
+ _a[PresetProperty.Title] = document.title,
66
+ _a[PresetProperty.Referrer] = document.referrer,
67
+ _a));
68
+ };
69
+ // 首次加载
70
+ setTimeout(send, 0);
71
+ // history.pushState/replaceState
72
+ var wrap = function (key) {
73
+ var orig = history[key];
74
+ history[key] = function () {
75
+ var args = [];
76
+ for (var _i = 0; _i < arguments.length; _i++) {
77
+ args[_i] = arguments[_i];
78
+ }
79
+ var r = orig.apply(this, args);
80
+ setTimeout(send, 0);
81
+ return r;
82
+ };
83
+ };
84
+ wrap('pushState');
85
+ wrap('replaceState');
86
+ // popstate
87
+ window.addEventListener('popstate', function () { return setTimeout(send, 0); });
88
+ // hashchange
89
+ window.addEventListener('hashchange', function () { return setTimeout(send, 0); });
90
+ }
91
+ function setupWebClick(selector, attrs) {
92
+ var onClick = function (e) {
93
+ var _a;
94
+ var target = e.target;
95
+ if (!target)
96
+ return;
97
+ var el = target.closest(selector || 'a, button, [data-track-click]');
98
+ if (!el)
99
+ return;
100
+ var props = (_a = {},
101
+ _a[PresetProperty.ElementSelector] = cssPath(el),
102
+ _a[PresetProperty.ElementType] = el.tagName.toLowerCase(),
103
+ _a[PresetProperty.ElementContent] = (el.textContent || '').trim().slice(0, 100),
104
+ _a[PresetProperty.ElementId] = el.id || undefined,
105
+ _a[PresetProperty.ElementClassName] = el.className || undefined,
106
+ _a);
107
+ if (el instanceof HTMLAnchorElement) {
108
+ props['$element_href'] = el.href;
109
+ }
110
+ for (var _i = 0, attrs_1 = attrs; _i < attrs_1.length; _i++) {
111
+ var a = attrs_1[_i];
112
+ var v = el.getAttribute(a);
113
+ if (v != null)
114
+ props[a] = v;
115
+ }
116
+ fire(PresetEvent.WebClick, props);
117
+ };
118
+ document.addEventListener('click', onClick, true);
119
+ }
120
+ function cssPath(el) {
121
+ if (el.id)
122
+ return "#".concat(el.id);
123
+ var parts = [];
124
+ var cur = el;
125
+ var _loop_1 = function () {
126
+ var self_1 = cur;
127
+ var part = self_1.tagName.toLowerCase();
128
+ if (self_1.classList && self_1.classList.length) {
129
+ part += '.' + Array.from(self_1.classList).slice(0, 2).join('.');
130
+ }
131
+ var parent_1 = self_1.parentElement;
132
+ if (parent_1) {
133
+ var siblings = Array.from(parent_1.children).filter(function (c) { return c instanceof Element && c.tagName === self_1.tagName; });
134
+ if (siblings.length > 1) {
135
+ part += ":nth-of-type(".concat(siblings.indexOf(self_1) + 1, ")");
136
+ }
137
+ }
138
+ parts.unshift(part);
139
+ cur = parent_1;
140
+ };
141
+ while (cur && cur !== document.body && parts.length < 5) {
142
+ _loop_1();
143
+ }
144
+ return parts.join(' > ');
145
+ }
146
+ function setupWebStay() {
147
+ var onEnter = function () { enterTime = Date.now(); };
148
+ var onLeave = function () {
149
+ var _a;
150
+ var dur = Date.now() - enterTime;
151
+ fire(PresetEvent.WebStay, (_a = {},
152
+ _a[PresetProperty.EventDuration] = dur,
153
+ _a[PresetProperty.URLPath] = path(),
154
+ _a));
155
+ };
156
+ window.addEventListener('beforeunload', onLeave);
157
+ document.addEventListener('visibilitychange', function () {
158
+ if (document.visibilityState === 'hidden')
159
+ onLeave();
160
+ else
161
+ onEnter();
162
+ });
163
+ }
164
+ function setupScrollDepth() {
165
+ reachedThresholds = new Set();
166
+ var onScroll = function () {
167
+ var _a;
168
+ var docH = document.documentElement.scrollHeight - window.innerHeight;
169
+ if (docH <= 0)
170
+ return;
171
+ var pct = Math.min(100, Math.round((window.scrollY / docH) * 100));
172
+ for (var _i = 0, thresholds_1 = thresholds; _i < thresholds_1.length; _i++) {
173
+ var t = thresholds_1[_i];
174
+ if (pct >= t && !reachedThresholds.has(t)) {
175
+ reachedThresholds.add(t);
176
+ fire('$scroll_depth', (_a = { percent: t }, _a[PresetProperty.URLPath] = path(), _a));
177
+ }
178
+ }
179
+ };
180
+ window.addEventListener('scroll', onScroll, { passive: true });
181
+ }
182
+ return {
183
+ name: 'auto-track',
184
+ install: function (_a) {
185
+ var sdk = _a.sdk;
186
+ if (!isBrowser())
187
+ return;
188
+ sdkRef = sdk;
189
+ if (opts.pageview !== false)
190
+ setupPageview();
191
+ if (opts.webclick !== false)
192
+ setupWebClick(opts.webclickSelector, opts.webclickAttrs || ['data-track-id', 'data-sensors-click']);
193
+ if (opts.webstay !== false)
194
+ setupWebStay();
195
+ if (opts.scrolldepth)
196
+ setupScrollDepth();
197
+ },
198
+ };
199
+ }
200
+
201
+ exports.autoTrack = autoTrack;
@@ -0,0 +1,199 @@
1
+ /**
2
+ * 浏览器端辅助方法
3
+ */
4
+ function isBrowser() {
5
+ return typeof window !== 'undefined' && typeof window.document !== 'undefined';
6
+ }
7
+
8
+ /**
9
+ * SDK 预置事件名与预置属性 key(v1.1:完整对齐神策)
10
+ * 命名风格对齐神策,方便跨平台对接
11
+ */
12
+ /** 预置事件名 */
13
+ var PresetEvent = {
14
+ PageView: '$pageview',
15
+ WebClick: '$WebClick',
16
+ WebStay: '$WebStay'};
17
+ /** 预置属性 key */
18
+ var PresetProperty = {
19
+ URLPath: '$url_path',
20
+ Title: '$title',
21
+ Referrer: '$referrer',
22
+ // 全埋点元素属性
23
+ ElementSelector: '$element_selector',
24
+ ElementType: '$element_type',
25
+ ElementId: '$element_id',
26
+ ElementClassName: '$element_class_name',
27
+ ElementContent: '$element_content',
28
+ EventDuration: '$event_duration'};
29
+
30
+ /**
31
+ * auto-track 插件
32
+ * - $pageview: 路由变化时自动 track
33
+ * - $WebClick: 监听 click,自动 track
34
+ * - $WebStay: 页面离开时上报停留时长
35
+ * - $scrolldepth: 25/50/75/100% 触发
36
+ */
37
+ function autoTrack(opts) {
38
+ var _a;
39
+ if (opts === void 0) { opts = {}; }
40
+ var sdkRef = null;
41
+ var enterTime = Date.now();
42
+ var reachedThresholds = new Set();
43
+ var thresholds = (_a = opts.scrollThresholds) !== null && _a !== void 0 ? _a : [25, 50, 75, 100];
44
+ function fire(event, properties) {
45
+ if (properties === void 0) { properties = {}; }
46
+ if (!sdkRef)
47
+ return;
48
+ sdkRef.track(event, properties);
49
+ }
50
+ function path() {
51
+ try {
52
+ return location.pathname + location.search + location.hash;
53
+ }
54
+ catch (_a) {
55
+ return '';
56
+ }
57
+ }
58
+ function setupPageview() {
59
+ var send = function () {
60
+ var _a;
61
+ fire(PresetEvent.PageView, (_a = {},
62
+ _a[PresetProperty.URLPath] = path(),
63
+ _a[PresetProperty.Title] = document.title,
64
+ _a[PresetProperty.Referrer] = document.referrer,
65
+ _a));
66
+ };
67
+ // 首次加载
68
+ setTimeout(send, 0);
69
+ // history.pushState/replaceState
70
+ var wrap = function (key) {
71
+ var orig = history[key];
72
+ history[key] = function () {
73
+ var args = [];
74
+ for (var _i = 0; _i < arguments.length; _i++) {
75
+ args[_i] = arguments[_i];
76
+ }
77
+ var r = orig.apply(this, args);
78
+ setTimeout(send, 0);
79
+ return r;
80
+ };
81
+ };
82
+ wrap('pushState');
83
+ wrap('replaceState');
84
+ // popstate
85
+ window.addEventListener('popstate', function () { return setTimeout(send, 0); });
86
+ // hashchange
87
+ window.addEventListener('hashchange', function () { return setTimeout(send, 0); });
88
+ }
89
+ function setupWebClick(selector, attrs) {
90
+ var onClick = function (e) {
91
+ var _a;
92
+ var target = e.target;
93
+ if (!target)
94
+ return;
95
+ var el = target.closest(selector || 'a, button, [data-track-click]');
96
+ if (!el)
97
+ return;
98
+ var props = (_a = {},
99
+ _a[PresetProperty.ElementSelector] = cssPath(el),
100
+ _a[PresetProperty.ElementType] = el.tagName.toLowerCase(),
101
+ _a[PresetProperty.ElementContent] = (el.textContent || '').trim().slice(0, 100),
102
+ _a[PresetProperty.ElementId] = el.id || undefined,
103
+ _a[PresetProperty.ElementClassName] = el.className || undefined,
104
+ _a);
105
+ if (el instanceof HTMLAnchorElement) {
106
+ props['$element_href'] = el.href;
107
+ }
108
+ for (var _i = 0, attrs_1 = attrs; _i < attrs_1.length; _i++) {
109
+ var a = attrs_1[_i];
110
+ var v = el.getAttribute(a);
111
+ if (v != null)
112
+ props[a] = v;
113
+ }
114
+ fire(PresetEvent.WebClick, props);
115
+ };
116
+ document.addEventListener('click', onClick, true);
117
+ }
118
+ function cssPath(el) {
119
+ if (el.id)
120
+ return "#".concat(el.id);
121
+ var parts = [];
122
+ var cur = el;
123
+ var _loop_1 = function () {
124
+ var self_1 = cur;
125
+ var part = self_1.tagName.toLowerCase();
126
+ if (self_1.classList && self_1.classList.length) {
127
+ part += '.' + Array.from(self_1.classList).slice(0, 2).join('.');
128
+ }
129
+ var parent_1 = self_1.parentElement;
130
+ if (parent_1) {
131
+ var siblings = Array.from(parent_1.children).filter(function (c) { return c instanceof Element && c.tagName === self_1.tagName; });
132
+ if (siblings.length > 1) {
133
+ part += ":nth-of-type(".concat(siblings.indexOf(self_1) + 1, ")");
134
+ }
135
+ }
136
+ parts.unshift(part);
137
+ cur = parent_1;
138
+ };
139
+ while (cur && cur !== document.body && parts.length < 5) {
140
+ _loop_1();
141
+ }
142
+ return parts.join(' > ');
143
+ }
144
+ function setupWebStay() {
145
+ var onEnter = function () { enterTime = Date.now(); };
146
+ var onLeave = function () {
147
+ var _a;
148
+ var dur = Date.now() - enterTime;
149
+ fire(PresetEvent.WebStay, (_a = {},
150
+ _a[PresetProperty.EventDuration] = dur,
151
+ _a[PresetProperty.URLPath] = path(),
152
+ _a));
153
+ };
154
+ window.addEventListener('beforeunload', onLeave);
155
+ document.addEventListener('visibilitychange', function () {
156
+ if (document.visibilityState === 'hidden')
157
+ onLeave();
158
+ else
159
+ onEnter();
160
+ });
161
+ }
162
+ function setupScrollDepth() {
163
+ reachedThresholds = new Set();
164
+ var onScroll = function () {
165
+ var _a;
166
+ var docH = document.documentElement.scrollHeight - window.innerHeight;
167
+ if (docH <= 0)
168
+ return;
169
+ var pct = Math.min(100, Math.round((window.scrollY / docH) * 100));
170
+ for (var _i = 0, thresholds_1 = thresholds; _i < thresholds_1.length; _i++) {
171
+ var t = thresholds_1[_i];
172
+ if (pct >= t && !reachedThresholds.has(t)) {
173
+ reachedThresholds.add(t);
174
+ fire('$scroll_depth', (_a = { percent: t }, _a[PresetProperty.URLPath] = path(), _a));
175
+ }
176
+ }
177
+ };
178
+ window.addEventListener('scroll', onScroll, { passive: true });
179
+ }
180
+ return {
181
+ name: 'auto-track',
182
+ install: function (_a) {
183
+ var sdk = _a.sdk;
184
+ if (!isBrowser())
185
+ return;
186
+ sdkRef = sdk;
187
+ if (opts.pageview !== false)
188
+ setupPageview();
189
+ if (opts.webclick !== false)
190
+ setupWebClick(opts.webclickSelector, opts.webclickAttrs || ['data-track-id', 'data-sensors-click']);
191
+ if (opts.webstay !== false)
192
+ setupWebStay();
193
+ if (opts.scrolldepth)
194
+ setupScrollDepth();
195
+ },
196
+ };
197
+ }
198
+
199
+ export { autoTrack };
@@ -0,0 +1,214 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * 序列化 & 编码
5
+ */
6
+ function encodeEvent(event, encryptor) {
7
+ var json = JSON.stringify(event);
8
+ return encryptor ? encryptor(json) : json;
9
+ }
10
+ function buildUrl(serverUrl, payload, contentType) {
11
+ var base = Array.isArray(serverUrl) ? serverUrl[0] || '' : serverUrl;
12
+ var has = base.indexOf('?') >= 0;
13
+ {
14
+ return "".concat(base).concat(has ? '&' : '?', "data=").concat(encodeURIComponent(payload));
15
+ }
16
+ }
17
+
18
+ /**
19
+ * 浏览器端辅助方法
20
+ */
21
+ function isBrowser() {
22
+ return typeof window !== 'undefined' && typeof window.document !== 'undefined';
23
+ }
24
+ function hasImage() {
25
+ return isBrowser() && typeof Image === 'function';
26
+ }
27
+
28
+ /**
29
+ * SDK 预置事件名与预置属性 key(v1.1:完整对齐神策)
30
+ * 命名风格对齐神策,方便跨平台对接
31
+ */
32
+ /** 预置事件名 */
33
+ /** 预置属性 key */
34
+ var PresetProperty = {
35
+ // 设备 / 环境
36
+ AppId: '$app_id',
37
+ AppVersion: '$app_version',
38
+ Lib: '$lib',
39
+ LibMethod: '$lib_method',
40
+ LibDetail: '$lib_detail',
41
+ LibVersion: '$lib_version',
42
+ ScreenWidth: '$screen_width',
43
+ ScreenHeight: '$screen_height',
44
+ ViewportWidth: '$viewport_width',
45
+ ViewportHeight: '$viewport_height',
46
+ TimezoneOffset: '$timezone_offset',
47
+ UserAgent: '$user_agent',
48
+ Language: '$language',
49
+ FirstBrowserCharset: '$first_browser_charset',
50
+ FirstBrowserLanguage: '$first_browser_language',
51
+ // 位置 / 流量来源
52
+ URL: '$url',
53
+ URLPath: '$url_path',
54
+ Title: '$title',
55
+ Referrer: '$referrer',
56
+ ReferrerHost: '$referrer_host',
57
+ LatestReferrer: '$latest_referrer',
58
+ LatestReferrerHost: '$latest_referrer_host',
59
+ LatestLandingPage: '$latest_landing_page',
60
+ LatestSearchKeyword: '$latest_search_keyword',
61
+ LatestTrafficSourceType: '$latest_traffic_source_type',
62
+ FirstReferrer: '$first_referrer',
63
+ FirstReferrerHost: '$first_referrer_host',
64
+ FirstSearchKeyword: '$first_search_keyword',
65
+ FirstTrafficSourceType: '$first_traffic_source_type',
66
+ FirstVisitTime: '$first_visit_time',
67
+ SearchKeywordId: '$search_keyword_id',
68
+ SearchKeywordIdHash: '$search_keyword_id_hash',
69
+ SearchKeywordIdType: '$search_keyword_id_type',
70
+ IsFirstDay: '$is_first_day',
71
+ IsFirstTime: '$is_first_time',
72
+ // UTM
73
+ LatestUtmSource: '$latest_utm_source',
74
+ LatestUtmMedium: '$latest_utm_medium',
75
+ LatestUtmCampaign: '$latest_utm_campaign',
76
+ LatestUtmContent: '$latest_utm_content',
77
+ LatestUtmTerm: '$latest_utm_term',
78
+ Utms: '$utms',
79
+ // 身份
80
+ DistinctId: '$distinct_id',
81
+ AnonymousId: '$anonymous_id',
82
+ FirstId: '$first_id',
83
+ OriginalId: '$original_id',
84
+ LoginId: '$login_id',
85
+ IsLoginId: '$is_login_id',
86
+ IdentityLoginId: '$identity_login_id',
87
+ IdentityAnonymousId: '$identity_anonymous_id',
88
+ IdentityCookieId: '$identity_cookie_id',
89
+ IdentityEmail: '$identity_email',
90
+ IdentityMobile: '$identity_mobile',
91
+ // 全埋点元素属性
92
+ ElementSelector: '$element_selector',
93
+ ElementPath: '$element_path',
94
+ ElementType: '$element_type',
95
+ ElementId: '$element_id',
96
+ ElementClassName: '$element_class_name',
97
+ ElementName: '$element_name',
98
+ ElementContent: '$element_content',
99
+ ElementTargetUrl: '$element_target_url',
100
+ ElementPosition: '$element_position',
101
+ PageX: '$page_x',
102
+ PageY: '$page_y',
103
+ // 性能
104
+ PageHeight: '$page_height',
105
+ PageResourceSize: '$page_resource_size',
106
+ EventDuration: '$event_duration',
107
+ ViewportPosition: '$viewport_position',
108
+ // 渠道
109
+ LatestWxAdClickId: '$latest_wx_ad_click_id',
110
+ LatestWxAdCallbacks: '$latest_wx_ad_callbacks',
111
+ LatestWxAdHashKey: '$latest_wx_ad_hash_key',
112
+ IsChannelCallbackEvent: '$is_channel_callback_event',
113
+ // 会话
114
+ EventSessionId: '$event_session_id',
115
+ // 元信息
116
+ Time: '$time',
117
+ Event: '$event',
118
+ Option: '$option',
119
+ Project: '$project',
120
+ Token: '$token',
121
+ // 特殊
122
+ SignupMethod: '$signup_method',
123
+ };
124
+
125
+ /**
126
+ * Debug 发送器(独立 plugin)
127
+ * - 启用后走 GET 请求到 debug_mode_url(默认从 server_url 推导 ?debug)
128
+ * - 成功后 alert("debug数据发送成功" + data)
129
+ * - 失败时 alert("debug失败" + JSON.stringify(err))
130
+ * - 优先级最高(先于其它 senders 执行)
131
+ */
132
+ function deriveDebugUrl(serverUrl) {
133
+ var base = Array.isArray(serverUrl) ? serverUrl[0] : serverUrl;
134
+ return base.includes('?') ? base + '&debug' : base + '?debug';
135
+ }
136
+ function debugSender(opts) {
137
+ if (opts === void 0) { opts = {}; }
138
+ return {
139
+ name: 'debug-sender',
140
+ install: function (_a) {
141
+ var _b, _c, _d, _e, _f;
142
+ var config = _a.config, stages = _a.stages, registry = _a.registry, sdk = _a.sdk;
143
+ var enabled = (_b = opts.enable) !== null && _b !== void 0 ? _b : !!config.debug_mode;
144
+ if (!enabled)
145
+ return;
146
+ var url = (_d = (_c = opts.url) !== null && _c !== void 0 ? _c : config.debug_mode_url) !== null && _d !== void 0 ? _d : deriveDebugUrl(config.server_url);
147
+ var upload = (_f = (_e = opts.upload) !== null && _e !== void 0 ? _e : config.debug_mode_upload) !== null && _f !== void 0 ? _f : 'true';
148
+ stages.sendDataStage.register({
149
+ name: 'debug-sender',
150
+ priority: 30, // 最高优先级
151
+ entry: function (ctx) {
152
+ var event = ctx.data;
153
+ try {
154
+ var enc = encodeEvent(event, config.encryptor);
155
+ Promise.resolve(enc).then(function (payload) {
156
+ var fullUrl = buildUrl(url, payload, 'form');
157
+ if (hasImage()) {
158
+ var img = new Image(1, 1);
159
+ img.onload = function () {
160
+ var _a;
161
+ try {
162
+ (_a = opts.onSuccess) === null || _a === void 0 ? void 0 : _a.call(opts, event);
163
+ }
164
+ catch ( /* ignore */_b) { /* ignore */ }
165
+ try {
166
+ if (typeof alert !== 'undefined')
167
+ alert('debug数据发送成功' + (event.event || ''));
168
+ }
169
+ catch ( /* ignore */_c) { /* ignore */ }
170
+ };
171
+ img.onerror = function () {
172
+ var _a;
173
+ var err = new Error('Image load failed');
174
+ try {
175
+ (_a = opts.onError) === null || _a === void 0 ? void 0 : _a.call(opts, err, event);
176
+ }
177
+ catch ( /* ignore */_b) { /* ignore */ }
178
+ try {
179
+ if (typeof alert !== 'undefined')
180
+ alert('debug失败 错误原因' + JSON.stringify({ message: err.message }));
181
+ }
182
+ catch ( /* ignore */_c) { /* ignore */ }
183
+ };
184
+ img.src = fullUrl;
185
+ }
186
+ else {
187
+ ctx.cancellationToken.stop();
188
+ }
189
+ }).catch(function (e) {
190
+ sdk.getLogger().error('debug-sender error:', e);
191
+ });
192
+ }
193
+ catch (e) {
194
+ sdk.getLogger().error('debug-sender error:', e);
195
+ }
196
+ return event;
197
+ },
198
+ });
199
+ // 标记 Dry-Run 风格
200
+ registry.on('sdkAfterInitAPI', function () {
201
+ Object.defineProperty(globalThis, '__et_debug_upload__', { value: upload, writable: true });
202
+ });
203
+ },
204
+ uninstall: function () {
205
+ try {
206
+ delete globalThis.__et_debug_upload__;
207
+ }
208
+ catch ( /* ignore */_a) { /* ignore */ }
209
+ },
210
+ };
211
+ }
212
+
213
+ exports.PresetProperty = PresetProperty;
214
+ exports.debugSender = debugSender;