cml init project
cd path-to-project
npm install umtrack-alipay --save
npm install umtrack-wx --save
参考cml的接口多态功能 可以通过终端命令创建该文件,选择Polymorphic function,输入文件名称uma
cml init component
# 选择 ,选择Polymorphic function ,输入uma
*** src/components/uma/uma.interface***
<script cml-type="interface">
interface UmaInterface {
uma:object;
}
</script>
<script cml-type="wx">
import uma from 'umtrack-wx';
class Method implements UmaInterface {
uma = uma ;
constructor(){
this.uma.init({
appKey: 'YOUR_APP_KEY',
useOpenid: false,
autoGetOpenid: false,
debug: true
});
}
}
export default new Method().uma;
</script>
<script cml-type="alipay">
import uma from 'umtrack-alipay';
class Method implements UmaInterface {
uma = uma ;
constructor(){
this.uma.init({
appKey: 'YOUR_APP_KEY',
debug: true
});
}
}
export default new Method().uma;
</script>
在app.cml的第一行脚本注入uma模块 /src/app/app.cml
<script>
import uma from '/components/uma/uma.interface';
</script>
调用uma模块: 在其他页面中直接 import uma from '/components/uma/uma.interface'
/src/pages/index/index.cml
<script>
import uma from '/components/uma/uma.interface';
</script>
*** /src/pages/index/index.cml ***
uma.trackEvent('buy', {
name: 'car'
})