loadContext: function()

in src/apache-unomi-tracker.js [341:385]


        loadContext: function (skipEvents = false, invalidate = false, forceReload = false) {
            if (wem.contextLoaded && !forceReload) {
                console.log('Context already requested by', wem.contextLoaded);
                return;
            }
            /** @type {Record<string, unknown>} */
            var jsonData = {
                requiredProfileProperties: wem.digitalData.wemInitConfig.requiredProfileProperties,
                requiredSessionProperties: wem.digitalData.wemInitConfig.requiredSessionProperties,
                requireSegments: wem.digitalData.wemInitConfig.requireSegments,
                requireScores: wem.digitalData.wemInitConfig.requireScores,
                source: wem.buildSourcePage()
            };
            if (!skipEvents) {
                jsonData.events = wem.digitalData.events;
            }
            if (wem.digitalData.personalizationCallback) {
                jsonData.personalizations = wem.digitalData.personalizationCallback.map(function (x) {
                    return x.personalization;
                });
            }

            jsonData.sessionId = wem.sessionID;

            var contextUrl = wem.contextServerUrl + '/context.json';
            if (invalidate) {
                contextUrl += '?invalidateSession=true&invalidateProfile=true';
            }
            wem.ajax({
                url: contextUrl,
                type: 'POST',
                async: true,
                contentType: 'text/plain;charset=UTF-8', // Use text/plain to avoid CORS preflight
                jsonData: jsonData,
                dataType: 'application/json',
                // @ts-expect-error This parameter does not exist
                invalidate: invalidate,
                success: wem._onSuccess,
                error: function () {
                    wem._executeFallback('error during context loading');
                }
            });
            wem.contextLoaded = Error().stack;
            console.info('[WEM] context loading...');
        },