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

Research-AEM CS #47

Draft
wants to merge 7 commits into
base: v2
Choose a base branch
from
Draft

Research-AEM CS #47

wants to merge 7 commits into from

Conversation

FentPams
Copy link
Contributor

@FentPams FentPams commented Nov 11, 2024

Description

This branch is for research use to track the integration of the experimentation engine within AEM CS

Pramod's repo =>
https://git.corp.adobe.com/pramodh/aemsite/tree/ootb-eds-experiment

Latest version Nov 15th

nov.15.mov

Nov 15 Updates

  • Solve selector issue on controller and variant page
    • Controller page: target correct component (with unique experiment id) and do replacement based on provided variant urls
    • Variant page: elements can be selected by using body > div as selector.

Nov 15 Issue Explanation:

Pseudo markup:

<div data-experiment = "e1" class="c1"> ... </div>
<div data-experiment = "e2" class="c1"> ... </div>

Two overlaypills will be generated, but all target the first div. Cause is when elements sharing same class (e.g. .cmp-image), in the case only the first element will be selected.

The screenshot:
Screenshot 2024-11-11 at 12 25 58 PM
Screenshot 2024-11-11 at 12 25 53 PM

Solutions Exploration:

Taken Suggestions:
Wrap the selector with more specific way, including its parent/ancestor's ID/class getSelectorForElement()

@FentPams FentPams requested a review from ramboz November 11, 2024 21:02
@ramboz ramboz changed the base branch from main to v2 November 11, 2024 22:27
src/index.js Outdated
let isDebugEnabled;
export function setDebugMode(url, pluginOptions) {
function setDebugMode(url, pluginOptions) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we really need to remove the exports?

Copy link
Contributor Author

@FentPams FentPams Nov 11, 2024

Choose a reason for hiding this comment

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

There were errs complaining about export when I tested in my local. Unexpected token 'export' (at clientlib-experimentation.lc-4153cffb83deab11322f9511383920a0-lc.js:209:1)
From my research, the error occurs because my AEM environment doesn't have a module bundler like we had <script src="/scripts/scripts.js" type="module"></script> in EDS project.

Pramod confirmed natively there is no module type, and need to transpile using webpack.
Same reason as the below import ued.js. I commented out for testing, Pramod will have it back in AEM.

Copy link
Contributor

Choose a reason for hiding this comment

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

We'd need to adjust this on the AEM side then so we can use the codebase as-is. The exports are needed both for unit testing and also to offer a proper granular API to the consumers.

We could theoretically compile/transpile the JS as needed in AEM using the proper google closure compiler settings in the clientlib config.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the idea, we will try the google closure compiler way :)

src/index.js Outdated Show resolved Hide resolved
src/index.js Outdated Show resolved Hide resolved
src/index.js Outdated Show resolved Hide resolved
src/index.js Outdated Show resolved Hide resolved
src/index.js Outdated Show resolved Hide resolved
src/index.js Outdated
@@ -723,9 +697,10 @@ async function getExperimentConfig(pluginOptions, metadata, overrides) {
config.selectedVariant = toClassName(overrides.variant);
} else {
// eslint-disable-next-line import/extensions
const { ued } = await import('./ued.js');
Copy link
Contributor

Choose a reason for hiding this comment

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

We'll need to keep this 😉 otherwise A/B testing will only ever serve "A" and not "B"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same reason as deleting the export key word, no module type support :(

Copy link
Contributor

Choose a reason for hiding this comment

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

That's a client lib config we can change. It just defaults to old ES5 code compliance, but we can bump this to ES6 and leverage modules if we want to

src/index.js Outdated Show resolved Hide resolved
src/index.js Outdated Show resolved Hide resolved
src/index.js Outdated Show resolved Hide resolved
src/index.js Outdated
// Challenge: experience fragment where CSS class may be different for each variation
function convertToVariantSelector(selector) {
const componentType = selector.match(/\.([\w-]+):/g)?.pop()?.replace(/[:.]/g, '') || '';
return `.cmp-${componentType}`;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not a fan of the hard-coded prefix here… this makes it dependent on the actual markup.

Copy link
Contributor Author

@FentPams FentPams Nov 15, 2024

Choose a reason for hiding this comment

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

You are right, my initial purpose is AEM engineer could define what the selector is by changing this function, and minimize other code changes.

After I synced up with Pramod this morning, we found every element could have its unique URI (the text has its url just has text div in its body, the image has its url just point to image, and the mix of them will have its url too), which from my understanding that we can simply fetch the element directly from the variant page 's body > div

But yes, I think the data-experiment-variant-selector could be a good idea, after your review, we will have current version for Pramod to test, if there are cases requiring variant selector to be declared in attributes, I'll further add that logic in 😉

src/index.js Outdated
// AEM CS experimentation modifications
const componentDataList = getAllMetadataAttributes(document, type);
await Promise.all(componentDataList.map(async (componentMetadata) => {
const { selector, variantSelector, ...metadata } = componentMetadata;
Copy link
Contributor

Choose a reason for hiding this comment

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

The variantSelector makes this pretty specific to AEM and not generic just based on data-* attributes anymore.
I'm also not convinced that the convertToVariantSelector will work (aside from the hardcoded prefix) it is returning a generic selector and you could have more than 1 on the page that is loaded.

I think leveraging something like data-experiment-variant-selector="…" that you specifically populate via some custom logic in AEM, and then leveraging that in the code instead of the extra variantSelector would likely be more generic and re-usable across different systems.

…the attributes: data-{scope}-* added in callback from runExperiment(),runCampaign(), serveAudience()
Copy link

codecov bot commented Nov 18, 2024

Codecov Report

Attention: Patch coverage is 80.00000% with 13 lines in your changes missing coverage. Please review.

Please upload report for BASE (v2@a072175). Learn more about missing BASE report.

Files with missing lines Patch % Lines
src/index.js 80.00% 9 Missing and 4 partials ⚠️
Additional details and impacted files
@@          Coverage Diff          @@
##             v2      #47   +/-   ##
=====================================
  Coverage      ?   92.63%           
=====================================
  Files         ?        1           
  Lines         ?      774           
  Branches      ?       16           
=====================================
  Hits          ?      717           
  Misses        ?       41           
  Partials      ?       16           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants