gio-miniprogram-sdk 4.4.0 → 4.4.1

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,6 +1,6 @@
1
1
  import { EventHooksType, MinipPageType } from '@@/types/eventHooks';
2
2
  import { GrowingIOType } from '@@/types/growingIO';
3
- import { has, isArray, isFunction, typeOf, unset } from '@@/utils/glodash';
3
+ import { has, isArray, isEmpty, isFunction, typeOf } from '@@/utils/glodash';
4
4
  import { consoleText, getGlobal, niceTry } from '@@/utils/tools';
5
5
 
6
6
  import AppEffects from './appEffects';
@@ -87,95 +87,135 @@ class EventHooks implements EventHooksType {
87
87
  }
88
88
  };
89
89
 
90
- // 生命周期方法effects
90
+ /**
91
+ * 执行生命周期回调并广播事件
92
+ */
93
+ lifeFcEffectsFn = (instance, args, cType, eventName, result = undefined) => {
94
+ // 创建参数数组副本
95
+ const argsArray =
96
+ typeOf(args) === 'array' ? Array.prototype.slice.call(args) : [];
97
+ // 如果有结果,添加到参数列表
98
+ if (!isEmpty(result)) {
99
+ argsArray.push(result);
100
+ }
101
+
102
+ // 执行effects
103
+ this[`def${cType}Cbs`][eventName].apply(instance, argsArray);
104
+
105
+ // 广播生命周期
106
+ this.growingIO.emitter.emit(EMIT_MSG.MINIP_LIFECYCLE, {
107
+ event: `${cType} ${eventName}End`,
108
+ timestamp: Date.now(),
109
+ params: { instance, arguments: Array.from(argsArray) }
110
+ });
111
+
112
+ return result;
113
+ };
114
+
115
+ /**
116
+ * 生命周期方法effects
117
+ */
91
118
  lifeFcEffects = (eventName: string, method: any, cType: 'App' | 'Page') => {
92
119
  const self = this;
93
- if (['onShareTimeline', 'onAddToFavorites'].includes(eventName)) {
94
- // onShareTimeline和onAddToFavorites不能异步执行,单独处理
95
- return function (...args) {
96
- let result = method.apply(this, args);
97
- if (
98
- eventName === 'onShareTimeline' &&
99
- self.growingIO.vdsConfig.followShare
100
- ) {
101
- result = self.currentPage.updateTimelineResult(result ?? {});
102
- }
103
- if (eventName === 'onAddToFavorites') {
104
- result = self.currentPage.updateAddFavoritesResult(result ?? {});
105
- }
106
- const argsArray = Array.prototype.slice.call(args);
107
- if (result) {
108
- argsArray.push(result);
120
+
121
+ return function (...args) {
122
+ let result;
123
+
124
+ // 分享事件单独处理
125
+ if (self.shareEventTypes.includes(eventName)) {
126
+ // 先执行分享的生命周期拿到分享数据
127
+ const originResult = method.apply(this, args) ?? {};
128
+
129
+ // sdk跟踪分享事件时才处理,否则直接返回原结果
130
+ if (!self.growingIO.vdsConfig.followShare) {
131
+ return originResult;
109
132
  }
110
- // 执行effects
111
- self[`def${cType}Cbs`][eventName].apply(this, argsArray);
112
- return result;
113
- };
114
- } else {
115
- // 其他生命周期可以异步执行
116
- return async function (...args) {
117
- let result;
118
- try {
119
- // 分享处理
120
- if (self.shareEventTypes.includes(eventName)) {
121
- // 先执行分享的生命周期拿到分享数据
122
- // 与基础库保持一致,没有返回值时默认使用{}
123
- result = method.apply(this, args) ?? {};
124
- // 如果分享事件是个promise函数,需要等待异步结果
125
- if (typeOf(result) === 'promise') {
126
- result = await result.then((r) => r);
127
- }
128
- // 如果返回的对象中包含promise,要等待异步结果
129
- if (typeOf(result.promise) === 'promise') {
130
- const f = async function () {
131
- let sRes = result;
132
- return new Promise((resolve) => {
133
- // 如果3秒后result.promise没有返回结果,则返回的是默认的result值
134
- // https://developers.weixin.qq.com/miniprogram/dev/reference/api/Page.html#onShareAppMessage-Object-object
135
- let t = setTimeout(() => {
136
- resolve({ ...sRes });
137
- clearTimeout(t);
138
- t = undefined;
139
- }, 3000);
140
- result.promise.then((res) => {
141
- sRes = res;
142
- resolve({ ...sRes });
143
- clearTimeout(t);
144
- t = undefined;
145
- });
146
- });
133
+ const isPromiseResult = typeOf(originResult) === 'promise';
134
+ const hasPromiseProperty = typeOf(originResult.promise) === 'promise';
135
+ // 支付宝的promise会被提前处理过,通过以下两个字段判断是否需要自定义promise
136
+ const isSpecialPromise =
137
+ has(originResult, '_result') && has(originResult, '_state');
138
+
139
+ // 处理异步分享结果
140
+ if (isPromiseResult || hasPromiseProperty || isSpecialPromise) {
141
+ // 创建处理Promise结果的通用函数
142
+ const handlePromiseResult = (promiseResult = {}) => {
143
+ try {
144
+ // 合并原始结果和Promise结果
145
+ const mergedResult = {
146
+ ...originResult,
147
+ ...promiseResult
147
148
  };
148
- result = { ...result, ...((await f()) as any) };
149
- unset(result, 'promise');
150
- }
151
- if (self.growingIO.vdsConfig.followShare) {
152
- result = self.currentPage.updateAppMessageResult(result ?? {});
149
+
150
+ // 更新分享内容
151
+ const updatedResult =
152
+ self.currentPage.updateShareResult(mergedResult);
153
+
154
+ // 执行回调
155
+ self.lifeFcEffectsFn(this, args, cType, eventName, updatedResult);
156
+ } catch (error) {
157
+ consoleText(error, 'error');
153
158
  }
159
+ };
160
+
161
+ // 处理整个返回值是Promise的情况
162
+ if (isPromiseResult) {
163
+ // 如果三秒内不resolve结果,分享会使用原默认参数
164
+ Promise.race([
165
+ originResult,
166
+ new Promise((resolve) => {
167
+ setTimeout(() => {
168
+ resolve({});
169
+ }, 3000);
170
+ })
171
+ ])
172
+ .then(handlePromiseResult)
173
+ .catch((error) => consoleText(error, 'error'));
154
174
  }
155
- const argsArray = Array.prototype.slice.call(args);
156
- if (result) {
157
- argsArray.push(result);
175
+
176
+ // 处理返回值中包含promise属性的情况
177
+ if (hasPromiseProperty) {
178
+ // 如果三秒内不resolve结果,分享会使用原默认参数
179
+ Promise.race([
180
+ originResult.promise,
181
+ new Promise((resolve) => {
182
+ setTimeout(() => {
183
+ resolve({});
184
+ }, 3000);
185
+ })
186
+ ])
187
+ .then(handlePromiseResult)
188
+ .catch((error) => consoleText(error, 'error'));
158
189
  }
159
- // 执行effects
160
- self[`def${cType}Cbs`][eventName].apply(this, argsArray);
161
- } catch (error) {
162
- consoleText(error, 'error');
163
- }
164
- // 执行分享之外的生命周期函数
165
- if (!self.shareEventTypes.includes(eventName)) {
166
- result = method.apply(this, args);
190
+
191
+ // 处理支付宝特有的promise
192
+ if (isSpecialPromise) {
193
+ self.growingIO.minipInstance?.handleSharePromise(
194
+ originResult,
195
+ handlePromiseResult
196
+ );
197
+ }
198
+
199
+ // 直接返回原分享结果继续执行原逻辑
200
+ result = self.currentPage.updateShareResult(originResult, false);
201
+ } else {
202
+ // 没有异步逻辑,直接更新分享内容执行回调
203
+ result = self.currentPage.updateShareResult(originResult);
204
+ self.lifeFcEffectsFn(this, args, cType, eventName, result);
167
205
  }
168
- self.growingIO.emitter.emit(EMIT_MSG.MINIP_LIFECYCLE, {
169
- event: `${cType} ${eventName}End`,
170
- timestamp: Date.now(),
171
- params: { instance: this, arguments: Array.from(args) }
172
- });
173
- return result;
174
- };
175
- }
206
+ } else {
207
+ // 其他生命周期事件:先执行回调,再执行原方法
208
+ self.lifeFcEffectsFn(this, args, cType, eventName);
209
+ result = method.apply(this, args);
210
+ }
211
+
212
+ return result;
213
+ };
176
214
  };
177
215
 
178
- // 自定义方法effects
216
+ /*
217
+ * 自定义方法effects
218
+ */
179
219
  customFcEffects = (eventName: string, method: any) => {
180
220
  const self = this;
181
221
  return function (...args) {
@@ -1,12 +1,4 @@
1
- import {
2
- compact,
3
- has,
4
- head,
5
- isEmpty,
6
- keys,
7
- last,
8
- unset
9
- } from '@@/utils/glodash';
1
+ import { compact, has, isEmpty, keys, last, unset } from '@@/utils/glodash';
10
2
  import { GrowingIOType } from '@@/types/growingIO';
11
3
  import { MinipPageType, PageShareResult } from '@@/types/eventHooks';
12
4
  import {
@@ -23,7 +15,7 @@ import { EVENT } from '@@/types/base';
23
15
 
24
16
  class MinipPage implements MinipPageType {
25
17
  // 根据页面存储的页面参数
26
- public queryOption: any;
18
+ public queryOptions: any;
27
19
  // 通过调用wx.setNavigationBarTitle设置的title
28
20
  public configuredTitle: any;
29
21
  // 页面级属性
@@ -36,12 +28,16 @@ class MinipPage implements MinipPageType {
36
28
  public lifeBeforeShow = true;
37
29
 
38
30
  constructor(public growingIO: GrowingIOType) {
39
- this.queryOption = {};
31
+ this.queryOptions = {};
40
32
  this.configuredTitle = {};
41
33
  this.pageProps = {};
42
34
  }
43
35
 
44
- // 获取页面地址
36
+ /**
37
+ * 获取当前页面路径
38
+ * 优先级:页面堆栈路径 > 启动参数路径 > 最近 page 事件路径 > 最近 visit 事件路径
39
+ * 插件环境下无页面时返回插件 appId
40
+ */
45
41
  getPagePath = () => {
46
42
  const { minipInstance, inPlugin, dataStore, trackingId } = this.growingIO;
47
43
  const path = minipInstance.getCurrentPath();
@@ -61,7 +57,10 @@ class MinipPage implements MinipPageType {
61
57
  }
62
58
  };
63
59
 
64
- // 获取页面参数
60
+ /**
61
+ * 获取当前页面参数(query)
62
+ * 优先级:页面堆栈参数 > 生命周期参数 > 启动参数 > 最近 page 事件参数 > 最近 visit 事件参数
63
+ */
65
64
  getPageQuery = () => {
66
65
  const { minipInstance, dataStore, trackingId } = this.growingIO;
67
66
  const stackPage = minipInstance.getCurrentPage();
@@ -71,13 +70,13 @@ class MinipPage implements MinipPageType {
71
70
  const pageParams = stackPage.options ?? stackPage.$taroParams;
72
71
  // 堆栈中有页面信息,则使用堆栈中的页面参数
73
72
  if (!isEmpty(pageParams)) {
74
- // 删掉taro框架中自带的字段
75
- unset(pageParams, '$taroTimestamp');
76
- // 有页面解析的option直接取
73
+ // 删掉 taro 框架中自带的字段,删除圈选可能带进来的参数
74
+ unset(pageParams, ['$taroTimestamp', 'gdpCircleRoomCollectUrl']);
75
+ // 有页面解析的 option 直接取
77
76
  return this.qsQuery(pageParams);
78
- } else if (!isEmpty(this.queryOption[stackPath])) {
79
- // 没有option从hook获取的生命周期参数中取
80
- return this.qsQuery(this.queryOption[stackPath]);
77
+ } else if (!isEmpty(this.queryOptions[stackPath])) {
78
+ // 没有 option 从 hook 获取的生命周期参数中取
79
+ return this.qsQuery(this.queryOptions[stackPath]);
81
80
  } else if (stackPath === enterParams.path) {
82
81
  // 某些小程序虽然有页面堆栈,但是页面还没加载完,兜底取启动参数
83
82
  return this.qsQuery(
@@ -93,16 +92,20 @@ class MinipPage implements MinipPageType {
93
92
  getLaunchQuery(enterParams?.query, enterParams?.referrerInfo?.extraData)
94
93
  );
95
94
  } else {
96
- // 作为页面组件时component created生命周期中的埋点会取不到页面堆栈,所以拿最近的一个page事件中的页面信息做兜底
95
+ // 作为页面组件时 component created 生命周期中的埋点会取不到页面堆栈,所以拿最近的一个 page 事件中的页面信息做兜底
97
96
  return dataStore.lastPageEvent[trackingId]?.path
98
97
  ? dataStore.lastPageEvent[trackingId]?.query
99
- : // 没有最近的一个page事件说明在app初始化的生命周期中,有些框架可能会有异步处理逻辑导致事件触发比visit晚,则使用visit事件中的页面信息兜底
98
+ : // 没有最近的一个 page 事件说明在 app 初始化的生命周期中,有些框架可能会有异步处理逻辑导致事件触发比 visit 晚,则使用 visit 事件中的页面信息兜底
100
99
  dataStore.lastVisitEvent[trackingId]?.query;
101
100
  }
102
101
  };
103
102
 
104
- // 获取页面标题
105
- // 页面title (优先级:setNavigationBarTitle > data.gioPageTitle[不保证能取到] > config.js中设置的值 > tabBar配置)
103
+ /**
104
+ * 获取页面标题
105
+ * 优先级:setNavigationBarTitle > data.gioPageTitle > config.js 中设置的值 > tabBar 配置
106
+ * 插件环境下无页面时返回插件 appId
107
+ * @param trackingId 可选,追踪 id
108
+ */
106
109
  getPageTitle = (trackingId?: string) => {
107
110
  const { minipInstance, inPlugin, dataStore } = this.growingIO;
108
111
  const path = minipInstance.getCurrentPath();
@@ -122,14 +125,22 @@ class MinipPage implements MinipPageType {
122
125
  }
123
126
  };
124
127
 
125
- // 格式化页面参数
128
+ /**
129
+ * 格式化页面参数为 query string
130
+ * 会去除 wxShoppingListScene 字段
131
+ * @param query 页面参数对象
132
+ */
126
133
  qsQuery = (query = {}) => {
127
134
  const slimQuery = { ...query };
128
135
  unset(slimQuery, 'wxShoppingListScene');
129
136
  return qsStringify(slimQuery);
130
137
  };
131
138
 
132
- // 获取页面来源
139
+ /**
140
+ * 获取页面来源(referrer)
141
+ * 优先级:最近 page 事件路径 > 启动参数 referrerInfo.appId > scene 场景值
142
+ * @param trackingId 追踪 id
143
+ */
133
144
  getReferralPage = (trackingId: string) => {
134
145
  const {
135
146
  minipInstance,
@@ -142,69 +153,68 @@ class MinipPage implements MinipPageType {
142
153
  );
143
154
  };
144
155
 
145
- // 处理分享参数
146
- buildShareQuery(
147
- result: PageShareResult // 客户自定义的参数
148
- ): [string, string] {
149
- // 自定义path的地址参数截取(onShareAppMessage中的页面参数是拼在地址中的)
156
+ /**
157
+ * 处理分享参数,生成分享用的 path 和 query
158
+ * 优先级:result.query > result.path > 当前页面参数(去除 utm_ 开头参数)
159
+ * @param result PageShareResult 客户自定义的参数
160
+ * @returns [path, queryString]
161
+ */
162
+ buildShareQuery(result: PageShareResult): [string, string] {
163
+ // 自定义 path 的地址参数截取(onShareAppMessage 中的页面参数是拼在地址中的)
150
164
  const customSplit = splitPath(result.path ?? '');
151
165
 
152
- let path = this.getPagePath();
166
+ let path = result.path || this.getPagePath();
153
167
  let parsedQuery: any = {};
154
168
  let resultHasPath = has(result, 'path');
155
- // 优先使用自定义的地址
156
- if (resultHasPath) {
157
- path = head(customSplit);
169
+ let resultHasQuery = has(result, 'query');
170
+ // 如果定义了 query 字段则优先取 query 参数
171
+ if (resultHasQuery) {
172
+ parsedQuery = qsParse(result.query ?? '') || {};
173
+ } else if (resultHasPath) {
174
+ // 没有定义 query 字段则尝试取 path 中的参数
158
175
  parsedQuery = qsParse(last(customSplit)) || {};
159
- }
176
+ } else {
177
+ // 只有在没有自定义 path 和 query 的情况下,才使用页面堆栈中的默认参数并删除 utm 参数
178
+ const stackPage = this.growingIO.minipInstance.getCurrentPage();
179
+ // 这里不要直接用对象赋值,下面的 unset 会修改原对象,导致触发一次分享以后当前页面事件中的 utm 参数就会被删除掉
180
+ parsedQuery = {
181
+ ...(stackPage.options || this.queryOptions[stackPage.route] || {})
182
+ };
160
183
 
161
- // 自定义path中没有截取到query说明是在onShareAppMessage中没有参数,或是在onShareTimeline中需要取自定义query
162
- if (isEmpty(parsedQuery)) {
163
- parsedQuery = qsParse(result.query ?? '') || {};
184
+ // 删除 utm_ 参数
164
185
  compact(keys(parsedQuery)).forEach((key) => {
165
- // 删除从默认页面的query中原有的utm参数,防止带入到下一次分享导致渠道统计错误(如果客户质疑参数被删,让他们自己拼回去或者关followShare)
166
186
  if (key.toLowerCase().startsWith('utm_')) {
167
187
  unset(parsedQuery, key);
168
188
  }
169
189
  });
170
190
  }
171
191
 
172
- // 以上两种都是自定义的地址和参数,不做处理直接用,防止出现encode/decode的问题。
173
-
174
- // 自定义query没有值则使用当前页面默认参数
175
- // 如果path存在,但是不携带参数,此时不使用当前页面的默认参数
176
- if (!resultHasPath && isEmpty(parsedQuery)) {
177
- const stackPage = this.growingIO.minipInstance.getCurrentPage();
178
- parsedQuery =
179
- stackPage.options || this.queryOption[stackPage.route] || {};
180
- }
181
-
182
192
  return [path, qsStringify(parsedQuery)];
183
193
  }
184
194
 
185
- // 更新分享结果
186
- updateShareResult = (result: PageShareResult) => {
195
+ /**
196
+ * 更新分享结果,补全参数
197
+ * @param result PageShareResult 分享参数对象
198
+ * @param fillParams 是否补全参数,默认 true
199
+ * @returns 更新后的 result
200
+ */
201
+ updateShareResult = (result: PageShareResult, fillParams = true) => {
187
202
  const [path, queryString] = this.buildShareQuery(result);
188
- result.path = normalPath(path + (queryString ? `?${queryString}` : ''));
189
- result.query = queryString;
190
- return result;
191
- };
192
-
193
- // 更新分享转发事件的结果
194
- updateAppMessageResult = this.updateShareResult;
195
-
196
- // 更新分享朋友圈结果
197
- updateTimelineResult = this.updateShareResult;
198
-
199
- // 更新收藏结果
200
- updateAddFavoritesResult = (result: PageShareResult) => {
201
- const [path, queryString] = this.buildShareQuery(result);
202
- result.path = normalPath(path + (queryString ? `?${queryString}` : ''));
203
- result.query = queryString;
203
+ if (fillParams || has(result, 'path')) {
204
+ result.path = normalPath(path + (queryString ? `?${queryString}` : ''));
205
+ }
206
+ if (fillParams || has(result, 'query')) {
207
+ result.query = queryString;
208
+ }
204
209
  return result;
205
210
  };
206
211
 
207
- // 给事件合并页面属性
212
+ /**
213
+ * 给事件合并页面属性
214
+ * @param trackingId 追踪 id
215
+ * @param event 事件对象
216
+ * @returns 合并后的属性对象
217
+ */
208
218
  eventSetPageProps = (trackingId: string, event: EVENT) => {
209
219
  const pageProps = niceTry(
210
220
  () => this.pageProps[trackingId][this.getPagePath()]
@@ -67,7 +67,7 @@ class PageEffects {
67
67
  switch (event) {
68
68
  case pageListeners.pageLoad: {
69
69
  // 获取一次页面参数存起来,防止类似支付宝小程序只能通过生命周期获取页面参数或页面堆栈拿不到页面参数,做兜底
70
- currentPage.queryOption[path] =
70
+ currentPage.queryOptions[path] =
71
71
  get(page, 'options') ||
72
72
  get(page, '__displayReporter.query') ||
73
73
  get(page, '$page.query') ||
@@ -75,7 +75,10 @@ class PageEffects {
75
75
  get(page, '$taroParams') ||
76
76
  args[0] ||
77
77
  {};
78
- unset(currentPage.queryOption[path], '$taroTimestamp');
78
+ unset(currentPage.queryOptions[path], [
79
+ '$taroTimestamp',
80
+ 'gdpCircleRoomCollectUrl'
81
+ ]);
79
82
  break;
80
83
  }
81
84
  case pageListeners.pageShow: {
@@ -114,6 +117,9 @@ class PageEffects {
114
117
  break;
115
118
  }
116
119
  case pageListeners.shareTime: {
120
+ if (minipInstance.platform === 'xhsp') {
121
+ toggleShareOut(true);
122
+ }
117
123
  trackersExecute((trackingId: string) => {
118
124
  const { followShare } = getTrackerVds(trackingId);
119
125
  if (followShare) {
@@ -582,7 +582,7 @@ class DataStore implements DataStoreType {
582
582
  };
583
583
  event.attributes = limitObject({
584
584
  ...(event.attributes ?? {}),
585
- $from: originResult.from,
585
+ $from: originResult?.from,
586
586
  $target: originResult?.target?.id,
587
587
  $share_title: updateResult?.title,
588
588
  $share_path: head(uri),
@@ -1,4 +1,4 @@
1
- import { compareVersion } from '@@/utils/tools';
1
+ import { compareVersion, consoleText } from '@@/utils/tools';
2
2
  import { GrowingIOType } from '@@/types/growingIO';
3
3
  import { isFunction } from '@@/utils/glodash';
4
4
  import BaseImplements from './base';
@@ -93,6 +93,39 @@ class Alipay extends BaseImplements {
93
93
  }
94
94
  return requestTask;
95
95
  };
96
+
97
+ // 执行支付宝特有的promise分享
98
+ handleSharePromise = (originResult, handlePromiseResult) => {
99
+ // 创建监听_result变化的Promise
100
+ const alipayPromise = new Promise((resolve) => {
101
+ // 如果已有_result直接返回
102
+ if (originResult._result) {
103
+ resolve(originResult._result);
104
+ return;
105
+ }
106
+ // 监听_result属性变化
107
+ Object.defineProperty(originResult, '_result', {
108
+ set(value) {
109
+ this.__result = value;
110
+ resolve(value);
111
+ },
112
+ get() {
113
+ return this.__result;
114
+ }
115
+ });
116
+ });
117
+ // 如果三秒内不resolve结果,分享会使用原默认参数
118
+ Promise.race([
119
+ alipayPromise,
120
+ new Promise((resolve) => {
121
+ setTimeout(() => {
122
+ resolve(originResult._result || {});
123
+ }, 3000);
124
+ })
125
+ ])
126
+ .then(handlePromiseResult)
127
+ .catch((error) => consoleText(error, 'error'));
128
+ };
96
129
  }
97
130
 
98
131
  export default Alipay;
@@ -23,7 +23,7 @@ const Config: PlatformConfigType = {
23
23
  'onReachBottom', // 实际sdk不会执行,但需要写在hook里,防止被归为自定义事件
24
24
  'onResize' // 实际sdk不会执行,但需要写在hook里,防止被归为自定义事件
25
25
  ],
26
- shareEventTypes: ['onShareAppMessage'],
26
+ shareEventTypes: ['onShareAppMessage', 'onShareTimeline', 'onAddToFavorites'],
27
27
  actionEventTypes: [
28
28
  'onclick',
29
29
  'tap',
@@ -1,5 +1,6 @@
1
1
  import { niceTry, getPlainPlatform } from '@@/utils/tools';
2
2
 
3
+ import XHSConfig from './xhs';
3
4
  import JDConfig from './jd';
4
5
  import KSConfig from './ks';
5
6
  import MyConfig from './my';
@@ -12,6 +13,7 @@ import WXConfig from './wx';
12
13
  const plainPlatform = getPlainPlatform();
13
14
  const FrameworkConfig = niceTry(() => {
14
15
  const INST = {
16
+ xhs: XHSConfig,
15
17
  jd: JDConfig,
16
18
  ks: KSConfig,
17
19
  my: MyConfig,
@@ -6,6 +6,7 @@ const MyConfig = {
6
6
  name: 'Alipay',
7
7
  platform: 'alip',
8
8
  scnPrefix: 'alip_',
9
+ shareEventTypes: ['onShareAppMessage'],
9
10
  hooks: {
10
11
  ...BaseConfig?.hooks,
11
12
  Behavior: false
@@ -2,12 +2,19 @@ import BaseConfig from './base';
2
2
 
3
3
  const XHSConfig = {
4
4
  ...BaseConfig,
5
- pageHandlers: [...BaseConfig.pageHandlers, 'onShareChat', 'onCopyUrl'],
6
- shareEventTypes: ['onShareAppMessage', 'onShareChat'],
5
+ pageHandlers: [
6
+ ...BaseConfig.pageHandlers,
7
+ 'onShareChat',
8
+ 'onCopyUrl',
9
+ 'onShareAppMessage',
10
+ 'onShareTimeline'
11
+ ],
12
+ shareEventTypes: [...BaseConfig.shareEventTypes, 'onShareChat', 'onCopyUrl'],
7
13
  listeners: {
8
14
  ...BaseConfig.listeners,
9
15
  page: {
10
16
  ...BaseConfig.listeners.page,
17
+ shareTime: 'onShareTimeline',
11
18
  shareChat: 'onShareChat',
12
19
  copyUrl: 'onCopyUrl'
13
20
  }
@@ -203,7 +203,9 @@ class GioEventAutoTracking {
203
203
  // 初始化圈选
204
204
  circleInit = (params: any) => {
205
205
  const { emitter } = this.growingIO;
206
- const extraData = getExtraData(params.referrerInfo?.extraData);
206
+ const extraData = getExtraData(
207
+ params.referrerInfo?.extraData || params.query || {}
208
+ );
207
209
  // 额外参数中存在gdpCircleRoomCollectUrl,则表示是圈选的跳转,进入圈选状态
208
210
  if (extraData?.gdpCircleRoomCollectUrl) {
209
211
  // 圈选初始化
@@ -108,7 +108,9 @@ class GioImpressionTracking {
108
108
  ? toString(hashCode(collectTarget.route)) // swan page
109
109
  : collectTarget.__nodeId__; // swan component
110
110
  case 'xhs':
111
- return collectTarget.pageId;
111
+ return collectTarget.route
112
+ ? collectTarget.pageId // xhs page
113
+ : collectTarget.componentId; // xhs component
112
114
  default:
113
115
  break;
114
116
  }
@@ -119,9 +121,10 @@ class GioImpressionTracking {
119
121
  const { gioPlatform } = this.growingIO;
120
122
  if (
121
123
  (gioPlatform === 'tt' && collectTarget.__nodeId__) ||
122
- (gioPlatform === 'ks' && collectTarget.is)
124
+ (gioPlatform === 'ks' && collectTarget.is) ||
125
+ (gioPlatform === 'xhs' && collectTarget.componentId)
123
126
  ) {
124
- // 字节和快手小程序页面监听时可以拿到自定义组件一次性完成监听,所以组件的节点实例不再处理
127
+ // 字节/快手/小红书小程序页面监听时可以拿到自定义组件一次性完成监听,所以组件的节点实例不再处理
125
128
  return false;
126
129
  }
127
130
  const nodeId = this.getNodeId(collectTarget);
@@ -76,7 +76,7 @@ export interface PageShareResult {
76
76
  }
77
77
 
78
78
  export interface MinipPageType {
79
- queryOption: any;
79
+ queryOptions: any;
80
80
  configuredTitle: any;
81
81
  pageProps: any;
82
82
  lastLifecycle: string;
@@ -88,9 +88,10 @@ export interface MinipPageType {
88
88
  qsQuery: (query: any) => string;
89
89
  getReferralPage: (trackingId: string) => string;
90
90
  buildShareQuery: (result: PageShareResult) => [string, string];
91
- updateAppMessageResult: (result: PageShareResult) => PageShareResult;
92
- updateTimelineResult: (result: PageShareResult) => PageShareResult;
93
- updateAddFavoritesResult: (result: PageShareResult) => PageShareResult;
91
+ updateShareResult: (
92
+ result: PageShareResult,
93
+ fillParams?: boolean
94
+ ) => PageShareResult;
94
95
  eventSetPageProps: (trackingId: string, event: EVENT) => any;
95
96
  }
96
97