From 3ae6cec5a24bdf5d9c8e70ab214800c17ca4a52b Mon Sep 17 00:00:00 2001 From: hass Date: Tue, 12 Jan 2021 19:35:43 -0800 Subject: [PATCH] Issue #2903906 by hass, kreynen: Assuming /404.html is at the root of site is confusing --- googleanalytics.module | 4 ++-- tests/googleanalytics.test | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/googleanalytics.module b/googleanalytics.module index c5e4f39..f756a5a 100644 --- a/googleanalytics.module +++ b/googleanalytics.module @@ -193,10 +193,10 @@ function googleanalytics_preprocess_layout() { // Track access denied (403) and file not found (404) pages. if ($status == '403 Forbidden') { // See http://www.google.com/support/analytics/bin/answer.py?answer=86927 - $url_custom = '"/403.html?page=" + document.location.pathname + document.location.search + "&from=" + document.referrer'; + $url_custom = '"' . $base_path . '403.html?page=" + document.location.pathname + document.location.search + "&from=" + document.referrer'; } elseif ($status == '404 Not Found') { - $url_custom = '"/404.html?page=" + document.location.pathname + document.location.search + "&from=" + document.referrer'; + $url_custom = '"' . $base_path . '404.html?page=" + document.location.pathname + document.location.search + "&from=" + document.referrer'; } // #2693595: User has entered an invalid login and clicked on forgot diff --git a/tests/googleanalytics.test b/tests/googleanalytics.test index 2f73a35..4f12be1 100644 --- a/tests/googleanalytics.test +++ b/tests/googleanalytics.test @@ -118,13 +118,15 @@ class GoogleAnalyticsBasicTest extends BackdropWebTestCase { // Enable tracking code for all user roles. config_set('googleanalytics.settings', 'roles', array()); + $base_path = base_path(); + // Test whether 403 forbidden tracking code is shown if user has no access. $this->backdropGet('admin'); - $this->assertRaw('/403.html', '[testGoogleAnalyticsPageVisibility]: 403 Forbidden tracking code shown if user has no access.'); + $this->assertRaw($base_path . '403.html', '[testGoogleAnalyticsPageVisibility]: 403 Forbidden tracking code shown if user has no access.'); // Test whether 404 not found tracking code is shown on non-existent pages. $this->backdropGet($this->randomName(64)); - $this->assertRaw('/404.html', '[testGoogleAnalyticsPageVisibility]: 404 Not Found tracking code shown on non-existent page.'); + $this->assertRaw($base_path . '404.html', '[testGoogleAnalyticsPageVisibility]: 404 Not Found tracking code shown on non-existent page.'); // DNT Tests: // Enable system internal page cache for anonymous users.