1.0.4 • Published 5 years ago
togetu-core v1.0.4
togetu 核心 npm 包
js bridge
1、支持 promise和callback 2种方式
// 例子1(无参数)
jsBridge("login",{
callback(err,res){
// 业务代码
}
)
jsBridge("login").then((res)=>{}).catch((err)=>{});
// 例子2(带参数)
// 目前
jsBridge('copyToClipborad',{
...
callback(err,res){
}
});
// 建议1
jsBridge("copyToClipborad",{...}).then((res)=>{}).catch((err)=>{});
2、callback模式中 错误信息 统一归纳在第一个参数 err
3、语法糖
// pushWindow
jsBridge("pushWindow",'http://xxxxx.com');
jsBridge("pushWindow",{...});
// jumpWindow
jsBridge("jumpWindow"); //只是后退-1;
// alert
jsBridge("alert","xxxxxxx"); // 默认补全 buttonText
// confirm
jsBridge("confirm","xxxxxxx"); // 默认补全 confirmButtonText,cancelButtonText
// showLoading
jsBridge("showLoading"); // 默认:hasIcon="true" content="" delay=0
jsBridge("showLoading",1000); // 默认:hasIcon="true" content="" 一秒后自动关闭
jsBridge("showLoading",{...});// 完整版
// copyToClipborad
jsBridge("copyToClipborad","xxxxxx");
jsBridge("copyToClipborad",{...}); // 完整版
埋点
<!-- 在HTML中插入以下代码,用于 ga 和 Matomo 埋点统计 -->
<!-- Google Analytics -->
<script>
(function (i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r; i[r] = i[r] || function () {
(i[r].q = i[r].q || []).push(arguments)
}, i[r].l = 1 * new Date(); a = s.createElement(o),
m = s.getElementsByTagName(o)[0]; a.async = 1; a.src = g; m.parentNode.insertBefore(a, m)
})(window, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga');
if (window.location.hostname === 'g.togetu.in') {
ga('create', 'UA-127168940-2', 'auto');
} else {
ga('create', 'UA-127168940-3', 'auto');
}
</script>
<!-- End Google Analytics -->
<!-- Matomo -->
<script type="text/javascript">
window._paq = window._paq || [];
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function () {
var u = "https://togetu.matomo.cloud/";
_paq.push(['setTrackerUrl', u + 'piwik.php']);
_paq.push(['setSiteId', '1']);
var d = document, g = d.createElement('script'), s = d.getElementsByTagName('script')[0];
g.type = 'text/javascript'; g.async = true; g.defer = true; g.src = u + 'piwik.js';s.parentNode.insertBefore(g, s);
})();
</script>
<!-- End Matomo Code -->
集成阿里云sls,ga, Matomo三种埋点 其中sls 和 Matomo 默认带参
this.params = {
currentPage: window.location.href,
UA: navigator.userAgent,
isToGetUApp: !!isToGetUApp,
H5_deviceId: H5_deviceId,
}
if(userInfo) {
this.params.uid = userInfo.tid
}
if(appInfo) {
this.params.app_deviceId = appInfo.deviceId;
this.params.app_version = appInfo.version;
this.params.app_version_name = appInfo.name;
}
if(bridge_userInfo_err) {
this.params = Object.assign(this.params, bridge_userInfo_err)
}
if(bridge_appInfo_err) {
this.params = Object.assign(this.params, bridge_appInfo_err)
}
使用方式
// 埋点 pv/uv
push_log({}, 'pageview')
// 其它
push_log({})