Skip to content

Commit deafd1f

Browse files
committed
Load the script via a reverse proxy
1 parent 5f3f0d3 commit deafd1f

File tree

1 file changed

+69
-2
lines changed

1 file changed

+69
-2
lines changed

sdks/client-side/introduction.mdx

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ However, if you are installing the script on a subdomain (e.g. **app.example.com
5252

5353
```html Other
5454
<script
55-
src="https://cdn.dub.co/analytics.js"
55+
src="https://www.dubcdn.com/analytics/script.js"
5656
data-cookie-options='{"domain": ".example.com"}'
5757
/>
5858
```
@@ -74,13 +74,80 @@ By default, the script sets the `dub_id` cookie to expire in 90 days. You can cu
7474
7575
```html Other
7676
<script
77-
src="https://cdn.dub.co/analytics.js"
77+
src="https://www.dubcdn.com/analytics/script.js"
7878
data-cookie-options='{"expiresInDays": 60}'
7979
/>
8080
```
8181
8282
</CodeGroup>
8383
84+
### Load the script via a reverse proxy
85+
86+
To avoid ad-blockers from blocking the `@dub/analytics` script, it is recommended to use a reverse proxy.
87+
88+
Depending on which backend framework you're using, there are a few different ways to do this:
89+
90+
<CodeGroup>
91+
92+
```javascript Next.js
93+
// next.config.js
94+
module.exports = {
95+
async rewrites() {
96+
return [
97+
{
98+
source: "/_proxy/dub/script.js",
99+
destination: "https://www.dubcdn.com/analytics/script.js",
100+
},
101+
];
102+
},
103+
};
104+
```
105+
106+
```json Vercel
107+
// vercel.json
108+
{
109+
"rewrites": [
110+
{
111+
"source": "/_proxy/dub/script.js",
112+
"destination": "https://www.dubcdn.com/analytics/script.js"
113+
}
114+
]
115+
}
116+
```
117+
118+
</CodeGroup>
119+
120+
Once you've set up your reverse proxy, don't forget to update the `scriptProps.src` parameter in the `<Analytics />` component to point to your proxy URL.
121+
122+
<CodeGroup>
123+
124+
```typescript React/Next.js
125+
import { Analytics as DubAnalytics } from "@dub/analytics/react";
126+
127+
export default function App() {
128+
return (
129+
<Layout>
130+
<DubAnalytics
131+
scriptProps={{
132+
src: "/_proxy/dub/script.js", // pointing to your reverse proxy
133+
}}
134+
/>
135+
{/* Your app code here */}
136+
</Layout>
137+
);
138+
}
139+
```
140+
141+
```javascript Other Frameworks
142+
// include this script tag in your HTML Head tag
143+
<script
144+
src="/_proxy/dub/script.js" // pointing to your reverse proxy
145+
defer
146+
/>
147+
```
148+
149+
</CodeGroup>
150+
84151
## Open-source examples
85152
86153
Here are some open-source code examples that you can referece:

0 commit comments

Comments
 (0)