This repository was archived by the owner on May 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
87 lines (79 loc) · 2.05 KB
/
index.html
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Google Analytics A/B Testing</title>
<script src="https://unpkg.com/vue"></script>
</head>
<body>
<div id="app">
<label>
Version
<select v-model="version">
<option value="A">A</option>
<option value="B">B</option>
</select>
</label>
<hr>
<h1>Version <span v-if="version === 'A'">🅰</span><span v-else>🅱</span></h1>
<p>This is the {{ version }} version of our landing page!</p>
<button @click="sendConversionEvent">Call to action</button>
</div>
<!-- Google Analytics -->
<script>
window.ga = window.ga || function () {
(ga.q = ga.q || []).push(arguments)
};
ga.l = +new Date;
ga('create', 'UA-XXXXX-Y', 'auto');
ga('send', 'pageview');
</script>
<script async src='https://www.google-analytics.com/analytics.js'></script>
<!-- End Google Analytics -->
<!-- A/B Testing Logic -->
<script>
function getVersion() {
return localStorage.getItem('version') || (Math.random() >= 0.5 ? 'A' : 'B');
}
function setVersion(value) {
localStorage.setItem('version', value);
}
function sendVirtualPageview(version) {
ga('send', {
hitType: 'pageview',
page: `/virtual/${version}`
});
// ga('send', 'pageview',`/${this.version}`)
}
function sendConversionEvent() {
ga('send', {
hitType: 'event',
eventCategory: 'Category',
eventAction: 'Action',
eventLabel: 'Label'
});
// ga('send', 'event', 'Category', 'Action', 'Label');
}
</script>
<!-- End A/B Testing Logic -->
<!-- Vue -->
<script>
new Vue({
el: '#app',
data: {
version: getVersion()
},
methods: { sendConversionEvent },
watch: {
version(value) {
setVersion(value);
}
},
mounted() {
sendVirtualPageview(this.version);
}
});
</script>
<!-- End Vue -->
</body>
</html>