-
Notifications
You must be signed in to change notification settings - Fork 169
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-161845: basic analytics on mas cards #3206
base: ccd
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,9 @@ const DEFAULT_BADGE_COLOR = '#000000'; | |
const DEFAULT_BADGE_BACKGROUND_COLOR = '#F8D904'; | ||
const CHECKOUT_LINK_STYLE_PATTERN = | ||
/(accent|primary|secondary)(-(outline|link))?/; | ||
export const ANALYTICS_TAG = 'mas:product_code/'; | ||
export const ANALYTICS_LINK_ATTR = 'daa-ll'; | ||
export const ANALYTICS_SECTION_ATTR = 'daa-lh'; | ||
|
||
function processFragment(fragmentData) { | ||
return fragmentData.fields.reduce( | ||
|
@@ -222,6 +225,17 @@ export function processCTAs(fragment, merchCard, aemFragmentMapping, variant) { | |
} | ||
} | ||
|
||
export function processAnalytics(fragment, merchCard) { | ||
const { tags } = fragment; | ||
const cardAnalyticsId = tags?.find(tag => tag.startsWith(ANALYTICS_TAG))?.split('/').pop(); | ||
if(cardAnalyticsId) { | ||
merchCard.setAttribute(ANALYTICS_SECTION_ATTR, cardAnalyticsId); | ||
merchCard.querySelectorAll(`a[data-analytics-id]`).forEach((link, index) => { | ||
link.setAttribute(ANALYTICS_LINK_ATTR, `${link.dataset.analyticsId}-${index + 1}`); | ||
}); | ||
} | ||
} | ||
|
||
export async function hydrate(fragmentData, merchCard) { | ||
const fragment = processFragment(fragmentData); | ||
const { variant } = fragment; | ||
|
@@ -237,6 +251,7 @@ export async function hydrate(fragmentData, merchCard) { | |
merchCard.removeAttribute('badge-color'); | ||
merchCard.removeAttribute('badge-text'); | ||
merchCard.removeAttribute('size'); | ||
merchCard.removeAttribute(ANALYTICS_SECTION_ATTR); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, i finally understood that it is here to reflect actual state of the fragment.
in between basically implies that we need, for each field, 2 places (preprocess & process ?), may be we need subfile / class that has those 2 methods. May be not for this PR :) cc @yesil |
||
|
||
merchCard.variant = variant; | ||
await merchCard.updateComplete; | ||
|
@@ -260,4 +275,5 @@ export async function hydrate(fragmentData, merchCard) { | |
processPrices(fragment, merchCard, aemFragmentMapping.prices); | ||
processDescription(fragment, merchCard, aemFragmentMapping.description); | ||
processCTAs(fragment, merchCard, aemFragmentMapping, variant); | ||
processAnalytics(fragment, merchCard); | ||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❤️ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
File ignored because of a matching ignore pattern. Use "--no-ignore" to override.