@tsteur opened this Issue on November 5th 2018 Member

Imagine you have for example a website running on http and https. Your analytics may only run on https.

The default embed tracking code you get, looks for example like this:

var u="//analytics.example.com/";

This means on an HTTP page the tracking request will be sent, and then redirected to HTTPS. If the request is a POST request with a body, important tracking requests may get lost. For example some bulk tracking requests, requests with a longer tracking url (could be caused eg by heatmaps, form analytics, etc.), or requests that are queued which will be available soon in https://github.com/matomo-org/matomo/pull/13616

Something that could work to detect a redirect is eg

xhr.onload = function() {
  if (xhr.status === 200) {
    if (xhr.responseURL !== trackingUrl && postWithBody) { 
     // we were redirected... we could try to post the same request to the response URL if a body was posted?
    }
  }
};

or something like this may work as well:

if (xhr.status < 400 && xhr.status >= 300) {
    alert(xhr.getResponseHeader("Location"));
  }

if a redirect was detected, we could maybe in the beginning retry and update the tracking URL internally only when there is for example a protocol mismatch (http vs https). At the least we could report such mismatches in the console.

I haven't tested it and neither thought too much about it, but could be quite useful to not lose any tracking requests.

Powered by GitHub Issue Mirror