diff --git a/app/assets/javascripts/surveys.js b/app/assets/javascripts/surveys.js index ec9ad7368..2248139d6 100644 --- a/app/assets/javascripts/surveys.js +++ b/app/assets/javascripts/surveys.js @@ -23,31 +23,26 @@ }, smallSurveys: [ { - url: 'https://www.surveymonkey.co.uk/r/73CQFCB', - identifier: 'international_content_survey', - template: TEMPLATE, - frequency: 10, + url: 'https://signup.take-part-in-research.service.gov.uk/?utm_campaign=marriage-abroad&utm_source=Marriage_abroad&utm_medium=Gov.UK&t=GDS', + identifier: 'user_research_panel_survey', + template: '
' + + '
' + + '

Help improve GOV.UK

' + + '

No thanks

' + + '

Answer some questions about yourself to join the research community. This link opens in a new tab.

' + + '
' + + '
', + frequency: 1, activeWhen: function() { - function sectionMatches() { - var sectionName = $('meta[name="govuk:section"]').attr('content'); - return (sectionName === 'visas and immigration' || sectionName === 'passports, travel and living abroad'); - } - function pathMatches() { - var pathMatchingExpr = /\/foreign-travel-advice|\/government\/world/; + var pathMatchingExpr = /\/marriage-abroad/; return pathMatchingExpr.test(userSurveys.currentPath()); } - function organisationMatches() { - var orgMatchingExpr = /|||/; - var metaText = $('meta[name="govuk:analytics:organisations"]').attr('content') || ""; - return orgMatchingExpr.test(metaText); - } - - return (sectionMatches() || pathMatches() || organisationMatches()); + return (pathMatches()); }, - startTime: new Date("October 25, 2016").getTime(), - endTime: new Date("October 28, 2016 23:59:59").getTime() + startTime: new Date("December 5, 2016").getTime(), + endTime: new Date("December 18, 2016 23:59:59").getTime() } ], @@ -81,7 +76,8 @@ var $surveyLink = $('#take-survey'); var surveyUrl = survey.url; - if (surveyUrl.indexOf('?c=') === -1) { + // Survey monkey can record the URL of the survey link if passed through as a query param + if ((/surveymonkey/.test(surveyUrl)) && (surveyUrl.indexOf('?c=') === -1)) { surveyUrl += "?c=" + root.location.pathname; } diff --git a/doc/surveys.md b/doc/surveys.md index 6de9d4e57..6aff0ebf9 100644 --- a/doc/surveys.md +++ b/doc/surveys.md @@ -56,7 +56,22 @@ A callback function returning true or false allowing further scoping of when the In the example above, the survey will only be considered "active" on pages with a section of "education and learning", and will not display on pages where this function evaluates to false. -Not providing this argument has the same effect as setting it to `return true`. The survey will therefore apply to all pages on GOV.UK between `startTime` and `endTime`. +Additional examples of functions which control when a survey should be active based on the current path and organisation: + +```javascript +function pathMatches() { + var pathMatchingExpr = /\/foreign-travel-advice|\/government\/world/; + return pathMatchingExpr.test(currentPath()); +} + +function organisationMatches() { + var orgMatchingExpr = /|||/; + var metaText = $('meta[name="govuk:analytics:organisations"]').attr('content') || ""; + return orgMatchingExpr.test(metaText); +} +``` + +Not providing the `activeWhen` argument has the same effect as setting it to `return true`. The survey will therefore apply to all pages on GOV.UK between `startTime` and `endTime`. ### `startTime` and `endTime` The survey will only be considered "active" between these dates and times. Where an explicit time is not provided (e.g. startTime) note that JavaScript will assume 00:00:00.000 i.e. just after midnight. diff --git a/spec/javascripts/surveys-spec.js b/spec/javascripts/surveys-spec.js index 7e780637a..be9600505 100644 --- a/spec/javascripts/surveys-spec.js +++ b/spec/javascripts/surveys-spec.js @@ -3,7 +3,7 @@ describe("Surveys", function() { var $block; var defaultSurvey = { - url: 'example.com/default', + url: 'surveymonkey.com/default', frequency: 1, // no randomness in the test suite pls identifier: 'user_satisfaction_survey', template: '
' + @@ -45,7 +45,6 @@ describe("Surveys", function() { surveys.init(); expect($('#take-survey').attr('href')).toContain(surveys.defaultSurvey.url); - expect($('#take-survey').attr('href')).toContain("?c=" + window.location.pathname); expect($('#user-satisfaction-survey').length).toBe(1); expect($('#user-satisfaction-survey').hasClass('visible')).toBe(true); expect($('#user-satisfaction-survey').attr('aria-hidden')).toBe('false'); @@ -61,7 +60,7 @@ describe("Surveys", function() { expect($('#user-satisfaction-survey').attr('aria-hidden')).toBe('false'); }); - it("links to the url for the survey with a completion redirect query parameter", function () { + it("links to the url for a surveymonkey survey with a completion redirect query parameter", function () { surveys.displaySurvey(defaultSurvey); expect($('#take-survey').attr('href')).toContain(defaultSurvey.url);