Skip to content

Commit

Permalink
fix: review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
rpapani committed Jan 17, 2024
1 parent 10e912b commit 1b7811a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 39 deletions.
2 changes: 2 additions & 0 deletions head.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
<script src="/scripts/scripts.js" type="module"></script>
<link rel="stylesheet" href="/styles/styles.css"/>
<link rel="icon" href="data:,">
<link rel="preconnect" href="https://edge.adobedc.net">
<link rel="preconnect" href="https://adobedc.demdex.net">
9 changes: 3 additions & 6 deletions plugins/experimentation/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}),
);
Expand Down
20 changes: 0 additions & 20 deletions scripts/analytics/lib-analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' }
Expand All @@ -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}}
Expand Down
30 changes: 17 additions & 13 deletions scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {
setupAnalyticsTrackingWithAlloy,
getSegmentsFromAlloy,
analyticsCustomData,
establishPreConnections,
} from './analytics/lib-analytics.js';

const LCP_BLOCKS = []; // add your LCP blocks to the list
Expand All @@ -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
Expand All @@ -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;
},
};

Expand Down Expand Up @@ -202,7 +207,6 @@ export function decorateMain(main) {
*/
async function loadEager(doc) {
document.documentElement.lang = 'en';
establishPreConnections();
decorateTemplateAndTheme();
await initAnalyticsTrackingQueue();

Expand Down

0 comments on commit 1b7811a

Please sign in to comment.