Browse files

Add outbound link tracking.

  • Loading branch information...
1 parent 6b4d9f7 commit 046711522d7acbba58fb677d7d25c6ec4371399e @jdm committed Jun 1, 2014
Showing with 21 additions and 8 deletions.
  1. +14 −1 foopy.js
  2. +7 −7 index.html
View
15 foopy.js
@@ -18,16 +18,27 @@
$(negative).addClass('visible');
}
+ function trackExternalLink() {
+ window.ga('send', 'event', 'outbound', 'click', $('#ok')[0].firstChild.href);
+ }
+
function updateCurrentChoice(lastIndex) {
var lastChoice = $('.choices li', groupNode)[choices[choices.length - 1][lastIndex]];
var choice = $('.choices li', groupNode)[choices[choices.length - 1][choiceIndex[choiceIndex.length - 1]]];
updateNegativeResponse();
lastChoice.style.display = 'none';
choice.style.display = 'inline';
- $('#ok')[0].firstChild.href = choice.hasAttribute('next-group') ?
+ var button = $('#ok')[0];
+ button.removeEventListener('click', trackExternalLink);
+ var isExternal = choice.hasAttribute('target');
+ button.firstChild.href = !isExternal ?
'' : choice.getAttribute('target');
+ if (isExternal) {
+ button.addEventListener('click', trackExternalLink);
+ }
+
setLocationHashSuffix(getUIDAttribute(choice));
}
@@ -216,6 +227,8 @@
var query = window.location.hash,
queryParts = query.split("/");
+ window.ga('send', 'pageview', query);
+
queryParts.shift(); // Dropping '#!'
var savedGroup = defaultGroup,
View
14 index.html
@@ -11,6 +11,13 @@
<link rel="resource" type="application/l10n" href="locales.ini" />
<link href="//mozorg.cdn.mozilla.net/media/css/tabzilla-min.css" rel="stylesheet"/>
<title>What can I do for Mozilla</title>
+ <!-- #responses div elements has display:none by default in case if js is disabled -->
+ <script>
+ $(document).ready(function() {
+ $('#responses div').show();
+ });
+ </script>
+ <!-- end of manipulation if js is disabled -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
@@ -20,13 +27,6 @@
ga('create', 'UA-35433268-58', 'whatcanidoformozilla.org');
ga('send', 'pageview');
</script>
- <!-- #responses div elements has display:none by default in case if js is disabled -->
- <script>
- $(document).ready(function() {
- $('#responses div').show();
- });
- </script>
- <!-- end of manipulation if js is disabled -->
</head>
<body>

0 comments on commit 0467115

Please sign in to comment.