Skip to content

Commit

Permalink
address comments and add documentation for full redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
FentPams committed Aug 13, 2024
1 parent c54015f commit a1881b1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
11 changes: 11 additions & 0 deletions documentation/experiments.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,17 @@ Start and end dates are in the flexible JS [Date Time String Format](https://tc3

So you can both use generic dates, like `2024-01-31` or `2024/01/31`, and time-specific dates like `2024-01-31T13:37` or `2024/01/31 1:37 pm`. You can even enforce a specific timezone so your experiment activates when, say, it's 2am GMT+1 by using `2024/1/31 2:00 pm GMT+1` or similar notations.

#### Full redirects
For the use case that fully redirect to the target URL instead of just replacing the content, you could add a new property `Experiment Resolution | redirect` in page metadata:
| Metadata | |
|-----------------------|--------------------------------------------------------------|
| Experiment | Hero Test |
| Experiment Variants | [https://{ref}--{repo}--{org}.hlx.page/my-page-variant-1](), [https://{ref}--{repo}--{org}.hlx.page/my-page-variant-2](), [https://{ref}--{repo}--{org}.hlx.page/my-page-variant-3]() |
| Experiment Resolution | redirect

Same for the audience and campaign personalization, by adding the following property to redirect to target URL:
`Audience Resolution: redirect`
`Campaign Resolution: redirect`
### Section-level experiments

Each section in a page can also run 1 experiment, so you can have as many section-level experiments as you have sections.
Expand Down
9 changes: 5 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,13 +373,14 @@ function createModificationsHandler(
const url = await getExperienceUrl(ns.config);
let res;
if (url && new URL(url, window.location.origin).pathname !== window.location.pathname) {
if (metadata?.resolution === 'redirect') {
if (toClassName(metadata?.resolution) === 'redirect') {
// Firing RUM event early since redirection will stop the rest of the JS execution
fireRUM(type, config, pluginOptions, url);
window.location.replace(url);
} else {
// eslint-disable-next-line no-await-in-loop
res = await replaceInner(new URL(url, window.location.origin).pathname, el);
return null;
}
// eslint-disable-next-line no-await-in-loop
res = await replaceInner(new URL(url, window.location.origin).pathname, el);
} else {
res = url;
}
Expand Down

0 comments on commit a1881b1

Please sign in to comment.