vue single-page application to add Baidu statistical code according to different business in different cities

Problem Description:

We know the general Baidu statistical code is added to the inside of the head html; however, because the current project is the development of single-page application vue, so do not jump between routing refresh the page,

If the statistical code on the head of the project in the index.heml, we can only count to the inlet flow of the entire project, other statistics can not be achieved within the page. And according to current project needs

Add different business and city codes corresponding statistics; it can only take the following methods:

 

Method to realize:

1, the package file a global variable, each city corresponding to all operations following, each service corresponds to a method which put statistical code.

 

2, in the methods of the project entry file encapsulates a method, internal method based on the current page of the business with the city, traverse a global variable in the code to find the corresponding statistics; then executed;

 

3, the first page call the method to add corresponding statistical code is loaded:

 

4, when we switch the city or jump routing, url certainly will change, so we need to send to monitor the url changes, then call statisticsCode () method; we've had to add a city or business changes corresponding statistical code.

Guess you like

Origin www.cnblogs.com/maxiansheng/p/11303162.html