diff options
author | Struan Donald <struan@exo.org.uk> | 2014-04-16 14:36:54 +0100 |
---|---|---|
committer | Struan Donald <struan@exo.org.uk> | 2014-04-16 16:00:47 +0100 |
commit | 0625dbe113dc88fe707ca1fb036bf0a580781e15 (patch) | |
tree | 756e83df645c5d5db3f1e9e09f570721e6fad325 /t/app/controller | |
parent | 4734b4c74e203928c599828d9a4fff6dbd57c38c (diff) |
alter pave url sent to analytics on report completion
In order to allow us to do funnel analysis in google analytics we need
to send a differnt page url when a user completes a report. To do this
we add a report_created=1 to the query string on either the report page
or the report confirmation page for logged in and confirm by email users
respectively.
There's a bit of complication as we don't want to set a session cookie
everywhere as that will break caching so we set a stash variable,
although if the user is logged in this is controlled by a variable in
the flash as there is already a session cookie at this point.
also, removes the code that sends an event upon report completion as
this was no use for funnel analysis.
Diffstat (limited to 't/app/controller')
-rw-r--r-- | t/app/controller/report_new.t | 116 |
1 files changed, 115 insertions, 1 deletions
diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t index b1b82954f..98b0175f8 100644 --- a/t/app/controller/report_new.t +++ b/t/app/controller/report_new.t @@ -826,7 +826,7 @@ foreach my $test ( $mech->submit_form_ok( { with_fields => { - title => "Test Report at café", + title => "Test Report at café", detail => 'Test report details.', photo => '', name => 'Joe Bloggs', @@ -1482,6 +1482,120 @@ subtest "categories from deleted bodies shouldn't be visible for new reports" => }; }; +subtest "extra google analytics code displayed on logged in problem creation" => sub { + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], + BASE_URL => 'http://www.fixmystreet.com', + MAPIT_URL => 'http://mapit.mysociety.org/', + }, sub { + # check that the user does not exist + my $test_email = 'test-2@example.com'; + + $mech->clear_emails_ok; + my $user = $mech->log_in_ok($test_email); + + # setup the user. + ok $user->update( + { + name => 'Test User', + phone => '01234 567 890', + } + ), + "set users details"; + + # submit initial pc form + $mech->get_ok('/around'); + $mech->submit_form_ok( { with_fields => { pc => 'GL50 2PR', } }, + "submit location" ); + + # click through to the report page + $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, + "follow 'skip this step' link" ); + + $mech->submit_form_ok( + { + with_fields => { + title => "Test Report at café", + detail => 'Test report details.', + photo => '', + name => 'Joe Bloggs', + may_show_name => '1', + phone => '07903 123 456', + category => 'Trees', + } + }, + "submit good details" + ); + + # find the report + my $report = $user->problems->first; + ok $report, "Found the report"; + + # check that we got redirected to /report/ + is $mech->uri->path, "/report/" . $report->id, "redirected to report page"; + + $mech->content_contains( "extra = '?created_report", 'extra google code present' ); + + # cleanup + $mech->delete_user($user); + }; +}; + +subtest "extra google analytics code displayed on email confirmation problem creation" => sub { + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], + BASE_URL => 'http://www.fixmystreet.com', + MAPIT_URL => 'http://mapit.mysociety.org/', + }, sub { + $mech->log_out_ok; + $mech->clear_emails_ok; + + $mech->get_ok('/'); + $mech->submit_form_ok( { with_fields => { pc => 'GL50 2PR' } }, + "submit location" ); + $mech->follow_link_ok( + { text_regex => qr/skip this step/i, }, + "follow 'skip this step' link" + ); + + my $fields = $mech->visible_form_values('mapSkippedForm'); + my $submission_fields = { + title => "Test Report", + detail => 'Test report details.', + photo => '', + email => 'firstlast@example.com', + name => 'Test User', + may_show_name => '1', + phone => '07903 123 456', + category => 'Trees', + password_register => '', + }; + + $mech->submit_form_ok( { with_fields => $submission_fields }, + "submit good details" ); + + my $email = $mech->get_email; + ok $email, "got an email"; + like $email->body, qr/confirm the problem/i, "confirm the problem"; + + my ($url) = $email->body =~ m{(https?://\S+)}; + ok $url, "extracted confirm url '$url'"; + + # confirm token in order to update the user details + $mech->get_ok($url); + + $mech->content_contains( "extra = '?created_report", 'extra google code present' ); + + my $user = + FixMyStreet::App->model('DB::User') + ->find( { email => 'firstlast@example.com' } ); + + $user->problems->delete; + $user->alerts->delete; + $user->delete; + }; +}; + $contact1->delete; $contact2->delete; $contact3->delete; |