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.

Simplify client-side script code examples

Tim Wilson14e9774b449e
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/analytics/use-dynamic-guide.ts b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/analytics/use-dynamic-guide.ts
index 7cf07bd185..c66513da0d 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/analytics/use-dynamic-guide.ts
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/analytics/use-dynamic-guide.ts
@@ -11,7 +11,7 @@ export function useDynamicGuide(
) {
const { guideMarkdown: guideMarkdownRaw, error } = useGuide(guide, swrOpts);
- const { publishableKey } = useWorkspace();
+ const { publishableKey, defaultProgramId } = useWorkspace();
const { program } = useProgram();
const [siteVisitTrackingEnabled] = useWorkspaceStore<boolean>(
@@ -77,8 +77,21 @@ export function useDynamicGuide(
// Clean up other attributes
const otherAttrs = afterSrc.replace(/>$/, "").trim();
+ const domainsConfigParts = [
+ ...(program ? [`"refer": "${program.domain}"`] : []),
+ ...(domainTrackingEnabled
+ ? [`"outbound": ["example.com", "example.sh"]`]
+ : []),
+ ].join(`, `);
+ const parts = [
+ `data-publishable-key="${publishableKey}"`,
+ ...(domainsConfigParts
+ ? [`data-domains='{${domainsConfigParts}}'`]
+ : []),
+ ].join(`\n${indent}`);
+
// Return: before src, src, publishable-key, other attrs, closing tag
- return `${beforeSrc}${srcAttr}\n${indent}data-publishable-key="${publishableKey}"${otherAttrs ? `\n${indent}${otherAttrs}` : ""}\n${indent}${closingTag}`;
+ return `${beforeSrc}${srcAttr}\n${indent}${parts}${otherAttrs ? `\n${indent}${otherAttrs}` : ""}\n${closingTag}`;
},
)
// for React applications - add publishableKey prop after <DubAnalytics
@@ -94,7 +107,23 @@ export function useDynamicGuide(
if (context.includes("publishableKey")) return match;
}
}
- return `${indent}${tag}\n${indent} publishableKey="${publishableKey}"${rest}`;
+
+ const domainsConfigParts = [
+ ...(program ? [`refer: "${program.domain}"`] : []),
+ ...(domainTrackingEnabled
+ ? [`outbound: ["example.com", "example.sh"]`]
+ : []),
+ ].join(`,\n${indent} `);
+ const parts = [
+ `publishableKey="${publishableKey}"`,
+ ...(domainsConfigParts
+ ? [
+ `domainsConfig={{\n${indent} ${domainsConfigParts}\n${indent} }}`,
+ ]
+ : []),
+ ].join(`\n ${indent}`);
+
+ return `${indent}${tag}\n${indent} ${parts}${rest}`;
},
)
// for GTM installations - add data-publishable-key after script.src
diff --git a/apps/web/guides/framer.md b/apps/web/guides/framer.md
index 298b2a4781..8bd982c48c 100644
--- a/apps/web/guides/framer.md
+++ b/apps/web/guides/framer.md
@@ -12,13 +12,3 @@ Follow these steps to add Dub client-side script to your Framer site:
src="https://www.dubcdn.com/analytics/script.js"
></script>
```
-
-If you're using [Dub Partners](https://dub.co/docs/partners/quickstart) for affiliate management, you will also need to set up the `data-domains` property to enable [client-side click-tracking](https://dub.co/docs/sdks/client-side/features/client-side-click-tracking).
-
-```html
-<script
- defer
- src="https://www.dubcdn.com/analytics/script.js"
- data-domains='{"refer":"yourcompany.link"}'
-></script>
-```
diff --git a/apps/web/guides/manual-client-sdk.md b/apps/web/guides/manual-client-sdk.md
index 5ca3eafe7e..d5b82e6823 100644
--- a/apps/web/guides/manual-client-sdk.md
+++ b/apps/web/guides/manual-client-sdk.md
@@ -7,13 +7,3 @@ You can add the Dub client-side script to your website same way you would add Go
src="https://www.dubcdn.com/analytics/script.js"
></script>
```
-
-If you're using [Dub Partners](https://dub.co/docs/partners/quickstart) for affiliate management, you will also need to set up the `data-domains` property to enable [client-side click-tracking](https://dub.co/docs/sdks/client-side/features/client-side-click-tracking).
-
-```html
-<script
- defer
- src="https://www.dubcdn.com/analytics/script.js"
- data-domains='{"refer":"yourcompany.link"}'
-></script>
-```
diff --git a/apps/web/guides/react.md b/apps/web/guides/react.md
index 1107b833c1..c26a46930e 100644
--- a/apps/web/guides/react.md
+++ b/apps/web/guides/react.md
@@ -30,26 +30,3 @@ export default function RootLayout({
);
}
```
-
-If you’re using [Dub Partners](https://dub.co/docs/partners/quickstart) for your affiliate program, you will also need to set the [`domainsConfig.refer` property](https://dub.co/docs/sdks/client-side/installation-guides/react#param-domains-config) to the short link domain you're using on Dub to enable [client-side click-tracking](https://dub.co/docs/sdks/client-side/features/click-tracking).
-
-```jsx
-import { Analytics as DubAnalytics } from '@dub/analytics/react';
-
-export default function RootLayout({
- children,
-}: Readonly<{
- children: React.ReactNode;
-}>) {
- return (
- <html lang="en">
- <body>{children}</body>
- <DubAnalytics
- domainsConfig={{
- refer: "yourcompany.link"
- }}
- />
- </html>
- );
-}
-```
diff --git a/apps/web/guides/webflow.md b/apps/web/guides/webflow.md
index eb2becb005..f1a77e743a 100644
--- a/apps/web/guides/webflow.md
+++ b/apps/web/guides/webflow.md
@@ -11,13 +11,3 @@ Follow these steps to add Dub client-side script to your Webflow site:
src="https://www.dubcdn.com/analytics/script.js"
></script>
```
-
-If you're using [Dub Partners](https://dub.co/docs/partners/quickstart) for affiliate management, you will also need to set up the `data-domains` property to enable [client-side click-tracking](https://dub.co/docs/sdks/client-side/features/client-side-click-tracking).
-
-```html
-<script
- defer
- src="https://www.dubcdn.com/analytics/script.js"
- data-domains='{"refer":"yourcompany.link"}'
-></script>
-```
diff --git a/apps/web/guides/wordpress.md b/apps/web/guides/wordpress.md
index c59def85e0..7aac8229b1 100644
--- a/apps/web/guides/wordpress.md
+++ b/apps/web/guides/wordpress.md
@@ -12,13 +12,3 @@ Follow these steps to add the Dub client-side script to your WordPress site:
src="https://www.dubcdn.com/analytics/script.js"
></script>
```
-
-If you're using [Dub Partners](https://dub.co/docs/partners/quickstart) for affiliate management, you will also need to set up the `data-domains` property to enable [client-side click-tracking](https://dub.co/docs/sdks/client-side/features/client-side-click-tracking).
-
-```html
-<script
- defer
- src="https://www.dubcdn.com/analytics/script.js"
- data-domains='{"refer":"yourcompany.link"}'
-></script>
-```