We use the same UA code on ~1,000 Drupal sites that make up the colorado.edu domain. Site owners have the option of adding an additional UA code, but all sites using our install profile get the default code so we have an overview of all activity. Unfortunately, the code in http://cgit.drupalcode.org/google_analytics/tree/googleanalytics.module?... assumes that the 404.html and 403.html are relative to the root of the domain.

// 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';
    }
    elseif ($status == '404 Not Found') {
      $url_custom = '"/404.html?page=" + document.location.pathname + document.location.search + "&from=" + document.referrer';
    }

In our case, they are not. I understand why you are creating a path for the 404 and 403 responses, but why not use the global $base_path instead of assuming /? Even if you are only running Drupal with a UA code on a single site in a directory, this will still result in more accurate analytics.

Also, the url in the comment for that functionality is (ironically) a 404. I think https://analytics.googleblog.com/2006/09/tip-tracking-404-pages.html is the same recommendation that was being made in https://web.archive.org/web/20110409081454/http://www.google.com/support....

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

kreynen created an issue. See original summary.

kreynen’s picture

hass’s picture

Version: 7.x-2.x-dev » 8.x-2.x-dev
hass’s picture

Issue tags: +Needs tests
+++ b/googleanalytics.module
@@ -201,11 +202,11 @@ function googleanalytics_page_alter(&$page) {
+      $url_custom = $base_path . '"git 404.html?page=" + document.location.pathname + document.location.search + "&from=" + document.referrer';

There is a word "git" in the line.

hass’s picture

Status: Active » Needs work

doubles quotes seems incorrect.

hass’s picture

Status: Needs work » Needs review
FileSize
2.52 KB

  • hass committed ff718d5 on 8.x-2.x
    Issue #2903906 by hass: Assuming /404.html is at the root of site is...

  • hass committed cab8a27 on 7.x-2.x
    Issue #2903906 by hass: Assuming /404.html is at the root of site is...
hass’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.