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

MWPW-146528[MILO][MEP][ANALYTICS] Add attribute to content changed by Target for analytics and MWPW-152274 #2593

Merged
merged 59 commits into from
Jul 24, 2024

Conversation

markpadbe
Copy link
Contributor

@markpadbe markpadbe commented Jul 18, 2024

In Dexter, there are scripts that add analytics to portions of a page that have been updated by Target. These scripts key off an attribute added by the testing library the T&O team uses. As pages migrate to milo, these scripts need the attribute once again.

  • add data-adobe-target-testid to elements updated by mep, but only when chosen experience is a Target experience.
  • moved some mep-related code from fragment.js, utils.js and martech.js to personalization.js
  • added an init function to personalization.js to handle some of the logic that used to be in utils/utils.js
  • updated unit tests to use the init function
  • added unit tests around new functionality
  • removed getExpFromParam function since it was preliminary version of the mep parameter and is no longer used

Resolves: MWPW-146528
Also resolves:
MWPW-152274 Move entitlements.js request up to happen while waiting on sstats / etc.
MWPW-152275 Move manifest.json request up while waiting on sstats / etc.
MWPW-154998 [MEP][MILO] Manifests do not execute in the right order when there is a disabled manifest

Instructions for testing:
Use the MEP button to switch between experiences. For each, copy and paste the following into the console: document.querySelectorAll('[data-adobe-target-testid]')

In the before link, no experience will have elements with the attributes.

Test URLs:
--Before: https://main--cc--adobecom.hlx.page/drafts/mepdev/fragments/2024/q3/addanalyticsattribute/addanalyticsattribute
--After: https://main--cc--adobecom.hlx.page/drafts/mepdev/fragments/2024/q3/addanalyticsattribute/addanalyticsattribute?milolibs=mepmovefromutils

In the after links, expected value for any found elements should be "myoverride" and the amount of found elements should match the numbers listed below.

Number of expected found elements by experience:
target-replacepage: 1
target-otheractions: 8
all others: 0

Test URLs:
--Before: https://main--cc--adobecom.hlx.page/drafts/mepdev/fragments/2024/q3/addanalyticsattribute/inblockgnavversion
--After: https://main--cc--adobecom.hlx.page/drafts/mepdev/fragments/2024/q3/addanalyticsattribute/inblockgnavversion?milolibs=mepmovefromutils

In the after links, expected value for any found elements should be "apples" and the amount of found elements should match the numbers listed below.

Number of expected found elements by experience:
target-block: 1
target-gnavfragment: 1
target-gnavchainfragments: 1
target-gnavwithinset: 2
all others: 0

Test URL for psi check:
https://mepmovefromutils--milo--adobecom.hlx.page/?martech=off

@markpadbe markpadbe requested a review from a team July 19, 2024 23:29
@vgoodric vgoodric changed the title MWPW-146528[MILO][MEP][ANALYTICS] Add attribute to content changed by Target for analytics MWPW-146528[MILO][MEP][ANALYTICS] Add attribute to content changed by Target for analytics and MWPW-152274 Jul 23, 2024
Copy link
Contributor

@chrischrischris chrischrischris left a comment

Choose a reason for hiding this comment

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

Nice!

libs/blocks/global-navigation/utilities/utilities.js Outdated Show resolved Hide resolved
…tc. (#2608)

* add preload

* shorten if and and conditional chaining

* run loop even if Target is off
}
export function addMepHighlightAndTargetId(el, source) {
let { manifestId, targetManifestId } = source.dataset;
manifestId ??= source?.closest('[data-manifest-id]')?.dataset?.manifestId;
Copy link
Contributor

Choose a reason for hiding this comment

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

??= is new for me. Never seen it used before =). Maybe consider that a lot of people are like me and also haven't seen it used and may be confused ;) I dunno, up to you

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@denlight, I take your point about the Nullish coalescing assignment operator (I had to look up the name up again today when Chris suggested it ;)), but it is nice and concise and we've already used in a couple of other places in personalization.js so let's keep it. Thanks.

@@ -424,24 +403,39 @@ const addHash = (url, newHash) => {
}
};

