Skip to content
This repository was archived by the owner on May 10, 2021. It is now read-only.

Commit

Permalink
Init
Browse files Browse the repository at this point in the history
  • Loading branch information
mwieser committed Jun 20, 2018
0 parents commit 25c6437
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 0 deletions.
8 changes: 8 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
The MIT License (MIT)
Copyright © 2018 Manuel Wieser

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Google Analytics A/B Testing
81 changes: 81 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<!DOCTYPE html>
<html>
<head>
<title>Google Analytics A/B Testing</title>
<script src="https://unpkg.com/vue"></script>
</head>
<body>

<div id="app">
<select v-model="version">
<option value="A">A</option>
<option value="B">B</option>
</select>
<h1>Version {{ version }}</h1>
<button @click="sendConversionEvent">Buy</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>

0 comments on commit 25c6437

Please sign in to comment.