Skip to content

Commit

Permalink
Release 0.0.9
Browse files Browse the repository at this point in the history
  • Loading branch information
weiqiangliu committed Jul 10, 2023
1 parent 1ef87bc commit b43b9af
Show file tree
Hide file tree
Showing 8 changed files with 162 additions and 14 deletions.
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ import bridgeAPI from './middle/baidu.js';
import bridgeAPI from './middle/toutiao.js';
// #endif

import get_enableVue3MpClick from './vue3-mpclick';

let sa = {};

let lib_plugin_track_timer = 0;
let js_uniapp_version = 'js_uniapp:0.0.8';
let js_uniapp_version = 'js_uniapp:0.0.9';

//检查是否是支持的平台,如果不支持就使用commonAPI
if (typeof bridgeAPI === 'undefined') {
Expand Down Expand Up @@ -81,5 +82,7 @@ if (typeof bridgeAPI === 'undefined') {

}

const enableVue3MpClick = get_enableVue3MpClick(sa);

export default sa;
export { enableVue3MpClick };
8 changes: 8 additions & 0 deletions middle/alipay.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// 原生SDK提供的API
import sensors from '../jssdk/alipay.js';

var _ = sensors._;
// 提供各端一致的公共API
var isParaSet = false;
let sa = {
Expand All @@ -12,6 +13,9 @@ let sa = {
sa.setPara(para);
}
sensors.init(para);
if (para && _.isObject(para.global_properties)) {
sensors.registerApp(para.global_properties);
}
},
setPara: (para) => {
para = para || {};
Expand All @@ -20,6 +24,10 @@ let sa = {
};
Object.assign(defaultValue, para);
sensors.setPara.call(sensors, defaultValue);

if (para && _.isObject(para.global_properties)) {
sensors.registerApp(para.global_properties);
}
isParaSet = true;
},
// 各端通用的常用API
Expand Down
9 changes: 9 additions & 0 deletions middle/baidu.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// 原生SDK提供的API
import sensors from '../jssdk/baidu.js';

var _ = sensors._;
// 提供各端一致的公共API
var isParaSet = false;
let sa = {
Expand All @@ -12,6 +13,9 @@ let sa = {
sa.setPara(para);
}
sensors.init(para);
if (para && _.isObject(para.global_properties)) {
sensors.registerApp(para.global_properties);
}
},
setPara: (para) => {
para = para || {};
Expand All @@ -20,6 +24,11 @@ let sa = {
};
Object.assign(defaultValue, para);
sensors.setPara.call(sensors, defaultValue);

if (para && _.isObject(para.global_properties)) {
sensors.registerApp(para.global_properties);
}

isParaSet = true;
},
// 各端通用的常用API
Expand Down
9 changes: 9 additions & 0 deletions middle/toutiao.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// 原生SDK提供的API
import sensors from '../jssdk/toutiao.js';

var _ = sensors._;
// 提供各端一致的公共API
var isParaSet = false;
let sa = {
Expand All @@ -12,6 +13,9 @@ let sa = {
sa.setPara(para);
}
sensors.init(para);
if (para && _.isObject(para.global_properties)) {
sensors.registerApp(para.global_properties);
}
},
setPara: (para) => {
para = para || {};
Expand All @@ -20,6 +24,11 @@ let sa = {
};
Object.assign(defaultValue, para);
sensors.setPara.call(sensors, defaultValue);

if (para && _.isObject(para.global_properties)) {
sensors.registerApp(para.global_properties);
}

isParaSet = true;
},
// 各端通用的常用API
Expand Down
25 changes: 15 additions & 10 deletions middle/web.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,19 @@ let sa = {
};
Object.assign(defaultValue, para);
sensors.init.call(sensors, defaultValue);

var _ = sensors._;
if (para && _.isObject(para.global_properties)) {
sensors.registerPage(para.global_properties);
}
},
//弹窗初始化
popupInit: (para) => {
if (typeof para === "object" && para !== null) {
if(systemInfo.screenWidth > 1024) {
if (systemInfo.screenWidth > 1024) {
sensors.use('WebPopup', para);
popups = webPopups;
}else {
} else {
sensors.use('Popup', para);
}
}
Expand All @@ -45,33 +50,33 @@ let sa = {
clearRegister: () => {
console.log('web 中不支持此方法 - clearRegister');
},
quick:(event,para) => {
sensors.quick(event,para);
quick: (event, para) => {
sensors.quick(event, para);
},
popupLoadSuccess: (callback) => {
if(popups.info.supportCustom && popups.info.supportCustom === 'withoutCampaignListener') {
if (popups.info.supportCustom && popups.info.supportCustom === 'withoutCampaignListener') {
popups.info.supportCustom = '';
};
if(popups.info && popups.info.popup_campaign_listener) {
if (popups.info && popups.info.popup_campaign_listener) {
popups.info.popup_campaign_listener.onStart = callback;
};
},
popupClose: (callback) => {
if(popups.info && popups.info.popup_campaign_listener) {
if (popups.info && popups.info.popup_campaign_listener) {
popups.info.popup_campaign_listener.onEnd = callback;
};
},
popupClick: (callback) => {
if(systemInfo.screenWidth <= 1024) {
if(popups.info && popups.info.popup_listener) {
if (systemInfo.screenWidth <= 1024) {
if (popups.info && popups.info.popup_listener) {
popups.info.popup_listener.onClick = callback;
};
} else {
console.log('web 中不支持此方法 - popupClick 方法');
}
},
popupLoadFailed: (callback) => {
if(popups.info && popups.info.popup_campaign_listener) {
if (popups.info && popups.info.popup_campaign_listener) {
popups.info.popup_campaign_listener.onFailed = callback;
};
}
Expand Down
10 changes: 10 additions & 0 deletions middle/weixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import sensors from '../jssdk/weixin.js';
import popups from '../plugin/wx-popup.esm.min';

var isParaSet = false;
var _ = sensors._;
// 提供各端一致的公共API
let sa = {
// 提供扩展性
Expand All @@ -13,6 +14,10 @@ let sa = {
sa.setPara(para);
}
sensors.init(para);

if (para && _.isObject(para.global_properties)) {
sensors.registerApp(para.global_properties);
}
},
//弹窗初始化
popupInit: (para) => {
Expand All @@ -27,6 +32,11 @@ let sa = {
};
Object.assign(defaultValue, para);
sensors.setPara.call(sensors, defaultValue);

if (para && _.isObject(para.global_properties)) {
sensors.registerApp(para.global_properties);
}

isParaSet = true;
},
// 各端通用的常用API
Expand Down
8 changes: 5 additions & 3 deletions uni-app-js.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

#### 本插件适用于 H5、APP、微信小程序、阿里小程序、百度小程序和头条小程序进行数据采集。

注:APP 需集成 Native 端插件,否则无法进行 APP 端数据采集,具体集成可参考 [神策 uni-app 原生插件](https://ext.dcloud.net.cn/plugin?id=4179)
注:
1. VUE3 开发环境下不支持 $MPClick 全埋点事件
2. APP 需集成 Native 端插件,否则无法进行 APP 端数据采集,具体集成可参考 [神策 uni-app 原生插件](https://ext.dcloud.net.cn/plugin?id=4179)

## 2. 使用方式

Expand All @@ -27,7 +29,7 @@ App中设置:
appHide: true, // 默认为 true,false 则关闭 $MPHide 事件采集
pageShow: true, // 默认为 true,false 则关闭 $MPViewScreen 事件采集
pageShare: true, // 默认为 true,false 则关闭 $MPShare 事件采集
mpClick: false, // 默认为 false,true 则开启 $MPClick 事件采集
mpClick: false, // 默认为 false,true 则开启 $MPClick 事件采集, VUE3 不支持
mpFavorite: true, // 默认为 true,false 则关闭 $MPAddFavorites 事件采集
pageLeave: false // 默认为 false, true 则开启 $MPPageLeave事件采集
},
Expand Down Expand Up @@ -101,7 +103,7 @@ App中设置:
appHide: true, // 默认为 true,false 则关闭 $MPHide 事件采集
pageShow: true, // 默认为 true,false 则关闭 $MPViewScreen 事件采集
pageShare: true, // 默认为 true,false 则关闭 $MPShare 事件采集
mpClick: false, // 默认为 false,true 则开启 $MPClick 事件采集
mpClick: false, // 默认为 false,true 则开启 $MPClick 事件采集, VUE3 不支持
mpFavorite: true, // 默认为 true,false 则关闭 $MPAddFavorites 事件采集
pageLeave: false // 默认为 false, true 则开启 $MPPageLeave事件采集
},
Expand Down
102 changes: 102 additions & 0 deletions vue3-mpclick.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
export default function get_enableVue3MpClick(sensors) {
var sa = sensors.instance;

return function enableVue3MpClick() {
// #ifdef VUE3
// #ifdef MP-WEIXIN || MP-ALIPAY || MP-BAIDU || MP-TOUTIAO || MP-JD || MP-KUAISHOU || MP-QQ || MP-LARK
var platform;
// #ifdef MP-WEIXIN
platform = wx
// #endif

// #ifdef MP-BAIDU
platform = swan
// #endif

// #ifdef MP-ALIPAY
platform = my
// #endif

// #ifdef MP-TOUTIAO
platform = tt
// #endif

// #ifdef MP-JD
platform = jd
// #endif

// #ifdef MP-KUAISHOU
platform = ks
// #endif

// #ifdef MP-QQ
platform = qq
// #endif

// #ifdef MP-LARK
platform = tt
// #endif

var oldCreatePage = platform.createPage;
if (oldCreatePage) {
platform.createPage = function (MiniProgramPage) {
var oldRender = MiniProgramPage.render;
MiniProgramPage.render = function (ctx) {
var bindingConfig = oldRender.apply(MiniProgramPage, arguments);
var mpInstance = ctx && ctx.$scope;
if (mpInstance) {
for (let i in bindingConfig) {
var propKey = bindingConfig[i];
if (typeof mpInstance[propKey] === 'function') {
let oldFn = mpInstance[propKey];
if (sa.para.autoTrack && sa.para.autoTrack.mpClick) {
mpInstance[propKey] = function () {
oldFn.apply(mpInstance, arguments);
clickTrack(arguments[0])
}
}
}
}
}
return bindingConfig;
}
oldCreatePage.apply(platform, arguments);
}
}

function clickTrack(events) {
var _ = sa._;
var prop = {};
var event_prop = _.isObject(events.event_prop) ? events.event_prop : {};
var type = events['type'];
var current_target = events.currentTarget || {};
var dataset = current_target.dataset || {};

prop['$element_id'] = current_target.id;
prop['$element_type'] = dataset['type'];
prop['$element_content'] = dataset['content'];
prop['$element_name'] = dataset['name'];
prop['$url_path'] = _.getCurrentPath();

if (type && isClick(type)) {
if (sa.para.preset_events && sa.para.preset_events.collect_element && sa.para.preset_events.collect_element(arguments[0]) === false) {
return false;
}
prop = _.extend(prop, event_prop);
sensors.track('$MPClick', prop);
}
}

function isClick(type) {
var mp_taps = {
tap: 1,
longpress: 1,
longtap: 1
};
return !!mp_taps[type];
}

// #endif
// #endif
}
}

0 comments on commit b43b9af

Please sign in to comment.