web建站教程
  1. 首页
  2. vuejs
  3. js
  4. 好玩
  5. seo教程
  6. 前端知识
  7. 百度echarts
  8. 更多
    php入门
    nodejs
    mockjs
    reactjs
    mysql
    wordpress
    织梦cms
    帝国cms
    git教程
    IT知识
    模板大全
    休息站

用vuejs实现浙里办埋点注意事项及全部代码案例

584 ℃
     

用vuejs实现浙里办埋点注意事项及全部代码案例,注意所有埋点都要写到index.html中,写到其它的vuejs中无效。

//获取链接参数
function getQueryString(name) {
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
	var r = window.location.search.substr(1).match(reg);
	if (r != null) return decodeURI(r[2]);
	return null;
}
//判断是否有票据ticket
const _t = getQueryString("ticket");
if (!localStorage.getItem("ZLB_TICKET")) {
	if (!_t) {
		localStorage.setItem("INIT_LINK", window.location.href);
		window.location.href =
			"https://puser.zjzwfw.gov.cn/sso/mobile.do?action=oauth&scope=1&servicecode=业务代码&goto=https://mapi.zjzwfw.gov.cn/web/mgop/gov-open/zj/2001832594/1.3.7/index&debug=true";
	} else {
		localStorage.setItem("ZLB_TICKET", _t);
	}
}
//原生js-ajax方法
function ajax() {  
	var ajaxData = {    
		type: arguments[0].type || "GET",
		    url: arguments[0].url || "",
		    async: arguments[0].async || "true",
		    data: arguments[0].data || null,
		    dataType: arguments[0].dataType || "text",
		    contentType: arguments[0].contentType || "application/x-www-form-urlencoded",
		    beforeSend: arguments[0].beforeSend || function() {},
		    success: arguments[0].success || function() {},
		    error: arguments[0].error || function() {}  
	}  
	ajaxData.beforeSend()
	var xhr = createxmlHttpRequest();   
	xhr.responseType = ajaxData.dataType;  
	xhr.open(ajaxData.type, ajaxData.url, ajaxData.async);   
	xhr.setRequestHeader("Content-Type", ajaxData.contentType);
	xhr.setRequestHeader("ticket", localStorage.getItem("ZLB_TICKET")); 
	xhr.send(convertData(ajaxData.data));   
	xhr.onreadystatechange = function() {     
		if (xhr.readyState == 4) {       
			if (xhr.status == 200) {        
				ajaxData.success(xhr.response)      
			} else {        
				ajaxData.error()      
			}     
		}  
	} 
}  
function createxmlHttpRequest() {   
	if (window.ActiveXObject) {     
		return new ActiveXObject("Microsoft.XMLHTTP");   
	} else if (window.XMLHttpRequest) {     
		return new XMLHttpRequest();   
	} 
}  
function convertData(data) {
	if (typeof data === 'object') {    
		var convertResult = "";     
		for (var c in data) {       
			convertResult += c + "=" + data[c] + "&";     
		}     
		convertResult = convertResult.substring(0, convertResult.length - 1)
		return convertResult;  
	} else {    
		return data;  
	}
}
//获取token接口
function getTokenByToken() {
	ajax({
		type: "get",
		url: "接口链接",
		dataType: "json",
		data: {

		},
		beforeSend: function() {

		},
		success: function(res) {
			console.log('res', res)
			if (res && res.code == 10000) {
				localStorage.setItem("ZLB_TOKEN", res.content.token);
				// 埋点
				(function(w, d, s, q, i) {
					w[q] = w[q] || [];
					var f = d.getElementsByTagName(s)[0];
					var j = d.createElement(s);
					j.async = true;
					j.id = "beacon-aplus";
					j.src = "https://d.alicdn.com/alilog/mlog/aplus.js?id=202951085";
					f.parentNode.insertBefore(j, f);
				})(window, document, "script", "aplus_queue");
				aplus_queue.push({
					action: "aplus.setMetaInfo",
					arguments: ["aplus-rhost-v", "alog.zjzwfw.gov.cn"]
				});
				aplus_queue.push({
					action: "aplus.setMetaInfo",
					arguments: ["aplus-rhost-g", "alog.zjzwfw.gov.cn"]
				});
				aplus_queue.push({
					action: "aplus.setMetaInfo",
					arguments: ["appId", "60506758"]
				});
				aplus_queue.push({
					action: "aplus.setMetaInfo",
					arguments: ["_user_id", res.content.userId]
				});
				aplus_queue.push({
					action: "aplus.setMetaInfo",
					arguments: ["_user_nick", res.content.userName]
				});
			} else if (res && res.code == 403) {
				// Message.warning({ message: response.data.message });
				window.location.replace(localStorage.getItem("INIT_LINK"));
			} else {
				console.log(res.message)
			}
		},
		error: function() {
			console.log("error")
		}
	})
}

浙里办小程序window.open失效解决方法(ios系统)

浙里办获取PV日志参数埋点

浙里办调用ZWJSBridge方法须知

浙里办二次回退已解决,兼容支付宝小程序和浙里办app

浙里办项目中如何获取经纬度、城市区域、当前地址等相关信息

标签: 埋点, 浙里办

上面是“用vuejs实现浙里办埋点注意事项及全部代码案例”的全面内容,想了解更多关于 vuejs 内容,请继续关注web建站教程。

当前网址:https://ipkd.cn/webs_1429.html

声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

当前位置: 网站首页 > vuejs
本文共计3187个字,预计阅读时长22分钟
生活小工具,收录了80多款小工具
上一篇: 推荐一个可以查询老黄历的网站,可以根据五行取名!
下一篇: 详细介绍HTTP状态码不同之处的原因(什么原因导致的)
x 打工人ai神器