浙⾥办设置埋点代码
说明:
浙⾥办对接有很多坑,其中埋点是必须要做的⼀个环节,埋点就是⽤来获取相关信息⽤的,具体写道代码内埋点成功也是要引⽤相关⽂件脚本和包的具体的⽤处和说明这⾥不赘述,可⾃⾏参考官⽹,这⾥只给出解决坑后成功埋点的代码参考。
埋点应该打印出heander内遗传带有各种信息的字符接⼝,如果没有,就没有成功:因为埋点⽆法线下测
以前版本的埋点信息:不成功
index.html引⼊⽂件:
<script type="text/javascript" src="//d.alicdn/alilog/mlog/aplus.js?id=202951085"></script>
home.vue 调⽤:
mounted() {
/
/ this.isLogin()
this.SetZwaplus() // 埋点?
},
SetZwaplus() {
// 埋点?
;(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 = 'd.alicdn/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', 'v']
})
aplus_queue.push({
action: 'aplus.setMetaInfo',
arguments: ['aplus-rhost-g', 'v']
})
/
/ 这个会落到 app_key 字段上
aplus_queue.push({
action: 'aplus.setMetaInfo',
arguments: ['appId', '60506758']
})
}
login.vue:调⽤埋点:
setZwaplus() {
// excuteBridge()
// itorTrace({
// monitorType: 'success',
/
/ module: 'Login'
// })
// .then(result => {
// console.log(result)
// })
// .catch(error => {
// console.log(error)
// })
// 埋点?
aplus_queue.push({
action: 'aplus.setMetaInfo',
arguments: ['_hold', 'BLOCK']
})
aplus_queue.push({
action: 'aplus.setMetaInfo',
arguments: ['_user_nick', this.userInfoData.username]
})
aplus_queue.push({
action: 'aplus.setMetaInfo',
arguments: ['_user_id', this.userInfoData.userid]
})
aplus_queue.push({
action: 'aplus.setMetaInfo',
arguments: ['_hold', 'START']
})
}
++++++++++++++++++
现改成如下⽅式:
index.html 引⼊⽅式:
<script type="text/javascript" src="d.alicdn/alilog/mlog/aplus.js?id=202951085"></script>
引⼊和使⽤埋点(官⽹提供)更改并都放到home.vue内:
mounted() {
this.isLogin()
this.SetZwaplus() // 埋点?
},
isLogin() {
// 判断⽤户是否登录
var UserId = getLocal('userid')
// console.log(UserId)
if (UserId == '' || UserId == undefined || UserId == null) {
window.location.href =
'v/sso/mobile.do?action=oauth&scope=1&servicecode=dhyswnej'
} else {
this.SetZwUserAplus(UserId) // ⽤户成功登录时
}
},
;(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 = 'd.alicdn/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', 'v']
})
aplus_queue.push({
action: 'aplus.setMetaInfo',
arguments: ['aplus-rhost-g', 'v']
})
// 这个会落到 app_key 字段上
aplus_queue.push({
action: 'aplus.setMetaInfo',
arguments: ['appId', '60506758']
})
// 单页应⽤或 “单个页⾯”需异步补充 PV ⽇志参数还需进⾏如下埋点:
aplus_queue.push({
action: 'aplus.setMetaInfo',
arguments: ['aplus-waiting', 'MAN']
})
// 单页应⽤路由切换后或在异步获取到 pv ⽇志所需的参数后再执⾏ sendPV:
aplus_queue.push({
action: 'aplus.sendPV',
arguments: [
{
is_auto: false
},
{
miniAppId: 'izt8cldk+2001830421+exokfd',
miniAppName: '......之家'
}
]
})
}
全代码参考:
index.html
<!DOCTYPE html>
<html lang="">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<!-- <meta name="viewport" content="width=device-width,initial-scale=1.0"> -->
<meta name="format-detection" content="telephone=yes"/>
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
<!-- 引⼊ZWJSBridge -->
<script type="text/javascript" src="//v/assets/ZWJSBridge/1.0.1/zwjsbridge.js"></script>
<script type="text/javascript" src="d.alicdn/alilog/mlog/aplus.js?id=202951085"></script>
<title>离岛温暖e家</title>
</head>
<body>
<noscript>
<strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>    </noscript>
<div id="app"></div>
<!-- built files will be auto injected -->
</body>
<script>session.setMaxInactiveInterval(60*60*4)</script>
<!-- 设置session过期时间 -->
</html>
login:
<template>
<div id="login"></div>
</template>
<script>
import { getTicket } from'@/api/ZWcommon'
import { setLocal } from'@/utils/local'
// 初始化jsbridge
// const excuteBridge = () => {
//  Ready(() => {
/
/    console.log('初始化完成后,执⾏bridge⽅法')
//  })
// } // 导⼊⼆次封装⽅法
export default {
data() {
return {
ticket: '',
userInfoData: {
userid: '', // ⽤户Id
username: '', // ⽤户姓名
mobile: '', // ⽤户电话
sex: '', // ⽤户性别
birthday: '', // ⽤户⽣⽇
createdate: ''// 创建时间
}
}
},
mounted() {
},
methods: {
getTicket() {
/
/ 获取票据
var url = window.location.href // 获取页⾯路由
if (url.indexOf('ticket') != -1) {
const params = url.split('?')[2].split('&') // 截取路由
for (let index = 0; index < params.length; index++) {
}
}
}
if (this.ticket != '') {
this.postTicket(this.ticket)
}
},
postTicket(value) {
// 票据验证登录
const params = { ticket: value }
getTicket(params)
.then(res => {
const resultCode = de // 获取返回的请求状态码
const resultData = res.data // 获取返回的结果
const Data = JSON.parse(JSON.stringify(resultData.userInfoResult))
this.userInfoData = JSON.parse(Data)
// console.log('本地结果', this.userInfoData)
if (resultCode == 200) {
this.SetUserInfo() // 设置⽤户信息
this.loginSuccess() // 跳转⾸页
} else {
this.ticket = ''
console.log(resultData.msg) // 不成功信
}
})
.catch(err => {
this.ticket = ''
console.log('err', err)
})
},
loginSuccess() {
// ⽤户成功登录回调
this.ticket = ''
this.$place('/')
},
SetUserInfo() {
// 设置⽤户信息
setLocal('userid', this.userInfoData.userid)
localStorage.setItem('userInfoData', this.userInfoData)
}
}
}
</script>
home.vue:
<template>
<div class="homePage">
<div class="cont-01 bgShadow">
<van-swipe
:autoplay="3000"
indicator-color="white"
:
show-indicators="true"
>
<van-swipe-item v-for="(img, index) in imageList" :key="index">
<van-image class="img-custom-large img320" lazy-load :src="img" />        </van-swipe-item>
</van-swipe>
<van-grid :gutter="10" :column-num="3"class="grid-custom">
<van-grid-item
v-for="(item, index) in menuList.slice(1)"
:key="index"
:icon="item.icon"
:text="item.value"
@click="menuClick(item)"
/>
<van-grid-item
v-for="(item, index) in menuList.slice(0, 1)"
:key="index"
:icon="item.icon"
text="查看更多"
/>
</van-grid>
</div>
<div class="cont-02">
<van-image
class="img-custom-large"
lazy-load
:src="require('@/assets/images/xhfd.png')"
@click="isAnswer"
/>
<van-cell
class="cell-custom"
title="家庭教育活动"
is-link
value="了解更多"
@click="toPath('jiating')"
/>
<van-grid :border="false" :column-num="2"class="gird-imgBtn">
<van-grid-item :border="false">
<div class="imgBtn bg1" @click="toPath('jiating')">
<span>亲⼦辅导</span>
</div>
</van-grid-item>
<van-grid-item>
<div class="imgBtn bg2" @click="toPath('jiating')">
<span>亲⼦互动</span>
</div>
</van-grid-item>
</van-grid>
</div>
<div class="cont-03 bgShadow" @click="toPath('dhysHome')">
<van-card
title="“东海渔嫂”社会组织活动展⽰"
:thumb="require('@/assets/dhys/dhys-logo.png')"
>
<template #desc>
<div class="van-multi-ellipsis--l3">{{ desc }}</div>
</template>
</van-card>
<van-grid :border="false" :column-num="5"class="gird-imgBtn">
<van-grid-item v-for="(it, index) in imgList" :key="index">
<van-image class="img-custom-large img120" lazy-load :src="it" />        </van-grid-item>
</van-grid>
</div>
<div class="cont-04">
<!-- weixin://dl/business/?t=wPuGB0QQ29q -->
<van-image
:src="require('@/assets/images/qiandao.png')"
@click="toSign"
/>
<van-popup v-model="signShow">
<van-image
class="img-custom-large"
lazy-load
:src="require('@/assets/images/signCode.jpg')"
/>
<p class="signTxt">长按图⽚识别⼆维码</p>
</van-popup>
<van-image
class="img-custom-large img180"
lazy-load
:src="require('@/assets/images/jstj.png')"
@click="toPath('jiufen')"js arguments
/>
<van-grid :border="false" :column-num="2"class="gird-imgBtn">
<van-grid-item>
<van-image
class="img-custom-large img180 pd20"
lazy-load
:src="require('@/assets/images/xlzx.png')"
@click="toPath('xinli')"
/>
</van-grid-item>
<van-grid-item>
<van-image
class="img-custom-large img180"
lazy-load
:src="require('@/assets/images/flzx.png')"
@click="toPath('falv')"
/>
</van-grid-item>
</van-grid>
</div>
</div>
</template>
<script>
import {
queryMySelfInfo,
getHomeData,
getGuidance,
getOpenId
} from'@/api/ZWcommon'
import { setLocal, getLocal } from'@/utils/local'
import { wx } from'weixin-js-sdk'
export default {
name: 'homePage',
data() {
return {
current: 0,
menuList: [
{
value: '青年交流',
icon: require(`@/assets/images/banner/icon-qingnian.png`)
},
{
value: '新婚辅导',
icon: require(`@/assets/images/banner/icon-xinhun.png`)
},
{
value: '⼼理咨询',
icon: require(`@/assets/images/banner/icon-xinli.png`)
},
{
value: '法律咨询',
icon: require(`@/assets/images/banner/icon-falv.png`)
},
{
value: '纠纷化解',
icon: require(`@/assets/images/banner/icon-jiufen.png`)
},
{
value: '家庭教育',
icon: require(`@/assets/images/banner/icon-jiating.png`)
}
],
infoShow: false,
openId: '',
source: '1', // 根据路由判断平台 1  2⼩程序  3浙⾥办  4浙政钉
desc:
'在社会治理中⼴泛开展各类宣传、宣讲活动。结合其⾃⾝特点,通过组建平安渔区禁毒反赌宣传队、渔业安全⽣产宣传队、创城知识宣传队、拆迁政策宣传队等队伍,多形式多层次开展宣传宣讲,配合党委政府中⼼⼯作,不断凝聚社会正能量。      signShow: false,
imageList: [],
phone: '',
imgList: [
require('@/assets/dhys/dhys-01.png'),
require('@/assets/dhys/dhys-02.png'),
require('@/assets/dhys/dhys-03.png'),
require('@/assets/dhys/dhys-04.png'),
require('@/assets/dhys/dhys-05.png'),
require('@/assets/dhys/dhys-06.png'),
require('@/assets/dhys/dhys-07.png'),
require('@/assets/dhys/dhys-08.png'),
require('@/assets/dhys/dhys-09.png'),
require('@/assets/dhys/dhys-10.png')
],
userInfoData: {} // ⽤户个⼈信息
}
},
created() {
this.init()
},
mounted() {
this.isLogin()
this.SetZwaplus() // 埋点?
},
methods: {
onChangeSwiper(index) {
this.current = index
},
sendMessage() {
const postData = {
url: window.location.href,
title: Response.username + ':' + Response.title,
image: Response.image
}
wx.miniProgram.postMessage({ data: JSON.stringify(postData) })
init() {
// this.source = getLocal('source')
/
/  ? getLocal('source')
//  : Params('source') // 来源source: 1  2⼩程序  3浙⾥办  4浙政钉this.source = '3'
setLocal('source', this.source)
this.userInfoData = Item('userInfoData')
this.phone = bile
this.openId = getLocal('userid')
setLocal('openId', this.openId)
if (this.source === '3') {
}
// if (this.source === '1') {
/
/  if (!getLocal('openId')) OpenId_gzh()
// } else if (this.source === '2') {
//  OpenId_app()
// }
},
// ⼩程序获取openId
getOpenId_app() {
this.openId = Params('openId')
// this.openId = '03e53b38216147c8b5dd842493284baf'
setLocal('openId', this.openId)
},
/
/ 获取openId
getOpenId_gzh() {
const code = Params('code') // 截取路径中的code
if (code == null || code === '') {
const url = window.location.href
const local = encodeURIComponent(url)
window.location.href =
'open.weixin.qq/connect/oauth2/authorize?appid=wxe24faf36e5d880b0&redirect_uri=' +          local +
'&response_type=code&scope=snsapi_userinfo&state=1#wechat_redirect'
} else {
}
},
getopenId(code) {
getOpenId({ code, source: '3' }).then(res => {
if (de !== 200) {
setLocal('openId', this.openId)
}
})
},
// 获取路由参数--根据路由判断平台 1  2⼩程序  3浙⾥办  4浙政钉
getParams(name) {
var reg = new RegExp('(|&)' + name + '=([^&]*)(&|$)', 'i')
var r = window.location.search.substr(1).match(reg)
if (r != null) {
return decodeURIComponent(r[2])
}
return null
},
getImgs() {
getHomeData().then(res => {
// console.log('获取图⽚', res)
if (de !== 200) return
this.imageList = res.data
})
},
toSign() {
if (this.source === '1') {
window.location.href = 'weixin://dl/business/?t=wPuGB0QQ29q'
} else {
this.signShow = true
}
},
menuClick(item) {
const obj = {
青年交流: () => {
},
新婚辅导: () => {
this.isAnswer()
},
⼼理咨询: () => {
this.$router.push({ path: '/xinli' })
},
法律咨询: () => {
this.$router.push({ path: '/falv' })
},
纠纷化解: () => {
this.$router.push({ path: '/jiufen' })
},
家庭教育: () => {
this.$router.push({ path: '/jiating' })
}
}
obj[item.value]()
},
isAnswer() {
if (!getLocal('openId')) return this.$toast('正在获取信息,请稍后')
const param = { openId: getLocal('openId') }
getGuidance(param).then(res => {
if (de === 200) {
this.$router.push({
path: '/finish',
query: {
trackingNumber: ackingNumber,
courierCompany: urierCompany
}
})
} else {
this.$router.push({ path: '/watchVideo', query: { id: res.data } })
}
})
},
toHunlian() {
if (!getLocal('openId')) return this.$toast('正在获取信息,请稍后')
const param = { openId: getLocal('openId'), phone: this.phone }
queryMySelfInfo(param)
.then(res => {
if (de === 200) {
this.$router.push({ path: '/myInfo' })
} else if (de === 201) {
this.$router.push({ path: '/nameSex' })
} else {
this.$toast(res.msg, { duration: 200000000, forbidClick: true })
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。