Skip to content

Commit

Permalink
Added audiences
Browse files Browse the repository at this point in the history
  • Loading branch information
adobabe committed Jun 20, 2024
1 parent 7d9e571 commit fd358b6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"version": "1.3.0",
"description": "Starter project for Adobe Helix",
"scripts": {
"lint:js": "eslint .",
"lint:js": "eslint --fix .",
"lint:css": "stylelint blocks/**/*.css styles/*.css",
"lint": "npm run lint:js && npm run lint:css"
},
Expand Down
21 changes: 10 additions & 11 deletions scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,21 @@ const detectBrowser = () => {
const browserInfo = window.navigator.userAgent;
if (/Chrome\/\d+/.test(browserInfo)) {
if (!/Chromium\/\d+|Edg\/\d+/.test(browserInfo)) {
console.log("chrome")
return "chrome";
return 'chrome';
}
} else if (/Safari\/\d+/.test(browserInfo)) {
if (!/Chrome\/\d+|Chromium\/\d+/.test(browserInfo)) {
return "safari";
}
if (!/Chrome\/\d+|Chromium\/\d+/.test(browserInfo)) {
return 'safari';
}
}
return None;
}
return null;
};

const AUDIENCES = {
mobile: () => window.innerWidth < 600,
desktop: () => window.innerWidth >= 600,
// chrome: () => detectBrowser() === "chrome",
// safari: () => detectBrowser() === "safari",
chrome: () => detectBrowser() === 'chrome',
safari: () => detectBrowser() === 'safari',
};

/**
Expand Down Expand Up @@ -132,8 +131,8 @@ async function loadEager(doc) {
|| Object.keys(getAllMetadata('campaign')).length
|| Object.keys(getAllMetadata('audience')).length) {
// eslint-disable-next-line import/no-relative-packages
const { loadEager } = await import('../plugins/experimentation/src/index.js');
await loadEager(document, { audiences: AUDIENCES }, pluginContext);
const { loadEager: runEager } = await import('../plugins/experimentation/src/index.js');
await runEager(document, { audiences: AUDIENCES }, pluginContext);
}
document.documentElement.lang = 'en';
decorateTemplateAndTheme();
Expand Down

0 comments on commit fd358b6

Please sign in to comment.