From 1b7811a0dcd9322fd4e6644c826436a3c06a1a48 Mon Sep 17 00:00:00 2001 From: Ravi Kiran Papani Date: Tue, 16 Jan 2024 20:34:36 -0800 Subject: [PATCH] fix: review feedback --- head.html | 2 ++ plugins/experimentation/src/index.js | 9 +++------ scripts/analytics/lib-analytics.js | 20 ------------------- scripts/scripts.js | 30 ++++++++++++++++------------ 4 files changed, 22 insertions(+), 39 deletions(-) diff --git a/head.html b/head.html index 9c1b93b2..23e9e335 100644 --- a/head.html +++ b/head.html @@ -2,3 +2,5 @@ + + diff --git a/plugins/experimentation/src/index.js b/plugins/experimentation/src/index.js index 6662fa1d..e0d4ff05 100644 --- a/plugins/experimentation/src/index.js +++ b/plugins/experimentation/src/index.js @@ -11,8 +11,6 @@ */ const MAX_SAMPLING_RATE = 10; // At a maximum we sample 1 in 10 requests -const RTCDP_AUDIENCE_PREFIX = 'rtcdp'; - export const DEFAULT_OPTIONS = { // Generic properties rumSamplingRate: MAX_SAMPLING_RATE, // 1 in 10 requests @@ -65,13 +63,12 @@ export async function getResolvedAudiences(applicableAudiences, options, context const results = await Promise.all( applicableAudiences .map((key) => { - if (key.indexOf(RTCDP_AUDIENCE_PREFIX) !== -1 && options.audiences[RTCDP_AUDIENCE_PREFIX]) { - const rtcdpAudience = key.replace(`${RTCDP_AUDIENCE_PREFIX}-`, ''); - return options.audiences[RTCDP_AUDIENCE_PREFIX](rtcdpAudience); - } if (options.audiences[key] && typeof options.audiences[key] === 'function') { return options.audiences[key](); } + if (!options.audiences[key] && typeof options.audiences.default === 'function') { + return options.audiences.default(key); + } return false; }), ); diff --git a/scripts/analytics/lib-analytics.js b/scripts/analytics/lib-analytics.js index f11cb45f..b7049697 100644 --- a/scripts/analytics/lib-analytics.js +++ b/scripts/analytics/lib-analytics.js @@ -18,12 +18,6 @@ const EXPERIENCE_STEP_EXPERIMENTATION = 'experimentation'; */ const CUSTOM_SCHEMA_NAMESPACE = '_sitesinternal'; -/** - * Pre connection domains to which pre-connect will be established - * NOTE: Add only those urls you need in LCP - */ -const PRECONNECTION_DOMAINS = ['https://edge.adobedc.net', 'https://adobedc.demdex.net']; - /** * Configure the cookie keys that should be mapped to the XDM schema and send with each event * Ex: { 'funnelState': 'userState' } @@ -32,20 +26,6 @@ const PRECONNECTION_DOMAINS = ['https://edge.adobedc.net', 'https://adobedc.demd const COOKIE_MAPPING_TO_SCHEMA = { }; -/** - * Establishes pre-connections to domains that are configured in PRECONNECTION_DOMAINS - */ -export function establishPreConnections() { - PRECONNECTION_DOMAINS.forEach((domain) => { - if (!document.querySelector(`head > link[rel="preconnect"][href="${domain}"]`)) { - const link = document.createElement('link'); - link.setAttribute('rel', 'preconnect'); - link.setAttribute('href', domain); - document.head.appendChild(link); - } - }); -} - /** * Returns experiment id and variant running * @returns {{experimentVariant: *, experimentId}} diff --git a/scripts/scripts.js b/scripts/scripts.js index 19e2e3c9..d53fba96 100644 --- a/scripts/scripts.js +++ b/scripts/scripts.js @@ -23,7 +23,6 @@ import { setupAnalyticsTrackingWithAlloy, getSegmentsFromAlloy, analyticsCustomData, - establishPreConnections, } from './analytics/lib-analytics.js'; const LCP_BLOCKS = []; // add your LCP blocks to the list @@ -33,6 +32,7 @@ const LCP_BLOCKS = []; // add your LCP blocks to the list * to generate the segment-mappings automatically from your AEP segments. */ const SEGMENTNAME_ID_MAPPINGS = '/data/segment-mappings.json'; +const RTCDP_AUDIENCE_PREFIX = 'rtcdp'; window.hlx.RUM_GENERATION = 'project-1'; // add your RUM generation information here // Define the custom audiences mapping for experience decisioning @@ -41,17 +41,22 @@ const AUDIENCES = { desktop: () => window.innerWidth >= 600, 'new-visitor': () => !localStorage.getItem('franklin-visitor-returning'), 'returning-visitor': () => !!localStorage.getItem('franklin-visitor-returning'), - rtcdp: async (rtcdpAudience) => { - const segmentMappingsResponse = await fetch(SEGMENTNAME_ID_MAPPINGS); - const segmentMappingsJson = await segmentMappingsResponse.json(); - const segmentMappings = []; - segmentMappingsJson.forEach((mapping) => { - const name = mapping.name.replace(/\s+/g, '-').toLowerCase(); - segmentMappings[name] = mapping.id; - }); - const rtcdpAudienceId = segmentMappings[rtcdpAudience]; - const segments = await getSegmentsFromAlloy(); - return segments.includes(rtcdpAudienceId); + default: async (audience) => { + // check if the audience is rtcdp audience + if (audience.indexOf(RTCDP_AUDIENCE_PREFIX) !== -1) { + const rtcdpAudience = audience.replace(`${RTCDP_AUDIENCE_PREFIX}-`, ''); + const segmentMappingsResponse = await fetch(SEGMENTNAME_ID_MAPPINGS); + const segmentMappingsJson = await segmentMappingsResponse.json(); + const segmentMappings = []; + segmentMappingsJson.forEach((mapping) => { + const name = mapping.name.replace(/\s+/g, '-').toLowerCase(); + segmentMappings[name] = mapping.id; + }); + const rtcdpAudienceId = segmentMappings[rtcdpAudience]; + const segments = await getSegmentsFromAlloy(); + return segments.includes(rtcdpAudienceId); + } + return false; }, }; @@ -202,7 +207,6 @@ export function decorateMain(main) { */ async function loadEager(doc) { document.documentElement.lang = 'en'; - establishPreConnections(); decorateTemplateAndTheme(); await initAnalyticsTrackingQueue();