Skip to content

Commit 0c349db

Browse files
authored
Merge pull request #23 from pdap/master
友盟+小程序sdk的跨平台集成最佳实践
2 parents 5b44265 + 520fe31 commit 0c349db

File tree

13 files changed

+7736
-0
lines changed

13 files changed

+7736
-0
lines changed

one-uma/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules/
2+
dist/
3+
yarn-error.log
4+
yarn.lock

one-uma/README.md

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# remaxjs 集成友盟+小程序统计sdk
2+
3+
# 1.注册友盟+账号
4+
[参考官网原生小程序文档](https://developer.umeng.com/docs/147615/detail/147619)
5+
# 2.友盟官网申请小程序appkey
6+
[参考官网原生小程序文档](https://developer.umeng.com/docs/147615/detail/147619)
7+
# 3.域名白名单配置
8+
[官网微信小程序文档](https://developer.umeng.com/docs/147615/detail/147619)
9+
[官网原生支付宝小程序接入](https://developer.umeng.com/docs/147615/detail/147727)
10+
# 4.创建remaxjs框架下的app
11+
[demo_on_github](https://github.com/umeng/mp-demos/tree/master/remaxjs)
12+
如果是旧工程,首先升级remax版本>=v1.19.0
13+
然后在*remax.config.js*开启one: true
14+
15+
```js
16+
module.exports = {
17+
one: true,
18+
output: 'dist/' + process.env.REMAX_PLATFORM
19+
};
20+
```
21+
如果是新工程,直接按照官网方法初始化
22+
```bash
23+
npx degit remaxjs/template-one my-app
24+
cd my-app
25+
```
26+
27+
# 5.安装sdk
28+
29+
```bash
30+
cd path-to-remaxproject
31+
npm install umtrack-alipay --save
32+
npm install umtrack-wx --save
33+
```
34+
# 6.跨平台集成最佳实践
35+
*不能像taro一样动态require [原因参见](https://zhuanlan.zhihu.com/p/52990313)*
36+
本教程使用文件名后缀区分不同平台代码,跟taro多文件跨平台类似,[参考reamx 跨平台介绍](https://remaxjs.org/one/intro)
37+
38+
*src/uma/index.wechat.js* 定义微信小程序环境需要导入的模块并初始化
39+
```js
40+
import uma from 'umtrack-wx';
41+
42+
uma.init({
43+
appKey: 'YOUR_APP_KEY',
44+
useOpenid: false,
45+
autoGetOpenid: false,
46+
debug: true
47+
});
48+
export default uma;
49+
```
50+
*src/uma/index.alipay.js*定义支付宝小程序需要导入的模块并初始化
51+
```js
52+
import uma from 'umtrack-alipay';
53+
54+
uma.init({
55+
appKey: 'YOUR_APP_KEY',
56+
debug: true
57+
});
58+
export default uma;
59+
```
60+
*src/uma/index.js*
61+
```js
62+
export { default } from './index.wechat';
63+
64+
```
65+
*app.js*
66+
67+
```js
68+
import '@/uma';//app.js中 uma模块一定要放在最前头
69+
import './app.css';
70+
71+
const App = props => props.children;
72+
export default App;
73+
74+
```
75+
# 7.自定义事件
76+
*pages/index/index.js*导入uma模块
77+
78+
```js
79+
import { useReady } from 'remax';
80+
import uma from '@/uma';
81+
82+
export default () => {
83+
useReady(()=>{
84+
uma.trackEvent('buy',{car:'bmw'});
85+
});
86+
return 'showtime';
87+
};
88+
```

0 commit comments

Comments
 (0)