const setDataIdOnChildren = (sections, id, value) => {
[...sections[0].children].forEach(
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 know that sections[0] will always exist ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@denlight, @vivgoodrich, setDataIdOnChildren is only called within the updateFragDataProps function which is only called in the fragment.js init function. There is already a check for sections.length before the sections variable is passed into updateFragDataProps (fragment.js, line 102) so the current code is safe. I can come back to this in a future ticket, but I suggest we leave it as is tonight to avoid last second changes. Thanks.

…hen there is a disabled manifest (#2616)

* add default execution order

* unit test
@@ -424,24 +403,39 @@ const addHash = (url, newHash) => {
}
};

const setDataIdOnChildren = (sections, id, value) => {
[...sections[0].children].forEach(
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
[...sections[0].children].forEach(
if (!sections.length) return;
[...sections[0].children].forEach(

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@vivgoodrich, please see comment above.

@milo-pr-merge
Copy link
Contributor

milo-pr-merge bot commented Jul 24, 2024

Error merging 2593: MWPW-146528[MILO][MEP][ANALYTICS] Add attribute to content changed by Target for analytics and MWPW-152274 file is not defined

@mokimo mokimo merged commit c5fcc8e into stage Jul 24, 2024
12 checks passed
@mokimo mokimo deleted the mepmovefromutils branch July 24, 2024 08:06
rohitsahu pushed a commit to rohitsahu/milo that referenced this pull request Jul 26, 2024
* stage:
  MWPW-154998 [MEP][MILO] Manifests do not execute in the right order when there is a disabled manifest (adobecom#2632)
  mwpw-154965: Fetch federal stage content from hlx.page instead of stage.adobe.com (adobecom#2618)
  Correct error messages for duplicate files on the stage to main workflow (adobecom#2621)
  MWPW-153245 [merch][analytics] dispatch wcomp events, and let default lh (adobecom#2610)
  Revert "MWPW-146528[MILO][MEP][ANALYTICS] Add attribute to content changed by Target for analytics and MWPW-152274" (adobecom#2627)
  MWPW-128600 Locale Tool: Langstore points to langstore/en (adobecom#2615)
  Fix for errors in dynamically loaded scripts in test cases (adobecom#2619)
  MWPW-146528[MILO][MEP][ANALYTICS] Add attribute to content changed by Target for analytics and MWPW-152274 (adobecom#2593)
  Bootstrapper script for milo feds blocks (adobecom#2560)
  Revert "[MWPW-152968] mWeb - Passing ECID to Branch.io banner - Implementation" (adobecom#2612)
  MWPW-146743 Improve Article Header Performance (adobecom#2577)
  MWPW-153808: fix duplicate tax label (adobecom#2614)
  MWPW-154026: Long CTAs fall in the second line in merch card footer (adobecom#2565)
  Revert "[MWPW-154795] Style Feds Global-footer region picker drop-up variant (without hash)" (adobecom#2611)
  [AUTOMATED-PR] Update imslib.min.js dependency (adobecom#2605)
  [MWPW-154795] Style Feds Global-footer region picker drop-up variant (without hash) (adobecom#2599)
  MWPW-143053 [MEP] Request for New Personalization Tag - CC Paid (adobecom#2604)
  [MWPW-152674] [Gray Box] Desktop gnav not hidden when device view is open (adobecom#2597)
  MWPW-150566 - 🆕 Editorial-Card block (adobecom#2533)

# Conflicts:
#	libs/deps/merch-card.js
rohitsahu pushed a commit to rohitsahu/milo that referenced this pull request Jul 30, 2024
* stage:
  [MWPW-153611] [Gray Box] environment aware links (adobecom#2622)
  MWPW-153580: Add Opt-In Feature for CaaS Badge Display (adobecom#2625)
  [MWPW-154335] [callout] Spacing issue encountered when the call-out section is added (adobecom#2628)
  MWPW-150557 - Split Marquee CLS issues on consuming sites (adobecom#2636)
  Mwpw 147034: Custom border color + badge/border color decoupling [merch card] (adobecom#2613)
  [MWPW-151517] - Remove condition for promobar hidden on mobile from gnav (adobecom#2538)
  MWPW-154998 [MEP][MILO] Manifests do not execute in the right order when there is a disabled manifest (adobecom#2632)
  mwpw-154965: Fetch federal stage content from hlx.page instead of stage.adobe.com (adobecom#2618)
  Correct error messages for duplicate files on the stage to main workflow (adobecom#2621)
  MWPW-153245 [merch][analytics] dispatch wcomp events, and let default lh (adobecom#2610)
  Revert "MWPW-146528[MILO][MEP][ANALYTICS] Add attribute to content changed by Target for analytics and MWPW-152274" (adobecom#2627)
  MWPW-128600 Locale Tool: Langstore points to langstore/en (adobecom#2615)
  Fix for errors in dynamically loaded scripts in test cases (adobecom#2619)
  MWPW-146528[MILO][MEP][ANALYTICS] Add attribute to content changed by Target for analytics and MWPW-152274 (adobecom#2593)
  Bootstrapper script for milo feds blocks (adobecom#2560)
  Revert "[MWPW-152968] mWeb - Passing ECID to Branch.io banner - Implementation" (adobecom#2612)

# Conflicts:
#	libs/deps/merch-card.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ready for Stage run-nala Run Nala Test Automation against PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants