From b383eaf428d5227f7697f42ccf477e8730cf4706 Mon Sep 17 00:00:00 2001 From: hoosteeno Date: Wed, 24 Jun 2015 15:27:21 -0700 Subject: [PATCH 1/7] [fix bug 1032455] Add helpfulness interface using GA --- kuma/wiki/templates/wiki/document.html | 1 + media/js/components.js | 1 + media/js/helpfulness.js | 32 ++++++++++++++++++++++++++ settings.py | 5 +++- 4 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 media/js/helpfulness.js diff --git a/kuma/wiki/templates/wiki/document.html b/kuma/wiki/templates/wiki/document.html index 559889c3b38..e19c56a3be9 100644 --- a/kuma/wiki/templates/wiki/document.html +++ b/kuma/wiki/templates/wiki/document.html @@ -416,4 +416,5 @@

{{ _('Document Tags and Contributors') }}

{# This can be removed once the social network button multivariate test is completed. #} mdn.optimizely.push(['activate', 2796520257]); + {{ js('document') }} {% endblock %} diff --git a/media/js/components.js b/media/js/components.js index 5045b0be9fa..149329ea0f8 100644 --- a/media/js/components.js +++ b/media/js/components.js @@ -429,6 +429,7 @@ { state: 'success', className: 'success', iconName: 'icon-smile' }, { state: 'error', className: 'error', iconName: 'icon-frown' }, { state: 'warning', className: 'warning', iconName: 'icon-warning-sign' }, + { state: 'question', className: 'question', iconName: 'icon-question-sign' }, defaultState ]; var statesObj = {}; diff --git a/media/js/helpfulness.js b/media/js/helpfulness.js new file mode 100644 index 00000000000..67c1925eea3 --- /dev/null +++ b/media/js/helpfulness.js @@ -0,0 +1,32 @@ +(function(win, doc, $) { + if (document.cookie.replace(/(?:(?:^|.*;\s*)helpful-stfu\s*\=\s*([^;]*).*$)|^.*$/, "$1") !== 'true') { + if (window.waffle && window.waffle.flag_is_active('helpfulness')) { + // if they stay a minute, ask if it was helpful + setTimeout(function() { + var question = mdn.Notifier.growl('Did this page help you?
YesNoNever ask me again', { closable: true, duration: 0}).question(); + + $('#helpful-yes').click(function() { + confirm("Thanks for your feedback!", 'success', 'Yes'); + }); + $('#helpful-no').click(function() { + confirm("Thanks! We\'ll improve it.", 'error', 'No'); + }); + $('#helpful-stfu').click(function() { + confirm("We won't bug you again.", 'info', 'STFU'); + document.cookie = "helpful-stfu=true; expires=Fri, 31 Dec 9999 23:59:59 GMT;"; + }); + + function confirm(msg, type, label) { + question.close(question.item); + mdn.Notifier.growl(msg, { closable: true, duration: 2500 })[type](); + mdn.analytics.trackEvent({ + category: 'Helpful', + action: 'Clicked', + label: label + }); + } + + }, 60000); + } + } +})(window, document, jQuery); diff --git a/settings.py b/settings.py index 04a30fb1aab..be0c8b6ff75 100755 --- a/settings.py +++ b/settings.py @@ -662,7 +662,6 @@ def JINJA_CONFIG(): 'js/analytics.js', 'js/main.js', 'js/auth.js', - 'js/social.js', 'js/fonts.js', ), 'home': ( @@ -677,6 +676,10 @@ def JINJA_CONFIG(): 'js/profile.js', 'js/moz-jquery-plugins.js', ), + 'document': ( + 'js/social.js', + 'js/helpfulness.js', + ), 'demostudio': ( 'js/libs/jquery.hoverIntent.minified.js', 'js/libs/jquery.scrollTo-1.4.2-min.js', From 083982f32d757dc756d4bba43a8ac7c065de7b31 Mon Sep 17 00:00:00 2001 From: hoosteeno Date: Thu, 25 Jun 2015 13:21:50 -0700 Subject: [PATCH 2/7] [bug 1032455] Add non-interactive GA param --- media/js/helpfulness.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/media/js/helpfulness.js b/media/js/helpfulness.js index 67c1925eea3..767a3dea8f9 100644 --- a/media/js/helpfulness.js +++ b/media/js/helpfulness.js @@ -22,7 +22,8 @@ mdn.analytics.trackEvent({ category: 'Helpful', action: 'Clicked', - label: label + label: label, + {'nonInteraction': 1} //http://www.lunametrics.com/blog/2014/05/06/noninteraction-events-google-analytics/ }); } From caaf880f2dee693a738695eedb7d3e6f2884587d Mon Sep 17 00:00:00 2001 From: hoosteeno Date: Thu, 25 Jun 2015 16:35:35 -0700 Subject: [PATCH 3/7] [bug 1032455] Add more info question --- media/js/helpfulness.js | 51 ++++++++++++++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 11 deletions(-) diff --git a/media/js/helpfulness.js b/media/js/helpfulness.js index 767a3dea8f9..b801eaba9f3 100644 --- a/media/js/helpfulness.js +++ b/media/js/helpfulness.js @@ -1,30 +1,59 @@ (function(win, doc, $) { if (document.cookie.replace(/(?:(?:^|.*;\s*)helpful-stfu\s*\=\s*([^;]*).*$)|^.*$/, "$1") !== 'true') { if (window.waffle && window.waffle.flag_is_active('helpfulness')) { - // if they stay a minute, ask if it was helpful + setTimeout(function() { - var question = mdn.Notifier.growl('Did this page help you?
YesNoNever ask me again', { closable: true, duration: 0}).question(); + var notification = mdn.Notifier.growl(gettext('Did this page help you?
YesNoNever ask me again'), { closable: true, duration: 0}).question(); $('#helpful-yes').click(function() { confirm("Thanks for your feedback!", 'success', 'Yes'); }); $('#helpful-no').click(function() { - confirm("Thanks! We\'ll improve it.", 'error', 'No'); + confirm("", 'error', 'No'); }); $('#helpful-stfu').click(function() { confirm("We won't bug you again.", 'info', 'STFU'); document.cookie = "helpful-stfu=true; expires=Fri, 31 Dec 9999 23:59:59 GMT;"; }); + // create a dropdown in case the page is unhelpful + var unhelpful_options = [ + {val: 'Translate', text: gettext('Translate it into my language')}, + {val: 'Make-Simpler', text: gettext('Make it less confusing')}, + {val: 'Needs-More-Info', text: gettext('It needs more information')}, + {val: 'Incorrect', text: gettext('It contains incorrect information')}, + {val: 'Other', text: gettext('Something else')} + ] + var $select = $('').attr({ - id: 'helpful-detail', - value: 'Choose one...' - }).append($('