307 Redirect when loading analytics.js in Chrome

I am building a web application and using Google Analytics (analytics.js) for analytics. I recently noticed that analytics doesn't work correctly in Chrome.

I load analytics using a standard piece of code into a separate module and enable via requirejs. I checked that this script is working as expected and executing a piece of analytics.

When I look at the network traffic in Firefox, I see that the analytics script is loading from Google as expected (HTTP response 200):

enter image description here

However, when I launch the same page in Chrome, I get an HTTP 307 response indicating approximately: blank and analytics does not start:

enter image description here

However, if I paste the analytics URL directly into the Chrome address bar, a script will be found. Any ideas what is going on here or how to fix it?

+70
javascript google-chrome google-analytics
Jan 14 '15 at 14:40
source share
3 answers

307 Internal Redirect with Non-Authorative-Reason: Delegate indicates that the request has been intercepted and modified (redirected) using the Chrome extension via webRequest or declarative webRequest extension APIs.

You can find out which extension caused the redirect as follows:

  • Visit chrome://net-internals/#events
  • Run the query (Google Analytics, in your case).
  • Go back to the chrome://net-internals/#events tab and find the URL_REQUEST matching your query (you can use the search filter to filter the search).
  • Click on an entry to display the log on the right. You will see the extension name, extension ID, and other request information:
 t = 7910 [st = 0] + REQUEST_ALIVE [dt = 6]
 t = 7910 [st = 0] + URL_REQUEST_DELEGATE [dt = 5]
 t = 7910 [st = 0] DELEGATE_INFO [dt = 5]
 -> delegate_info = "extension [Name of extension]" 
  t = 7915 [st = 5] CHROME_EXTENSION_REDIRECTED_REQUEST 
                     -> extension_id = "ebmlimjkpnhckbaejoagnjlgcdhdnjlb"
 t = 7915 [st = 5] -URL_REQUEST_DELEGATE
 t = 7915 [st = 5] + URL_REQUEST_START_JOB [dt = 1]
                  -> load_flags = 339804160 (BYPASS_DATA_REDUCTION_PROXY | MAYBE_USER_GESTURE | REPORT_RAW_HEADERS | VERIFY_EV_CERT)
                  -> method = "GET"
                  -> priority = "LOW"
 -> url = "https://www.google-analytics.com/analytics.js"
 t = 7915 [st = 5] URL_REQUEST_REDIRECT_JOB
                    -> reason = "Delegate"
 t = 7915 [st = 5] URL_REQUEST_FAKE_RESPONSE_HEADERS_CREATED 
                     -> HTTP / 1.1 307 Internal Redirect 
                         Location: about: blank 
                         Non-Authoritative-Reason: Delegate

In this log example, an extension with the name "[Extension Name]" and extension ID "ebmlimjkpnhckbaejoagnjlgcdhdnjlb" redirected the request. After finding the extension name and / or identifier, you can visit chrome://extensions and disable or remove the extension that changed the request.

+173
Jan 14 '15 at 17:19
source share

In my case, the reason for the 307 redirect was more prosaic. Due to the habit of using protocol related URLs , I removed the protocol from the URL in the Google Universal Analytics embed script by changing https://www.google-analytics.com/analytics.js to //www.google-analytics.com/analytics.js .

For example (do not try to do this at home):

(function (i, s, o, g, r, a, m) {i ['GoogleAnalyticsObject'] = r; I [r] = i [r] || function () {(i [r] .q = I [r] .q || []). push (arguments)}, I [r] .l = 1 * new Date (); a = s.createElement (o), m = s.getElementsByTagName (o) [ 0]; a.async = 1; a.src = g; m.parentNode.insertBefore (a, m)}) (window, document, "script", " https: //www.google-analytics.com/analytics ".js', 'ha');

This is undesirable since Google appears to be serving scripts and tracking requests only through https. Thus, deleting the protocol causes a redirection both during the first embedding of the script and in any (!) Subsequent tracking request. In addition, as Paul Irrish stated in an update to his canonical post on protocol - related URLs , this method is no longer encouraged or really has its merits:

Now that SSL is encouraged for everyone and has no performance issues, this method is now an anti-pattern. If the resource you need is available via SSL, always use https: // asset.

+7
Nov 29 '16 at 13:20
source share

In my case, UBlock Origin is activated in my browser. After disconnecting or authorizing on the site, internal redirects stopped

0
May 18 '19 at 15:41
source share



All Articles