[CDX-277] Add missing Data-Attributes#189
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds missing Constructor.io data attributes to improve tracking capabilities across product cards and PLP containers. The changes ensure proper attribution for sponsored listings, search terms, zero-result states, and conversion actions.
- Conditionally adds data attributes for price, variation ID, and sponsored listing information to product cards
- Adds search term, zero-result, and section attributes to PLP containers with proper loading state handling
- Introduces a new helper function for conversion button tracking attributes
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
src/utils/dataAttributeHelpers.ts |
Enhanced data attribute helpers to support optional item parameter, conditional attributes, and added new conversion button helper function |
src/hooks/useCioPlp.ts |
Extracted status variable and passed loading state to PLP container attributes function |
src/components/ProductCard/ProductCard.tsx |
Updated to pass item to data attributes function and added conversion tracking to add-to-cart button |
spec/utils.test.tsx |
Added comprehensive test coverage for new data attribute functions and edge cases |
spec/components/ProductCard/productCard.test.js |
Added tests to verify data attributes are properly rendered on product cards |
spec/components/CioPlpGrid/CioPlpGrid.test.jsx |
Updated import statement and added assertion for zero-result attribute |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
evanyan13
left a comment
There was a problem hiding this comment.
Hi @Alexey-Pavlov
Thank you for working on the changes!
Left quite a few comments for your consideration please 😄
Co-authored-by: Evan Yan <[email protected]>
TarekAlQaddy
left a comment
There was a problem hiding this comment.
Thanks @Alexey-Pavlov and @evanyan13!
LGTM! Left a minor comment but shouldn't be a blocker
| const productCard = screen.getByRole('link'); | ||
| expect(productCard.getAttribute(cnstrcDataAttrs.common.itemId)).toBe(item.itemId); | ||
| expect(productCard.getAttribute(cnstrcDataAttrs.common.itemName)).toBe(item.itemName); | ||
| expect(productCard.getAttribute(cnstrcDataAttrs.common.itemPrice)).toBeTruthy(); |
There was a problem hiding this comment.
Is there a reason why we are not checking on the exact value here?
There was a problem hiding this comment.
could you add additional test to check that the price / variation data attributes don't exist when they are not provided as they are conditional
There was a problem hiding this comment.
Done, thank you!
Code Review Results✅ StrengthsThe PR systematically refactors data attributes into a centralized configuration object (cnstrcDataAttrs), improving maintainability and reducing hardcoded strings across the codebase. 🚨 Critical IssuesNone identified.
|
No description provided.