Skip to content

Commit

Permalink
[SDK] Feature: Configure analytics URL (#5270)
Browse files Browse the repository at this point in the history
## Problem solved

Short description of the bug fixed or feature added

<!-- start pr-codex -->

---

## PR-Codex overview
This PR introduces the ability to configure the analytics endpoint for the `thirdweb` package, enhancing flexibility in specifying where analytics data is sent.

### Detailed summary
- Added a new configuration option for `analytics` in `apps/playground-web/src/lib/client.ts`.
- Replaced the hardcoded `ANALYTICS_ENDPOINT` URL with a dynamic URL using `getThirdwebBaseUrl` in `packages/thirdweb/src/analytics/track/index.ts`.
- Introduced a default value for `analytics` in `packages/thirdweb/src/utils/domains.ts`.

> ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}`

<!-- end pr-codex -->
  • Loading branch information
gregfromstl committed Nov 2, 2024
1 parent 7d36418 commit 0660416
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/red-garlics-play.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"thirdweb": patch
---

Enable configuring the analytics endpoint
1 change: 1 addition & 0 deletions apps/playground-web/src/lib/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ setThirdwebDomains({
storage: process.env.NEXT_PUBLIC_STORAGE_URL,
bundler: process.env.NEXT_PUBLIC_BUNDLER_URL,
pay: process.env.NEXT_PUBLIC_PAY_URL,
analytics: process.env.NEXT_PUBLIC_ANALYTICS_URL,
});

const isDev =
Expand Down
5 changes: 2 additions & 3 deletions packages/thirdweb/src/analytics/track/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import type { ThirdwebClient } from "../../client/client.js";
import { getThirdwebBaseUrl } from "../../utils/domains.js";
import { getClientFetch } from "../../utils/fetch.js";
import { stringify } from "../../utils/json.js";
import type { Ecosystem } from "../../wallets/in-app/core/wallet/types.js";

const ANALYTICS_ENDPOINT = "https://c.thirdweb.com/event";

/**
* @internal
*/
Expand All @@ -23,7 +22,7 @@ export async function track({
...data,
};

return fetch(ANALYTICS_ENDPOINT, {
return fetch(`${getThirdwebBaseUrl("analytics")}/event`, {
method: "POST",
body: stringify(event),
}).catch(() => {});
Expand Down
8 changes: 8 additions & 0 deletions packages/thirdweb/src/utils/domains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ type DomainOverrides = {
* @default "bundler.thirdweb.com"
*/
bundler?: string;
/**
* The base URL for the analytics server.
* @default "c.thirdweb.com"
*/
analytics?: string;
};

export const DEFAULT_RPC_URL = "rpc.thirdweb.com";
Expand All @@ -37,6 +42,7 @@ const DEFAULT_IN_APP_WALLET_URL = "embedded-wallet.thirdweb.com";
const DEFAULT_PAY_URL = "pay.thirdweb.com";
const DEFAULT_STORAGE_URL = "storage.thirdweb.com";
const DEFAULT_BUNDLER_URL = "bundler.thirdweb.com";
const DEFAULT_ANALYTICS_URL = "c.thirdweb.com";

let domains: { [k in keyof DomainOverrides]-?: string } = {
rpc: DEFAULT_RPC_URL,
Expand All @@ -45,6 +51,7 @@ let domains: { [k in keyof DomainOverrides]-?: string } = {
pay: DEFAULT_PAY_URL,
storage: DEFAULT_STORAGE_URL,
bundler: DEFAULT_BUNDLER_URL,
analytics: DEFAULT_ANALYTICS_URL,
};

/**
Expand All @@ -58,6 +65,7 @@ export const setThirdwebDomains = (DomainOverrides: DomainOverrides) => {
pay: DomainOverrides.pay ?? DEFAULT_PAY_URL,
storage: DomainOverrides.storage ?? DEFAULT_STORAGE_URL,
bundler: DomainOverrides.bundler ?? DEFAULT_BUNDLER_URL,
analytics: DomainOverrides.analytics ?? DEFAULT_ANALYTICS_URL,

Check warning on line 68 in packages/thirdweb/src/utils/domains.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/utils/domains.ts#L68

Added line #L68 was not covered by tests
};
};

Expand Down

0 comments on commit 0660416

Please sign in to comment.