Skip to content

Commit

Permalink
Merge pull request #178 from adobe/feature-flags-2.x
Browse files Browse the repository at this point in the history
feat(index): add new feature flag system
  • Loading branch information
trieloff authored May 31, 2024
2 parents b9cf546 + 7ef9f20 commit 3f7c152
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ const KNOWN_PROPERTIES = ['weight', 'id', 'referer', 'checkpoint', 't', 'source'
const DEFAULT_TRACKING_EVENTS = ['click', 'cwv', 'form', 'enterleave', 'viewblock', 'viewmedia', 'loadresource', 'utm'];
const { sampleRUM, queue, isSelected } = (window.hlx && window.hlx.rum) ? window.hlx.rum : {};

const fflags = {
has: (flag) => this[flag].indexOf(Array.from(window.origin)
.map((a) => a.charCodeAt(0))
.reduce((a, b) => a + b, 1) % 1371) !== -1,
enabled: (flag, callback) => this.has(flag) && callback(),
disabled: (flag, callback) => !this.has(flag) && callback(),
onetrust: [543, 770, 1136],
};

const urlSanitizers = {
full: () => window.location.href,
origin: () => window.location.origin,
Expand Down Expand Up @@ -87,9 +96,7 @@ function optedIn(checkpoint, data) {
// Gets configured collection from the config service for the current domain
function getCollectionConfig() {
// eslint-disable-next-line max-len
if ([770, 1136].includes(Array.from(window.origin).map((a) => a.charCodeAt(0)).reduce((a, b) => a + b, 1) % 1371)) {
return DEFAULT_TRACKING_EVENTS.concat('consent');
}
fflags.enabled('onetrust', () => DEFAULT_TRACKING_EVENTS.push('consent'));
return DEFAULT_TRACKING_EVENTS;
}

Expand Down

0 comments on commit 3f7c152

Please sign in to comment.