Skip to content

@W-17643479@ Add page meta data to search results and product pages#2232

Merged
vcua-mobify merged 5 commits intodevelopfrom
add-page-meta-tags
Feb 4, 2025
Merged

@W-17643479@ Add page meta data to search results and product pages#2232
vcua-mobify merged 5 commits intodevelopfrom
add-page-meta-tags

Conversation

@vcua-mobify
Copy link
Contributor

@vcua-mobify vcua-mobify commented Jan 31, 2025

SCAPI products and search results can now return page meta tags that have been configured in Business Manager.

This PR updates the PDP and PLP to include any page meta data that is available.

Testing the changes:
Start the app

(Note: The meta tags may appear before or after the style tags so you may want to check both locations)
Search:
Search for a product (ie. shirt)
In dev tools, view the network request and see 'pageMetaTags` is included in the search results
View the HTML header and see that the page meta tags have been added

Category:
Navigate to a category page
In dev tools, view the network request and see 'pageMetaTags` is included in the search results
View the HTML header and see that the page meta tags have been added

Product detail:
Navigate to a PDP
In dev tools, view the network request and see 'pageMetaTags` is included in the product data
View the HTML header and see that the page meta tags have been added

@vcua-mobify vcua-mobify marked this pull request as ready for review January 31, 2025 19:17
@vcua-mobify vcua-mobify requested a review from a team as a code owner January 31, 2025 19:17
<Helmet>
<title>{product?.pageTitle}</title>
<meta name="description" content={product?.pageDescription} />
{product?.pageMetaTags ? (
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a scenario where pageMetaTags is included in the response but is empty, and we would want to fall back to pageDescription?

Suggested change
{product?.pageMetaTags ? (
{product?.pageMetaTags?.length ? (

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think it will ever be empty (the PDP meta data is auto generated based on other properties of the product so I think there'll always be something) but having extra safety is good so I'll add this change.

Screenshot 2025-02-03 at 3 29 33 PM

Comment on lines +459 to +468
{product?.pageMetaTags ? (
// description is one of the page meta tags returned for products
// and this is the same as product?.pageDescription
product.pageMetaTags?.map((pageMetaTag) => {
const name = pageMetaTag.id
const content = pageMetaTag.value
return <meta name={name} content={content} key={name} />
})
) : (
<meta name="description" content={product?.pageDescription} />
Copy link
Contributor

Choose a reason for hiding this comment

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

Similarly, I think we should also consider the scenario where the pageMetaTags does not include a description key. In that case, the code will fall back to using the pageDescription.

Suggested change
{product?.pageMetaTags ? (
// description is one of the page meta tags returned for products
// and this is the same as product?.pageDescription
product.pageMetaTags?.map((pageMetaTag) => {
const name = pageMetaTag.id
const content = pageMetaTag.value
return <meta name={name} content={content} key={name} />
})
) : (
<meta name="description" content={product?.pageDescription} />
{product?.pageMetaTags?.length > 0 && product.pageMetaTags.map(({ id, value }) => (
<meta name={id} content={value} key={id} />
))}
{/* Fallback for description if not included in pageMetaTags */}
{!product?.pageMetaTags?.some(tag => tag.id === 'description') && product?.pageDescription && (
<meta name="description" content={product.pageDescription} />

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My understanding is that the description meta tag is generated from the product description so they will always be the same value. But I can add this fallback just in case.

Copy link
Contributor

Choose a reason for hiding this comment

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

Should the meta title be consistent with the content of the <title> tag, or default to product.pageTitle if the meta title is not provided?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unlike with description, the title meta tag and page title do appear to be different. (It seems that the title meta tag is generated based on the page title, the price, and the site id?)

I think using the page title as the title is more straightforward as what you enter in BM is what you'll get with no extras added.

@vcua-mobify vcua-mobify requested a review from adamraya February 3, 2025 23:43
Copy link
Contributor

@adamraya adamraya left a comment

Choose a reason for hiding this comment

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

Thanks for addressing edge cases. +1 Looks good to me.

Copy link
Contributor

@joeluong-sfcc joeluong-sfcc left a comment

Choose a reason for hiding this comment

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

LGTM, was able to manually confirm that both PDP and PLP SCAPI calls include the page_meta_tags in the expand query parameter, and that the data from the pageMetaTags property in the response is able to be found in the meta tags on the DOM

@vcua-mobify vcua-mobify merged commit 4467268 into develop Feb 4, 2025
39 checks passed
vcua-mobify added a commit that referenced this pull request Feb 12, 2025
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.

4 participants