Skip to content

feat(send-to-caas): support CTA URL localization via caasLocaleInject metadata flag #4538

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

Open
wants to merge 3 commits into
base: stage
Choose a base branch
from

Conversation

sanrai
Copy link
Contributor

@sanrai sanrai commented Jul 10, 2025

Description

This change adds the ability to automatically prepend the page's locale segment to primary and secondary CTA URLs when a page is localized, controlled by a new metadata flag.

Previously, localization logic was missed in the post-processing step in getCaaSMetadata(). We've refactored it so the locale injection is scoped entirely to the CTA URL computations in send-utils.js, making the metadata builder itself simpler and preserving its original responsibility.

Resolves: MWPW-167994

What's Changed

  • Introduce localizeCtaUrl(val) helper (in tools/send-to-caas/send-utils.js)
    • Reads <meta name="caaslocaleinject" content="true"> (case‐sensitive)
    • Uses getPageLocale(window.location.pathname) to detect if the page is localized
    • Wraps the output of checkCtaUrl(...) for both cta1url and cta2url
    • Prepends /${locale} to the URL path only once, if not already localized
  • Refactored props.cta1url and props.cta2url to call localizeCtaUrl(checkCtaUrl(...))
  • Simplified path logic to a single assignment, since URL.pathname always begins with "/"
  • Ensured the metadata flag value is lowercased when read, matching how the backend emits it

Why

  • Encapsulates locale injection solely at the CTA prop level, keeping the core CaaS metadata builder untouched
  • Improves code clarity and maintainability by localizing complexity to a single helper
  • Honors pages that have not been localized (default/global pages remain unaffected unless the metadata flag is set)

To test

Author a word doc and put some already localized links and others not.
image

Toggle this caasLocaleInject parameter (either omit it for legacy consumers or let it be true for consumers who need this)
image

You will see the unlocalized link localized and the localized link stay the same.
image

Test URLs:

Copy link
Contributor

aem-code-sync bot commented Jul 10, 2025

Hello, I'm the AEM Code Sync Bot and I will run some actions to deploy your branch and validate page speed.
In case there are problems, just click a checkbox below to rerun the respective action.

  • Re-run PSI checks
  • Re-sync branch
Commits

@sanrai sanrai changed the title Mwpw 167994 MWPW-167994: a Jul 10, 2025
@sanrai sanrai changed the title MWPW-167994: a feat(send-to-caas): support CTA URL localization via caasLocaleInject metadata flag Jul 10, 2025
Copy link
Contributor

aem-code-sync bot commented Jul 10, 2025

Page Scores Audits Google
📱 /drafts/sanrai/foo?martech=off PERFORMANCE A11Y SEO BEST PRACTICES SI FCP LCP TBT CLS PSI
🖥️ /drafts/sanrai/foo?martech=off PERFORMANCE A11Y SEO BEST PRACTICES SI FCP LCP TBT CLS PSI

@sanrai sanrai added caas-configurator CaaS Configurator CaaS CaaS related code @caas labels Jul 10, 2025
Copy link
Contributor

This pull request is not passing all required checks. Please see this discussion for information on how to get all checks passing. Inconsistent checks can be manually retried. If a test absolutely can not pass for a good reason, please add a comment with an explanation to the PR.

@sanrai sanrai removed CaaS CaaS related code caas-configurator CaaS Configurator @caas labels Jul 11, 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.

2 participants