Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(index): add new feature flag system #178

Merged
merged 1 commit into from
May 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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],
};

Comment on lines +17 to +25
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@trieloff No tests mean broken code in production... arrow functions do not have a this! This code fails.

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
Loading