Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

add “data” prop to <Embed />

Kiran Kea46beff5a5c
diff --git a/packages/embeds/core/src/constants.ts b/packages/embeds/core/src/constants.ts
index 587f60dfb8..745e5690e2 100644
--- a/packages/embeds/core/src/constants.ts
+++ b/packages/embeds/core/src/constants.ts
@@ -1,2 +1,2 @@
-export const EMBED_URL = "https://app.dub.co/embed/referrals";
+export const EMBED_REFERRALS_URL = "https://app.dub.co/embed/referrals";
export const DUB_CONTAINER_ID = "dub-embed-container";
diff --git a/packages/embeds/core/src/core.ts b/packages/embeds/core/src/core.ts
index 492a248e7b..581ee766bc 100644
--- a/packages/embeds/core/src/core.ts
+++ b/packages/embeds/core/src/core.ts
@@ -1,4 +1,4 @@
-import { DUB_CONTAINER_ID, EMBED_URL } from "./constants";
+import { DUB_CONTAINER_ID, EMBED_REFERRALS_URL } from "./constants";
import { EmbedError } from "./error";
import { DubEmbedOptions, DubInitResult, IframeMessage } from "./types";
@@ -27,7 +27,13 @@ class DubEmbed {
renderEmbed() {
console.debug("[Dub] Rendering embed.");
- const { token, root, containerStyles, onError } = this.options;
+ const {
+ token,
+ root,
+ containerStyles,
+ onError,
+ data = "referrals",
+ } = this.options;
const existingContainer = document.getElementById(DUB_CONTAINER_ID);
@@ -45,7 +51,14 @@ class DubEmbed {
...containerStyles,
});
- const iframe = createIframe(EMBED_URL, token);
+ const iframeUrl = data === "referrals" ? EMBED_REFERRALS_URL : "";
+
+ if (!iframeUrl) {
+ console.error("[Dub] Invalid embed data type.");
+ return null;
+ }
+
+ const iframe = createIframe(iframeUrl, token);
container.appendChild(iframe);
// Listen the message from the iframe
diff --git a/packages/embeds/core/src/types.ts b/packages/embeds/core/src/types.ts
index 1889156b53..c2536713ee 100644
--- a/packages/embeds/core/src/types.ts
+++ b/packages/embeds/core/src/types.ts
@@ -18,6 +18,8 @@ export type DubEmbedOptions = {
// The styles for the embed container
containerStyles?: Partial<CSSStyleDeclaration>;
+
+ data?: "referrals";
};
export interface IframeMessage {
diff --git a/packages/embeds/react/src/example/app.tsx b/packages/embeds/react/src/example/app.tsx
index f87af7053c..48ad04807f 100644
--- a/packages/embeds/react/src/example/app.tsx
+++ b/packages/embeds/react/src/example/app.tsx
@@ -15,7 +15,7 @@ const Embed = () => {
createToken();
}, []);
- return <DubEmbed token={token} />;
+ return <DubEmbed token={token} />;
};
ReactDom.render(<Embed />, document.getElementById("root"));