-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvue-ya-metrica.js
56 lines (55 loc) · 1.73 KB
/
vue-ya-metrica.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import Vue from 'vue'
const VueYaMetrica = Vue.component('VueYaMetrica', {
name: 'VueYaMetrica',
render: function (createElement) {
return createElement('div')
},
props: {
'counter' : {
required: true,
type: Number
},
'enableWebvisor': {
type: Boolean
},
'enableHash': {
type: Boolean
}
},
mounted: function() {
var cId = this.$props.counter;
if(!cId){
throw new Error('Yandex.Metrica counter id is not provided');
return;
}
(function(d, w, c) {
(w[c] = w[c] || []).push(function() {
try {
var counterName = 'yaCounter' + cId;
w[counterName] = new Ya.Metrika({
id: cId,
clickmap: true,
trackLinks: true,
accurateTrackBounce: true,
webvisor: !!this.$propsenableWebvisor,
trackHash: !!this.$propsenableHash
});
} catch (e) {}
});
var n = d.getElementsByTagName("script")[0],
s = d.createElement("script"),
f = function() {
n.parentNode.insertBefore(s, n);
};
s.type = "text/javascript";
s.async = true;
s.src = "https://mc.yandex.ru/metrika/watch.js";
if (w.opera == "[object Opera]") {
d.addEventListener("DOMContentLoaded", f, false);
} else {
f();
}
})(document, window, "yandex_metrika_callbacks");
}
});
export default VueYaMetrica