From ed5f472b2f360dadb260b14e87a00c959224952e Mon Sep 17 00:00:00 2001 From: Bryan Wilson Date: Mon, 28 Aug 2023 18:55:22 -0700 Subject: [PATCH] Update Segment url intercepts for fetch-based Segment js API The analytics.js API from CDN started using fetch instead of XHR on March 1 2023. Replace custom Appsembler code which does the replication of frontendJS events to ours and customer's Segment backends Override fetch calls to swap api.segmentio calls with Open edX /segmentio/send/* requests --- lms/templates/widgets/segment-io.html | 30 ++++++++++++++++----------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/lms/templates/widgets/segment-io.html b/lms/templates/widgets/segment-io.html index 0e4f40ece20..5f8da23000e 100644 --- a/lms/templates/widgets/segment-io.html +++ b/lms/templates/widgets/segment-io.html @@ -5,19 +5,25 @@ % if settings.LMS_SEGMENT_KEY and settings.LMS_SEGMENT_SITE: ## begin Copy from edx-platform/cms/templates/widgets/segment-io.html ## Appsembler: begin Segment Site - + return resource; + } + const { fetch: originalFetch } = window; + window.fetch = async (...args) => { + let [resource, config ] = args; + resource = replaceFetchResourceForSegmentSite(resource); + const response = await originalFetch(resource, config); + return response; + }; + }(); + ## Appsembler: end Segment Site ## end Copy % endif