From 06604162a11d99ff119bbf427a24b9a7d82c1575 Mon Sep 17 00:00:00 2001 From: gregfromstl Date: Sat, 2 Nov 2024 07:22:52 +0000 Subject: [PATCH] [SDK] Feature: Configure analytics URL (#5270) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Problem solved Short description of the bug fixed or feature added --- ## 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}` --- .changeset/red-garlics-play.md | 5 +++++ apps/playground-web/src/lib/client.ts | 1 + packages/thirdweb/src/analytics/track/index.ts | 5 ++--- packages/thirdweb/src/utils/domains.ts | 8 ++++++++ 4 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 .changeset/red-garlics-play.md diff --git a/.changeset/red-garlics-play.md b/.changeset/red-garlics-play.md new file mode 100644 index 00000000000..980ea4783dd --- /dev/null +++ b/.changeset/red-garlics-play.md @@ -0,0 +1,5 @@ +--- +"thirdweb": patch +--- + +Enable configuring the analytics endpoint diff --git a/apps/playground-web/src/lib/client.ts b/apps/playground-web/src/lib/client.ts index a5e484cf213..e6be51abf73 100644 --- a/apps/playground-web/src/lib/client.ts +++ b/apps/playground-web/src/lib/client.ts @@ -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 = diff --git a/packages/thirdweb/src/analytics/track/index.ts b/packages/thirdweb/src/analytics/track/index.ts index 534a6b946fc..5b6875f75ca 100644 --- a/packages/thirdweb/src/analytics/track/index.ts +++ b/packages/thirdweb/src/analytics/track/index.ts @@ -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 */ @@ -23,7 +22,7 @@ export async function track({ ...data, }; - return fetch(ANALYTICS_ENDPOINT, { + return fetch(`${getThirdwebBaseUrl("analytics")}/event`, { method: "POST", body: stringify(event), }).catch(() => {}); diff --git a/packages/thirdweb/src/utils/domains.ts b/packages/thirdweb/src/utils/domains.ts index 6f4820e7eda..99e03676a8e 100644 --- a/packages/thirdweb/src/utils/domains.ts +++ b/packages/thirdweb/src/utils/domains.ts @@ -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"; @@ -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, @@ -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, }; /** @@ -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, }; };