Skip to content

Commit

Permalink
Update introduction.mdx
Browse files Browse the repository at this point in the history
  • Loading branch information
steven-tey committed Jan 20, 2025
1 parent 970557f commit c29fdab
Showing 1 changed file with 51 additions and 1 deletion.
52 changes: 51 additions & 1 deletion sdks/client-side/introduction.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,57 @@ You can pass the following props to the `@dub/analytics` script to customize its

## Examples

Check out some examples of the script in action:
Here are some code examples to learn how to use the script:

### Cross-domain tracking

By default, the script already sets the `dub_id` cookie on a cross-domain level. This means that if you have the script installed on your marketing site (e.g. **example.com**), the cookie will also be accessible when your user signs up for your app (e.g. **app.example.com**).

However, if you are installing the script on a subdomain (e.g. **app.example.com**), you will need to set the following option to make sure the cookie is accessible on the apex domain as well (e.g. **example.com**):

<CodeGroup>
```typescript React
<DubAnalytics
cookieOptions={{
domain: ".example.com",
}}
/>
```

```html Other
<script
src="https://cdn.dub.co/analytics.js"
data-cookie-options='{"domain": ".example.com"}'
/>
```
</CodeGroup>
### Custom cookie window
By default, the script sets the `dub_id` cookie to expire in 90 days. You can customize this behavior by passing the `cookieOptions` prop to the script:
<CodeGroup>
```typescript React
<DubAnalytics
cookieOptions={{
expiresInDays: 60, // setting the cookie to expire in 60 days
}}
/>
```
```html Other
<script
src="https://cdn.dub.co/analytics.js"
data-cookie-options='{"expiresInDays": 60}'
/>
```
</CodeGroup>
## Open-source examples
Here are some open-source code examples that you can referece:
<CardGroup cols={2}>
<Card
Expand Down

0 comments on commit c29fdab

Please sign in to comment.