Permalink
Browse files

Merge pull request #43 from alphagov/adding_analytics_request

New analytics request form
  • Loading branch information...
2 parents b10d3c6 + 64709e9 commit 9f9673d2903c8f3220a14b88339f8bc91483ee1f @annashipman annashipman committed Jan 28, 2013
@@ -0,0 +1,16 @@
+require 'analytics_request_zendesk_ticket'
+
+class AnalyticsRequestsController < RequestsController
+ protected
+ def new_request
+ AnalyticsRequest.new(requester: Requester.new, needed_report: NeededReport.new)
+ end
+
+ def zendesk_ticket_class
+ AnalyticsRequestZendeskTicket
+ end
+
+ def parse_request_from_params
+ AnalyticsRequest.new(params[:analytics_request])
+ end
+end
@@ -0,0 +1,21 @@
+require 'shared/tableless_model'
+require 'shared/with_requester'
+require 'shared/with_request_context'
+require 'analytics/needed_report'
+
+class AnalyticsRequest < TablelessModel
+ include WithRequester
+ include WithRequestContext
+
+ attr_accessor :needed_report, :justification_for_needing_report
+
+ validates_presence_of :needed_report, :justification_for_needing_report
+
+ def needed_report_attributes=(attr)
+ self.needed_report = NeededReport.new(attr)
+ end
+
+ def self.label
+ "Analytics"
+ end
+end
@@ -0,0 +1,35 @@
+require 'shared/tableless_model'
+
+class NeededReport < TablelessModel
+ attr_accessor :reporting_period_start,
+ :reporting_period_end,
+ :pages_or_sections,
+ :non_standard_requirements,
+ :frequency
+
+ validates_presence_of :reporting_period_start,
+ :reporting_period_end,
+ :pages_or_sections,
+ :frequency
+
+ validates :frequency, inclusion: {
+ in: %w(one-off weekly monthly),
+ message: "%{value} is not valid option"
+ }
+
+ def frequency_options
+ [
+ ["One-off", "one-off"],
+ ["Weekly", "weekly"],
+ ["Monthly", "monthly"],
+ ]
+ end
+
+ def formatted_frequency
+ Hash[frequency_options].key(frequency)
+ end
+
+ def reporting_period
+ "From #{reporting_period_start} to #{reporting_period_end}"
+ end
+end
@@ -3,7 +3,7 @@ class RequestGroups
def initialize
@groups = [
- RequestGroup.new("Content request", [ContentChangeRequest, NewFeatureRequest]),
+ RequestGroup.new("Content request", [ContentChangeRequest, NewFeatureRequest, AnalyticsRequest]),
RequestGroup.new("User Access", [CreateNewUserRequest, RemoveUserRequest]),
RequestGroup.new("Campaigns", [CampaignRequest]),
RequestGroup.new("Other Issues", [GeneralRequest]),
@@ -13,4 +13,8 @@ def initialize
def each(&block)
@groups.each(&block)
end
+
+ def all_request_classes
+ @groups.collect(&:request_classes).flatten
+ end
end
@@ -3,9 +3,9 @@ module WithRequestContext
def self.included(base)
base.validates_presence_of :request_context
- base.validates :request_context, :inclusion => {
- :in => %w(mainstream inside_government detailed_guidance other),
- :message => "%{value} is not valid option"
+ base.validates :request_context, inclusion: {
+ in: %w(mainstream inside_government detailed_guidance),
+ message: "%{value} is not valid option"
}
end
@@ -0,0 +1,29 @@
+<%= f.semantic_fields_for :needed_report do |r| %>
+ <%= r.inputs name: "What reporting period are you interested in?" do %>
+ <%= r.input :reporting_period_start, label: "From", required: true, input_html: {:class => "span6", :"aria-required" => true} %>
+ <%= r.input :reporting_period_end, label: "To", required: true, input_html: {:class => "span6", :"aria-required" => true} %>
+ <%= r.input :pages_or_sections, as: :text, label: "Which page(s) or section(s) on GOV.UK do you want data for? (Please provide URLs and, if possible or relevant, Need IDs)", required: true, input_html: {:class => "span6", :rows => 6, :cols => 50, :"aria-required" => true } %>
+ <% end %>
+
+ <%= f.input :justification_for_needing_report, as: :text, label: "How will you use the report and what decisions will it help you make?", required: true, input_html: {:class => "span6", :rows => 6, :cols => 50, :"aria-required" => true } %>
+
+ <div class="alert alert-info">
+ <p>The standard reporting includes the following metrics:</p>
+ <ul>
+ <li>total pageviews</li>
+ <li>total unique pageviews</li>
+ <li>total unique visitors</li>
+ <li>average time on page</li>
+ </ul>
+ </div>
+
+ <%= r.input :non_standard_requirements, as: :text, label: "Beyond the standard reporting, what other information are you interested in?", input_html: {:class => "span6", :rows => 6, :cols => 50} %>
+
+ <div id="frequency">
+ <%= r.input :frequency, as: :radio, required: true, label: "How often do you need to receive these reports?", collection: r.object.frequency_options, input_html: { :"aria-required" => true } %>
+ </div>
+
+ <div class="alert alert-info">
+ <p>For recurring reports, you will need to renew your request every 6 months.</p>
+ </div>
+<% end %>
@@ -0,0 +1,15 @@
+<%= content_for :page_title, "Analytics" %>
+<%= content_for :header, "Request analytics reports from GDS" %>
+
+<div class="well">
+ <%= semantic_form_for @request, url: { action: "create" }, html: { novalidate: false } do |f| %>
+
+ <%= render partial: "support/requester", locals: { f: f, show_collaborators: true } %>
+
+ <%= render partial: "support/request_context", locals: { f: f } %>
+
+ <%= render partial: "needed_report_details", locals: { f: f } %>
+
+ <%= f.action :submit, label: "Submit", button_html: { class: "btn btn-success" } %>
+ <% end %>
+</div>
View
@@ -1,11 +1,10 @@
+require 'request_groups'
+
Support::Application.routes.draw do
- resource :content_change_request, :only => [:new, :create]
- resource :create_new_user_request, :only => [:new, :create]
- resource :remove_user_request, :only => [:new, :create]
- resource :general_request, :only => [:new, :create]
- resource :new_feature_request, :only => [:new, :create]
- resource :campaign_request, :only => [:new, :create]
+ RequestGroups.new.all_request_classes.each do |request_class|
+ resource request_class.name.underscore, only: [:new, :create]
+ end
match "acknowledge" => "support#acknowledge"
- root :to => 'support#landing'
+ root to: 'support#landing'
end
@@ -0,0 +1,38 @@
+Feature: Analytics requests
+ In order to measure the impact of my content (e.g. a campaign)
+ As a government employee
+ I want a means to request analytics data from GDS
+
+ Background:
+ * the following user has SSO access:
+ | Name | Email |
+ | John Smith | john.smith@email.com |
+
+ Scenario: successful analytics request
+ When the user submits the following analytics request:
+ | Context | From | To | Pages/sections/URLs | What's it for | More detailed analysis | Frequency |
+ | Mainstream (business/citizen) | Start Q4 2012 | End 2012 | https://gov.uk/X | To measure campaign success | I also need KPI Y | One-off |
+ Then the following ticket is raised in ZenDesk:
+ | Subject | Requester email |
+ | Request for analytics | john.smith@email.com |
+ And the ticket is tagged with "govt_form analytics"
+ And the comment on the ticket is:
+ """
+ [Which part of GOV.UK is this about?]
+ Mainstream (business/citizen)
+
+ [Reporting period]
+ From Start Q4 2012 to End 2012
+
+ [Requested pages/sections]
+ https://gov.uk/X
+
+ [Justification for needing report]
+ To measure campaign success
+
+ [More detailed analysis needed?]
+ I also need KPI Y
+
+ [Reporting frequency]
+ One-off
+ """
@@ -149,4 +149,38 @@
fill_in "Additional comments", :with => @request_details["Additional comments"]
step "the user submits the request successfully"
-end
+end
+
+When /^the user submits the following analytics request:$/ do |request_details_table|
+ @request_details = request_details_table.hashes.first
+
+ visit '/'
+
+ click_on "Analytics"
+
+ assert page.has_content?("Request analytics reports from GDS")
+
+ step "the user fills out their details"
+
+ within "#request-context" do
+ choose @request_details["Context"]
+ end
+
+ fill_in "From", :with => @request_details["From"]
+ fill_in "To", :with => @request_details["To"]
+
+ fill_in "Which page(s) or section(s) on GOV.UK do you want data for? (Please provide URLs and, if possible or relevant, Need IDs)",
+ with: @request_details["Pages/sections/URLs"]
+
+ fill_in "How will you use the report and what decisions will it help you make?",
+ with: @request_details["What's it for"]
+
+ fill_in "Beyond the standard reporting, what other information are you interested in?",
+ with: @request_details["More detailed analysis"]
+
+ within "#frequency" do
+ choose @request_details["Frequency"]
+ end
+
+ step "the user submits the request successfully"
+end
@@ -0,0 +1,28 @@
+require 'zendesk_ticket'
+require 'labelled_snippet'
+
+class AnalyticsRequestZendeskTicket < ZendeskTicket
+ def subject
+ "Request for analytics"
+ end
+
+ def tags
+ super + ["analytics"]
+ end
+
+ protected
+ def comment_snippets
+ [
+ LabelledSnippet.new(on: @request, field: :formatted_request_context,
+ label: "Which part of GOV.UK is this about?"),
+ LabelledSnippet.new(on: @request.needed_report, field: :reporting_period),
+ LabelledSnippet.new(on: @request.needed_report, field: :pages_or_sections,
+ label: "Requested pages/sections"),
+ LabelledSnippet.new(on: @request, field: :justification_for_needing_report),
+ LabelledSnippet.new(on: @request.needed_report, field: :non_standard_requirements,
+ label: "More detailed analysis needed?"),
+ LabelledSnippet.new(on: @request.needed_report, field: :formatted_frequency,
+ label: "Reporting frequency"),
+ ]
+ end
+end
@@ -0,0 +1,9 @@
+require 'test_helper'
+
+class AnalyticsRequestTest < Test::Unit::TestCase
+ should validate_presence_of(:requester)
+ should validate_presence_of(:request_context)
+
+ should validate_presence_of(:needed_report)
+ should validate_presence_of(:justification_for_needing_report)
+end
@@ -0,0 +1,21 @@
+require 'test_helper'
+
+class NeededReportTest < Test::Unit::TestCase
+ should validate_presence_of(:reporting_period_start)
+ should validate_presence_of(:reporting_period_end)
+ should validate_presence_of(:pages_or_sections)
+ should validate_presence_of(:frequency)
+
+ should allow_value("one-off").for(:frequency)
+ should allow_value("weekly").for(:frequency)
+ should allow_value("monthly").for(:frequency)
+ should_not allow_value("xxx").for(:frequency)
+
+
+ should allow_value("KPI abc").for(:non_standard_requirements)
+
+ should "provide a text representation of the reporting period" do
+ report = NeededReport.new(reporting_period_start: "Jan 2012", reporting_period_end: "Dec 2012")
+ assert_equal "From Jan 2012 to Dec 2012", report.reporting_period
+ end
+end
@@ -11,17 +11,15 @@ class TestModelWithRequestContextTest < Test::Unit::TestCase
should allow_value("mainstream").for(:request_context)
should allow_value("inside_government").for(:request_context)
should allow_value("detailed_guidance").for(:request_context)
- should allow_value("other").for(:request_context)
should_not allow_value("xxx").for(:request_context)
should "know if it's related to inside government or not" do
- assert TestModelWithRequestContext.new(:request_context => "inside_government").inside_government_related?
- assert TestModelWithRequestContext.new(:request_context => "detailed_guidance").inside_government_related?
- assert !TestModelWithRequestContext.new(:request_context => "mainstream").inside_government_related?
- assert !TestModelWithRequestContext.new(:request_context => "other").inside_government_related?
+ assert TestModelWithRequestContext.new(request_context: "inside_government").inside_government_related?
+ assert TestModelWithRequestContext.new(request_context: "detailed_guidance").inside_government_related?
+ assert !TestModelWithRequestContext.new(request_context: "mainstream").inside_government_related?
end
should "also define the formatted version" do
- assert "Inside Government", TestModelWithRequestContext.new(:request_context => "inside_government").formatted_request_context
+ assert "Inside Government", TestModelWithRequestContext.new(request_context: "inside_government").formatted_request_context
end
end

0 comments on commit 9f9673d

Please sign in to comment.