-
Notifications
You must be signed in to change notification settings - Fork 15
/
vue-umami-mixin.js
53 lines (47 loc) · 1.63 KB
/
vue-umami-mixin.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
export default {
data() {
return {
umamiInstalled: document.getElementById("umami-script") !== null
};
},
created() {
if (
!this.$developmentMode &&
localStorage.getItem("umamiTracking") !== "false"
) {
this.installUmami();
if (localStorage.getItem("umamiTracking") === null) {
localStorage.setItem("umamiTracking", "true");
}
}
},
methods: {
installUmami: function() {
if (
!this.$developmentMode &&
!document.getElementById("umami-script")
) {
let umamiScript = document.createElement("script"),
scriptTag = document.getElementsByTagName("script")[0];
umamiScript.async = true;
umamiScript.defer = true;
umamiScript.src = "https://domain.com/umami.js";
umamiScript.id = "umami-script";
umamiScript.setAttribute(
"data-website-id",
"umami-site-id"
);
scriptTag.parentNode.insertBefore(umamiScript, scriptTag);
console.log("Activated Umami anonymous analytics");
}
},
uninstallUmami: function() {
if (!this.$developmentMode) {
let umamiScript = document.getElementById("umami-script");
umamiScript.remove();
localStorage.setItem("umamiTracking", "false");
console.log("Deactivated Umami anonymous analytics");
}
}
}
};