Add mParticle template targeting to tests - #1809
Merged
Merged
Conversation
Contributor
tomrf1
reviewed
Sep 11, 2026
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved moderate issues remain in profile gating and template matching and substitution.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Adds mParticle attribute targeting and template substitution for Banner and Epic A/B tests.
Changes:
- Extends schemas and props with mParticle template configuration.
- Adds profile matching and content substitution helpers.
- Integrates targeting and substitution into selection and routers with unit tests.
File summaries
| File | Reviewed changes |
|---|---|
src/shared/types/props/epic.ts |
Adds mParticle template props. |
src/shared/types/props/banner.ts |
Adds mParticle template props. |
src/shared/types/abTests/epic.ts |
Extends Epic test schema. |
src/shared/types/abTests/banner.ts |
Extends Banner test schema. |
src/server/tests/headers/headerSelection.test.ts |
Updates profile fixtures. |
src/server/tests/epics/epicSelection.ts |
Adds Epic template targeting. |
src/server/tests/banners/bannerSelection.ts |
Adds Banner template targeting. |
src/server/lib/targeting.test.ts |
Updates targeting fixtures. |
src/server/lib/mParticleTemplates.ts |
Implements matching and substitution. |
src/server/lib/mParticleTemplates.test.ts |
Tests template behavior. |
src/server/lib/mParticle.ts |
Supports optional profile attributes. |
src/server/api/epicRouter.ts |
Substitutes Epic content in responses. |
src/server/api/bannerRouter.ts |
Substitutes Banner content in responses. |
Review details
Suppressed comments (2)
src/server/lib/mParticleTemplates.ts:24
- Eligibility checks attribute keys case-sensitively, but substitution deliberately resolves them case-insensitively. For example, a configured
FIRST_NAMEwith a profile keyfirst_nameis rejected before the substitution that would have succeeded. Use the same case-insensitive key lookup for matching.
for (const template of mParticleTemplates) {
if (!mParticleProfile.user_attributes || !(template in mParticleProfile.user_attributes)) {
return false;
src/server/lib/mParticleTemplates.ts:74
- The spread preserves user-visible fields such as
cta.text, custom secondary-CTA text, and newslettersuccessDescriptionwithout substitution. Templates placed in any of those EpicVariant fields will therefore remain in the response; the variant helper needs to transform those nested content fields too.
return {
...epicVariant,
heading: updatedHeading,
paragraphs: updatedParagraphs,
highlightedText: updatedHighlightedText,
};
- Files reviewed: 13/13 changed files
- Comments generated: 5
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
tomrf1
reviewed
Sep 15, 2026
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this change?
This PR Introduces support for mParticle template personalisation in both Banners and epics. It allows for substitution of user attributes from mParticle profiles into banner and epic content, based on templates defined in A/B test configurations.
The changes:
mParticleTemplatesin both banner and epic A/B test schemas (bannerTestFromToolSchemaandepicTestFromToolSchema) and their corresponding props, allowing tests to specify which mParticle user attributes should be substituted into content.mParticleTemplates.tsto check for required user attributes (matchesMParticleTemplates) and to substitute attribute values into banner and epic content (substituteMParticleTemplate,substituteMParticleTemplateInBannerVariant,substituteMParticleTemplateInEpicVariant).Added unit tests for template matching and substitution, covering missing profiles, missing attributes, multiple substitutions, and regular tests that do not require mParticle attributes.
Why are we doing this PR?
Currently, Banner and Epic tests can't use mParticle attributes to personalise their content. Adding mParticle templates means we can personalise content using a user's mParticle attributes, such as first name or previous contribution amount.
How to test?
Tested locally using a stubbed mParticle profile.
MPARTICLE_STUB_PROFILE=trueso it uses the test profile instead of the mParticle API.MPARTICLE_ATTRIBUTES_containing an mParticle template and check that the template is replaced with the value from the test profile.MPARTICLE_ATTRIBUTES_in the name and check that the mParticle menu is not available and mParticle attributes are not required for variant selection.How can we measure success?
For this PR it is being able to select Banner and Epic variants based on whether a user has the required mParticle attributes, and correctly substitute those attributes into the content.
The wider goal is to enable personalised messaging for users with the right mParticle attributes, and measure the impact through conversion rate and LTV3 per impression.
Screenshots
Banner:
Epic:
Accessibility