From 45c36be800899164cc77858ecba372fbdfaddf79 Mon Sep 17 00:00:00 2001 From: Paul Hayes Date: Tue, 14 Jul 2015 17:55:25 +0100 Subject: [PATCH 1/4] Add analytics profile to transactions Departments often want to track user journeys from transaction start pages through to their service. This will allow publishers to self serve. https://github.com/alphagov/govuk_content_models/pull/307 https://trello.com/c/QyHwb1Zu/ --- app/views/transactions/_fields.html.erb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/views/transactions/_fields.html.erb b/app/views/transactions/_fields.html.erb index 5bc148ed4..66bb0275f 100644 --- a/app/views/transactions/_fields.html.erb +++ b/app/views/transactions/_fields.html.erb @@ -31,6 +31,13 @@ :label => 'What you need to know', :wrapper_html => { :class => 'add-top-margin' }, :input_html => { :rows => 4, :disabled => @resource.locked_for_edits?, :class => 'input-md-7' } %> + + <%= f.input :department_analytics_profile, + :label => 'Department analytics profile', + :placeholder => 'UA-XXXXXX-X', + :hint => 'Let departments track user journeys between GOV.UK and their service using Google Analytics.', + :wrapper_html => { :class => 'add-top-margin' }, + :input_html => { :rows => 4, :disabled => @resource.locked_for_edits?, :class => 'input-md-2' } %> <% end %> <%= render partial: 'shared/common_edition_tags', locals: {f: f} %> From 4b2ac1b22da03488a87dcb4eabd20ecaad932faa Mon Sep 17 00:00:00 2001 From: Paul Hayes Date: Wed, 15 Jul 2015 12:09:14 +0100 Subject: [PATCH 2/4] Add profile IDs to transaction editions Migrate existing analytics profiles from frontend to non-archived transaction editions * Add profiles from https://github.com/alphagov/frontend/blob/d940889b5bb779ca72266c03c7458b b296e010af/app/helpers/cross_domain_analytics_helper.rb * 1 new from https://trello.com/c/QyHwb1Zu/ --- .../20150715113301_add_analytics_profiles.rb | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 db/migrate/20150715113301_add_analytics_profiles.rb diff --git a/db/migrate/20150715113301_add_analytics_profiles.rb b/db/migrate/20150715113301_add_analytics_profiles.rb new file mode 100644 index 000000000..1f4bd78b8 --- /dev/null +++ b/db/migrate/20150715113301_add_analytics_profiles.rb @@ -0,0 +1,20 @@ +class AddAnalyticsProfiles < Mongoid::Migration + def self.up + profiles = { + 'register-to-vote' => 'UA-23066786-5', + 'accelerated-possession-eviction' => 'UA-37377084-12', + 'renewtaxcredits' => 'UA-43414424-1', + 'registered-traveller' => 'UA-47583357-4', + } + + profiles.each do |slug, profile| + editions = TransactionEdition.where(slug: slug, :state.ne => 'archived') + editions.each do |edition| + edition.set(:department_analytics_profile, profile) + end + end + end + + def self.down + end +end From 87648cca286845b687bdd8a54842438e6eeb7c05 Mon Sep 17 00:00:00 2001 From: Paul Hayes Date: Wed, 15 Jul 2015 15:42:33 +0100 Subject: [PATCH 3/4] Add missing transaction integration test --- .../transaction_create_edit_test.rb | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 test/integration/transaction_create_edit_test.rb diff --git a/test/integration/transaction_create_edit_test.rb b/test/integration/transaction_create_edit_test.rb new file mode 100644 index 000000000..caf1df8e6 --- /dev/null +++ b/test/integration/transaction_create_edit_test.rb @@ -0,0 +1,73 @@ +# encoding: utf-8 +require 'integration_test_helper' + +class TransactionCreateEditTest < JavascriptIntegrationTest + setup do + @artefact = FactoryGirl.create(:artefact, + slug: "register-for-space-flight", + kind: "transaction", + name: "Register for space flight", + owning_app: "publisher", + ) + + setup_users + stub_collections + end + + with_and_without_javascript do + should "edit a new TransactionEdition" do + visit "/publications/#{@artefact.id}" + + assert page.has_content? @artefact.name + + fill_in "Introductory paragraph", :with => "Become a space pilot" + fill_in "Will continue on", :with => "UK Space Recruitment" + fill_in "More information", :with => "Take part in the final frontier" + + save_edition_and_assert_success + assert page.has_content? @artefact.name + + transaction = TransactionEdition.first + assert_equal @artefact.id.to_s, transaction.panopticon_id + + assert_equal "Become a space pilot", transaction.introduction + assert_equal "UK Space Recruitment", transaction.will_continue_on + assert_equal "Take part in the final frontier", transaction.more_information + end + + should "allow editing a TransactionEdition" do + transaction = FactoryGirl.create(:transaction_edition, + :panopticon_id => @artefact.id, + :title => "Register for space flight", + :introduction => "Become a space pilot", + :will_continue_on => "UK Space Recruitment",) + + visit "/editions/#{transaction.to_param}" + + assert page.has_content? 'Register for space flight' + assert page.has_field?("Introductory paragraph", :with => "Become a space pilot") + assert page.has_field?("Will continue on", :with => "UK Space Recruitment") + + fill_in "Introductory paragraph", :with => "Get your licence to fly to Mars" + fill_in "Will continue on", :with => "UK Terrestrial Mars Office" + + save_edition_and_assert_success + + t = TransactionEdition.find(transaction.id) + assert_equal "Get your licence to fly to Mars", t.introduction + assert_equal "UK Terrestrial Mars Office", t.will_continue_on + end + end + + should "disable fields for a published edition" do + edition = FactoryGirl.create(:transaction_edition, + :panopticon_id => @artefact.id, + :state => 'published', + :slug => @artefact.slug, + :title => "Foo transaction" + ) + + visit "/editions/#{edition.to_param}" + assert_all_edition_fields_disabled(page) + end +end From 3fb4ebb788998a3c5d6e5382d8b5db659d2ecf07 Mon Sep 17 00:00:00 2001 From: Paul Hayes Date: Wed, 15 Jul 2015 15:47:39 +0100 Subject: [PATCH 4/4] Add integration test for analytics profile --- .../transaction_create_edit_test.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/integration/transaction_create_edit_test.rb b/test/integration/transaction_create_edit_test.rb index caf1df8e6..6d39880c6 100644 --- a/test/integration/transaction_create_edit_test.rb +++ b/test/integration/transaction_create_edit_test.rb @@ -12,6 +12,8 @@ class TransactionCreateEditTest < JavascriptIntegrationTest setup_users stub_collections + + login_as @author end with_and_without_javascript do @@ -57,6 +59,23 @@ class TransactionCreateEditTest < JavascriptIntegrationTest assert_equal "Get your licence to fly to Mars", t.introduction assert_equal "UK Terrestrial Mars Office", t.will_continue_on end + + should "allow only a valid department analytics profile" do + transaction = FactoryGirl.create(:transaction_edition, + :panopticon_id => @artefact.id, + :title => "Register for space flight") + + visit "/editions/#{transaction.to_param}" + + fill_in "Department analytics profile", :with => "UA-INVALID-SPACE-FLIGHT" + save_edition_and_assert_error + + fill_in "Department analytics profile", :with => "UA-00100000-1" + save_edition_and_assert_success + + t = TransactionEdition.find(transaction.id) + assert_equal "UA-00100000-1", t.department_analytics_profile + end end should "disable fields for a published edition" do