# togetu-core

> togetu team js core

Latest version **1.0.4** (published 2019-02-16) · UNLICENSED license · 0 weekly downloads

## Install

```sh
npm install togetu-core
pnpm add togetu-core
yarn add togetu-core
bun add togetu-core
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2019-02-16 |
| First published | 2019-02-15 |
| Weekly downloads | 0 |
| License | UNLICENSED |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 44.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | togetU |
| Maintainers | vigdxx |

## Links

- npm: https://www.npmjs.com/package/togetu-core
- npm.io page: https://npm.io/package/togetu-core

## Dependencies (2)

- [md5](https://npm.io/package/md5.md) ^2.2.1
- [@babel/polyfill](https://npm.io/package/@babel/polyfill.md) ^7.0.0

## Recent versions

- 1.0.4 (latest) — 2019-02-16
- 1.0.3 — 2019-02-16
- 1.0.2 — 2019-02-16
- 1.0.1 — 2019-02-16
- 1.0.0 — 2019-02-15

## README

# togetu 核心 npm 包
  
## js bridge

### 1、支持 promise和callback 2种方式
``` JavaScript
// 例子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、语法糖
``` JavaScript
// 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
<!-- 在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 默认带参
``` javascript
    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)
    }
```

## 使用方式

``` javascript
// 埋点 pv/uv
push_log({}, 'pageview')
// 其它
push_log({})
```

## 唤起 APP

---
_Source: https://npm.io/package/togetu-core · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
