feat(frontend): Embeddable Campaign Widget component for partner websites - #1389
Merged
joelpeace48-cell merged 2 commits intoSep 25, 2026
Conversation
…lders (FinesseStudioLab#1219) Add lib/embedSnippet.js (validate options with the backend's rules, build /embed/v1/:widget/:campaignId URLs, and generate sandboxed <iframe> and React snippets) and a drop-in <TrivelaCampaignWidget> React component that renders the card/leaderboard/progress widget in a sandboxed, lazy iframe and renders nothing on invalid props.
…udioLab#1219) Replace the hard-coded dark-card iframe snippet with EmbedSnippetGenerator: partners pick widget type, theme and format (HTML iframe or React component) and copy the generated snippet. Adds component tests.
|
@abayomicornelius Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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.
Summary
Partners can now embed a Trivela campaign widget on their own sites either as a plain
<iframe>or as a drop-in React component, using snippets generated from the campaign page.The backend already serves sandbox-safe widget pages at
/embed/v1/:widgetType/:campaignId(card,leaderboard,progress). What was missing was the partner-facing side: the campaign page only offered one hard-coded dark-card iframe, and there was no React component.Changes
1.
frontend/src/lib/embedSnippet.js: snippet buildersvalidateEmbedOptions()applies the same rules the backend enforces inembedWidget.js, so a generated snippet never points at a URL the server rejects:card | leaderboard | progress, theme ∈dark | light;color;partnermatching[A-Za-z0-9_-]{1,64};orgtrimmed to 60 characters;limitfrom 1 to 50, ignored for other widgets.buildEmbedUrl(origin, options)builds the/embed/v1/...URL with encoded query parameters.buildIframeSnippet()produces a copy-paste iframe:loading="lazy"andreferrerpolicy="strict-origin-when-cross-origin";max-width:100%;allow-scripts allow-popups allow-popups-to-escape-sandboxcovers what the widgets need (their inline resize/postMessage script, and "Register on Trivela" opening in a new tab). It deliberately omitsallow-same-origin, so the widget can't access the host page.buildReactSnippet()produces a<TrivelaCampaignWidget …/>snippet listing only the props that are set.2.
frontend/src/components/TrivelaCampaignWidget.jsx: the React component<TrivelaCampaignWidget origin campaignId widget theme color partner org limit width height title className style />renders the widget in a sandboxed, lazy iframe.3.
frontend/src/components/EmbedSnippetGenerator.jsxinCampaignDetail.jsxpartnerattribution (?partner=) is supported by the builders and the component. Partners add their own id to the generated snippet.Tests (vitest)
src/lib/embedSnippet.test.js(7 tests):limitbounds;allow-same-originis absent;src/components/TrivelaCampaignWidget.test.jsx(3 tests):srcand size;npx vitest run src/lib/embedSnippet.test.js src/components/TrivelaCampaignWidget.test.jsx: 10/10 passing.Closes #1219
Closes #1228
Closes #1229
Closes #1220
Backward compatibility
/embed/campaign/:idand/embed/v1/*routes are untouched, so iframe snippets already published by partners keep working.