uniapp 集成友盟并且上传页面路径

如果不需要上传页面路径可以看看这篇https://blog.csdn.net/2301_78184382/article/details/156606416?spm=1011.2415.3001.5331

项目用的uniapp 框架是vue3目前项目中有个需求是需要统计用户访问地址和停留时间,话不多说上代码

插件地址

https://ext.dcloud.net.cn/plugin?id=12026

友盟https://workbench.umeng.com/去创建app应用

appkey查看位置,管理下面的应用管理的应用列表

在manifest.json中模块配置勾选统计

在manifest.json常用其他设置urlSchemes 这一步是为了调试的时候去看实时数据

新增mixin.js页面

javascript 复制代码
// main.js
import {
	createSSRApp
} from 'vue';
// #ifdef APP-PLUS
const UMStatistic = uni.requireNativePlugin('UM-Statistic');
// #endif
// 定义全局 mixin 对象
export const globalMixin = {
	// 生命周期(UniApp 页面生命周期)
	onLoad() {
		// #ifdef APP-PLUS
		//初始化,勾选友盟统计模块配置文件里面配置了appkey和channel时调用此接口初始化
		UMStatistic.UMinit();
		// #endif
		//appkey和channel初始化,未配置时用此接口初始化
		//UMStatistic.initWithAppkey(appkey, channel);
	},
	onShow() {
		var enable = false;//true:自动采集页面 false:手动采集页面
		console.log('页面显示')
		let pageValue = this.$getPath();
		// #ifdef APP-PLUS
		UMStatistic.setAutoPageEnabled(enable);
		UMStatistic.onPageStart(pageValue);
		// #endif
		console.log('页面显示', pageValue)
	},
	onHide() {
		let pageValue = this.$getPath();
		// #ifdef APP-PLUS
		UMStatistic.onPageEnd(pageValue);
		// #endif
	},
	// 自定义数据
	data() {
		return {
			globalTitle: '全局标题'
		}
	},
	// 全局方法
	methods: {
		// 显示提示
		$toast(title, duration = 2000) {
			uni.showToast({
				title,
				duration,
				icon: 'none'
			})
		},

		// 跳转页面
		$navigate(url) {
			uni.navigateTo({
				url
			})
		},

		// 获取当前页面路径
		$getPath() {
			const pages = getCurrentPages()
			return pages[pages.length - 1]?.route || ''
		}
	}
}

// export function createApp() {
//   const app = createSSRApp(App)

//   // 注册全局 mixin
//   app.mixin(globalMixin)

//   return { app }
// }

在main.js中去引入

javascript 复制代码
import {globalMixin} from '@/common/mixin.js'
export function createApp() {
	const app = createSSRApp(App)
	app.mixin(globalMixin)
	return {
		app,
		Vuex
	}
}

设置完了就需要打自定义基座,删除旧基座去重新运行

安卓文档集成测试

https://developer.umeng.com/docs/119267/detail/118639

ios文档集成测试

https://developer.umeng.com/docs/119267/detail/119520

登录友盟跳转查看实时日志

https://mobile.umeng.com/platform/config/check/realtimelog

相关推荐
天蓝色的鱼鱼1 小时前
关于 CSS 你可能不知道的属性,但关键时刻很有用
前端·css
泯泷2 小时前
第 2 篇:设计第一套字节码:Opcode、Instruction 与 Constant Pool
前端·javascript·安全
妙码生花2 小时前
从 PHP 到 AI + Golang,程序员自救转型手记(十五):优化细节、网络请求封装
前端·后端·ai编程
泯泷2 小时前
第 1 篇:从 1 + 2 开始:亲手写出第一台 JSVM
前端·javascript·安全
团团崽_七分甜2 小时前
Spring Boot 核心知识点总结
前端
lichenyang4532 小时前
从一个按钮开始,理解 ASCF 框架到底在做什么
前端
古夕3 小时前
第三方 SSO 接入实践:redirect_uri 编码、回调一致性与跨项目联调
前端·vue.js
朦胧之3 小时前
页面白屏卡住排查方法
前端·javascript
用户593608741403 小时前
Playwright 黑魔法:用 ClipboardEvent 绕过 React 富文本编辑器
前端
Ruihong3 小时前
Vue withDefaults 转 React:VuReact 怎么处理?
vue.js·react.js·面试