aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--perllib/FixMyStreet/App/Controller/Report.pm3
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/New.pm4
-rw-r--r--perllib/FixMyStreet/App/Controller/Tokens.pm2
-rw-r--r--t/app/controller/report_new.t116
-rw-r--r--templates/web/default/report/extra_analytics.html0
-rw-r--r--templates/web/default/tokens/confirm_problem.html1
-rw-r--r--templates/web/fixmystreet/report/display.html1
-rw-r--r--templates/web/fixmystreet/report/extra_analytics.html8
-rw-r--r--templates/web/fixmystreet/tracking_code.html12
9 files changed, 134 insertions, 13 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Report.pm b/perllib/FixMyStreet/App/Controller/Report.pm
index 081256fe2..13a347a90 100644
--- a/perllib/FixMyStreet/App/Controller/Report.pm
+++ b/perllib/FixMyStreet/App/Controller/Report.pm
@@ -167,6 +167,9 @@ sub format_problem_for_display : Private {
}
$c->stash->{extra_name_info} = $problem->bodies_str && $problem->bodies_str eq '2482' ? 1 : 0;
+ if ( $c->sessionid && $c->flash->{created_report} ) {
+ $c->stash->{created_report} = $c->flash->{created_report};
+ }
$c->forward('generate_map_tags');
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm
index 761215344..4a5e11573 100644
--- a/perllib/FixMyStreet/App/Controller/Report/New.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/New.pm
@@ -1155,7 +1155,9 @@ sub redirect_or_confirm_creation : Private {
$report_uri = $c->cobrand->base_url_for_report( $report ) . $report->url;
}
$c->log->info($report->user->id . ' was logged in, redirecting to /report/' . $report->id);
- $c->flash->{created_report} = 'loggedin';
+ if ( $c->sessionid ) {
+ $c->flash->{created_report} = 'loggedin';
+ }
$c->res->redirect($report_uri);
$c->detach;
}
diff --git a/perllib/FixMyStreet/App/Controller/Tokens.pm b/perllib/FixMyStreet/App/Controller/Tokens.pm
index 19130e25f..44cb2429d 100644
--- a/perllib/FixMyStreet/App/Controller/Tokens.pm
+++ b/perllib/FixMyStreet/App/Controller/Tokens.pm
@@ -102,7 +102,7 @@ sub confirm_problem : Path('/P') {
$c->res->redirect($report_uri);
}
- $c->flash->{created_report} = 'fromemail';
+ $c->stash->{created_report} = 'fromemail';
return 1;
}
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;
diff --git a/templates/web/default/report/extra_analytics.html b/templates/web/default/report/extra_analytics.html
deleted file mode 100644
index e69de29bb..000000000
--- a/templates/web/default/report/extra_analytics.html
+++ /dev/null
diff --git a/templates/web/default/tokens/confirm_problem.html b/templates/web/default/tokens/confirm_problem.html
index 51b459925..723d515e1 100644
--- a/templates/web/default/tokens/confirm_problem.html
+++ b/templates/web/default/tokens/confirm_problem.html
@@ -28,5 +28,4 @@ You can <a href="[% c.cobrand.base_url_for_report( problem ) %][% problem.url %]
[% display_crosssell_advert( problem.user.email, problem.name ) %]
-[% INCLUDE 'report/extra_analytics.html' %]
[% INCLUDE 'footer.html' %]
diff --git a/templates/web/fixmystreet/report/display.html b/templates/web/fixmystreet/report/display.html
index 2c65ca104..b75ef92bc 100644
--- a/templates/web/fixmystreet/report/display.html
+++ b/templates/web/fixmystreet/report/display.html
@@ -23,7 +23,6 @@
[% INCLUDE 'report/banner.html' %]
[% INCLUDE 'report/_main.html' %]
-[% INCLUDE 'report/extra_analytics.html' %]
[% TRY %][% INCLUDE 'report/_message_manager.html' %][% CATCH file %][% END %]
<div class="shadow-wrap">
diff --git a/templates/web/fixmystreet/report/extra_analytics.html b/templates/web/fixmystreet/report/extra_analytics.html
deleted file mode 100644
index 4a993cc2d..000000000
--- a/templates/web/fixmystreet/report/extra_analytics.html
+++ /dev/null
@@ -1,8 +0,0 @@
-[% IF c.flash.created_report %]
-<script type="text/javascript">
- var cobrand = $('meta[name="cobrand"]').attr('content');
- if ( typeof ga !== 'undefined' && cobrand == 'fixmystreet' ) {
- ga('send', 'event', 'report', 'completed', '[% c.flash.created_report %]' );
- }
-</script>
-[% END %]
diff --git a/templates/web/fixmystreet/tracking_code.html b/templates/web/fixmystreet/tracking_code.html
index a9412d4f2..9d8c00d3c 100644
--- a/templates/web/fixmystreet/tracking_code.html
+++ b/templates/web/fixmystreet/tracking_code.html
@@ -7,6 +7,18 @@ m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
ga('create', 'UA-660910-4', {'cookieDomain': '.fixmystreet.com'});
ga('set', 'anonymizeIp', true);
+[% IF created_report %]
+ga(function(tracker) {
+ var page = tracker.get('location');
+ var extra = '';
+ if ( page.indexOf('?') != -1 ) {
+ extra = '&created_report=1';
+ } else {
+ extra = '?created_report=1';
+ }
+ tracker.set('location', page + extra);
+});
+[% END %]
ga('send', 'pageview');
</script>