Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect redirects in Matomo JS Tracker #13669

Open
tsteur opened this issue Nov 5, 2018 · 0 comments
Open

Detect redirects in Matomo JS Tracker #13669

tsteur opened this issue Nov 5, 2018 · 0 comments
Labels
Enhancement For new feature suggestions that enhance Matomo's capabilities or add a new report, new API etc.

Comments

@tsteur
Copy link
Member

tsteur commented Nov 5, 2018

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 #13616

Something that could work to detect a redirect is eg

xhr.onload = function() {
  if (xhr.status === 301 || xhr.status === 302) {
    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.

@tsteur tsteur added the Enhancement For new feature suggestions that enhance Matomo's capabilities or add a new report, new API etc. label Nov 5, 2018
@mattab mattab added this to the 3.9.0 milestone Nov 5, 2018
@mattab mattab modified the milestones: 3.9.0, 3.10.0 Mar 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement For new feature suggestions that enhance Matomo's capabilities or add a new report, new API etc.
Projects
None yet
Development

No branches or pull requests

3 participants