From c620342b421d46c0e4345d4e794a13e8c58ebb4f Mon Sep 17 00:00:00 2001 From: "R. Miles McCain" Date: Wed, 15 Apr 2020 18:01:26 -0400 Subject: [PATCH] Improve ingress location handling --- shynet/analytics/tasks.py | 5 ++++- shynet/analytics/templates/analytics/scripts/page.js | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/shynet/analytics/tasks.py b/shynet/analytics/tasks.py index c6ac590..2d33872 100644 --- a/shynet/analytics/tasks.py +++ b/shynet/analytics/tasks.py @@ -122,7 +122,10 @@ def ingress_request( session=session, initial=initial, tracker=tracker, - location=location, + # At first, location is given by the HTTP referrer. Some browsers + # will send the source of the script, however, so we allow JS payloads + # to include the location. + location=payload.get("location", location), referrer=payload.get("referrer", ""), load_time=payload.get("loadTime"), ) diff --git a/shynet/analytics/templates/analytics/scripts/page.js b/shynet/analytics/templates/analytics/scripts/page.js index ab121e4..6d45fa3 100644 --- a/shynet/analytics/templates/analytics/scripts/page.js +++ b/shynet/analytics/templates/analytics/scripts/page.js @@ -16,6 +16,7 @@ window.onload = function () { JSON.stringify({ idempotency: idempotency, referrer: document.referrer, + location: window.location.href, loadTime: window.performance.timing.domContentLoadedEventEnd - window.performance.timing.navigationStart,