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

用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")
		}
	})
}
以上是编程学习网小编为您介绍的“用vuejs实现浙里办埋点注意事项及全部代码案例”的全面内容,想了解更多关于 vuejs 内容,请继续关注编程基础学习网。

本文标题为:用vuejs实现浙里办埋点注意事项及全部代码案例

基础教程推荐