VUE single page application plus Baidu statistics code (intimately effective)

After applying for Baidu statistics, you will get a js code, you need to insert each page, the first thought that the Vue.js project is first, insert the statistical code into the Index.html entry file, which is globally inserted Each page is all; doing this involves a problem, the Vue.js project is a single page application, each time the user browses the website, the page is not refreshed, and it means no Trigger Baidu statistics; so the effect of ultimately seeing the background of Baidu statistics is only the traffic of the web entry, but cannot count the access traffic of the internal page.

In the main.js file, the AfteReach method of calling Vue-router is called, and the statistical code is added to this method, so that each ROUTER is When you change, you will perform the statistical code, so you have achieved the purpose, the code is as follows:

Router.AFTEREACH ((to, from, next) => {setTimeout () => {var _hmt = _hmt || []; (function () {// Before execution, remove the last inserted code Document.GtelementByid (‘Baidu_tj’) && document.getlementByid (‘baidu_tj’ ) .Remove (); var hm = document.createElement (“script”); hm.src = “”; = “baidu_tj” var s = Document.GtelementsBytagname (“script”) [0]; s.parentnode.insertbefore (hm, s);}) ();}, 0);};
is small The VUE single page application is added to the Baidu statistics code, I hope to help everyone. If you have any questions, please leave a message, the small package will reply to everyone. Thank you very much for your support of Tumi Cloud Website!

© Copyright Notice
Just support it if you like
comment Grab the couch

Please log in to comment