Skip to content

Commit

Permalink
Squashed 'plugins/experience-decisioning/' changes from f602282..be2e07d
Browse files Browse the repository at this point in the history
be2e07d doc: update README.md
287e35f feat: adopt the plugin api (#2)
9028520 fix: possible css leaking into pill overlay
162aab2 fix: improve anonymization for better gdpr/hippa compliance (#3)
0071dbd fix: audience pill activation
a486023 fix: audience parsing
4789afd feat: limit the sampling rate
7fbef36 feat: limit the sampling rate (#1)
92e2abb fix: campaigns parsing
4467d3e fix: block-level experiments resolution
4438f52 doc: update readme
44a3aa4 fix: support installation in sub-directories
a77433f style: properly inherit text color in the overlay

git-subtree-dir: plugins/experience-decisioning
git-subtree-split: be2e07ddce1d9c8d1622e6221f7a16593d87b811
  • Loading branch information
ramboz committed Oct 27, 2023
1 parent 9ef00bf commit 59aea1e
Show file tree
Hide file tree
Showing 5 changed files with 163 additions and 98 deletions.
41 changes: 37 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,33 @@ If you prefer using `https` links you'd replace `git@github.com:adobe/aem-experi

## Project instrumentation

### On top of the plugin system

The easiest way to add the plugin is if your project is set up with the plugin system extension in the boilerplate.
You'll know you have it if `window.hlx.plugins` is defined on your page.

If you don't have it, you can follow the proposal in https://github.com/adobe/aem-lib/pull/23 and apply the changes to your `aem.js`/`lib-franklin.js`.

Once you have confirmed this, you'll need to edit your `scripts.js` in your AEM project and add the following at the start of the file:
```js
const AUDIENCES = {
mobile: () => window.innerWidth < 600,
desktop: () => window.innerWidth >= 600,
// define your custom audiences here as needed
};

window.hlx.plugins.add('experience-decisioning', {
condition: () => getMetadata('experiment')
|| Object.keys(getAllMetadata('campaign')).length
|| Object.keys(getAllMetadata('audience')).length,
options: { audiences: AUDIENCES },
load: 'eager',
url: '/plugins/experience-decisioning/src/index.js',
});
```

### Without the plugin system

To properly connect and configure the plugin for your project, you'll need to edit your `scripts.js` in your AEM project and add the following:

1. at the start of the file:
Expand Down Expand Up @@ -77,7 +104,7 @@ To properly connect and configure the plugin for your project, you'll need to ed
|| Object.keys(getAllMetadata('audience')).length) {
// eslint-disable-next-line import/no-relative-packages
const { loadEager: runEager } = await import('../plugins/experience-decisioning/src/index.js');
await runEager.call(pluginContext, { audiences: AUDIENCES });
await runEager(document, { audiences: AUDIENCES }, pluginContext);
}
}
Expand All @@ -90,11 +117,10 @@ To properly connect and configure the plugin for your project, you'll need to ed
// Add below snippet at the end of the lazy phase
if ((getMetadata('experiment')
|| Object.keys(getAllMetadata('campaign')).length
|| Object.keys(getAllMetadata('audience')).length)
&& (window.location.hostname.endsWith('hlx.page') || window.location.hostname === ('localhost'))) {
|| Object.keys(getAllMetadata('audience')).length)) {
// eslint-disable-next-line import/no-relative-packages
const { loadLazy: runLazy } = await import('../plugins/experience-decisioning/src/index.js');
await runLazy.call(pluginContext, { audiences: AUDIENCES });
await runLazy(document, { audiences: AUDIENCES }, pluginContext);
}
}
```
Expand All @@ -107,6 +133,13 @@ You have already seen the `audiences` option in the examples above, but here is

```js
runEager.call(pluginContext, {
// Overrides the base path if the plugin was installed in a sub-directory
basePath: '',
// Lets you configure if we are in a prod environment or not
// (prod environments do not get the pill overlay)
isProd: () => window.location.hostname.endsWith('hlx.page')
|| window.location.hostname === ('localhost')

/* Generic properties */
// RUM sampling rate on regular AEM pages is 1 out of 100 page views
// but we increase this by default for audiences, campaigns and experiments
Expand Down
Loading

0 comments on commit 59aea1e

Please sign in to comment.