Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Analytics] Unify client analytics #2224

Merged
merged 24 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/silly-dolphins-fly.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@thirdweb-dev/unity-js-bridge": patch
"@thirdweb-dev/react-native": patch
"@thirdweb-dev/react": patch
---

Adds global sdk vars
10 changes: 10 additions & 0 deletions packages/react-native/src/evm/providers/thirdweb-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import { SafeAreaProvider } from "react-native-safe-area-context";
import { walletIds } from "@thirdweb-dev/wallets";
import { ThirdwebStorage } from "../../core/storage/storage";
import type { Locale } from "../i18n/types";
import { appBundleId, packageVersion } from "../utils/version";
import { Platform } from "react-native";

export interface ThirdwebProviderProps<TChains extends Chain[]>
extends Omit<
Expand Down Expand Up @@ -148,6 +150,14 @@ export const ThirdwebProvider = <TChains extends Chain[] = DefaultChains>(
...restProps
} = props;

if (typeof globalThis !== "undefined") {
(globalThis as any).X_SDK_NAME = packageVersion.name;
(globalThis as any).X_SDK_PLATFORM = "react-native";
(globalThis as any).X_SDK_VERSION = packageVersion.version;
(globalThis as any).X_SDK_OS = Platform.OS;
(globalThis as any).APP_BUNDLE_ID = appBundleId;
}

const coinbaseWalletObj = supportedWallets.find(
(w) => w.id === walletIds.coinbase,
);
Expand Down
7 changes: 0 additions & 7 deletions packages/react-native/src/evm/utils/global.ts

This file was deleted.

7 changes: 0 additions & 7 deletions packages/react-native/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1 @@
import { isGlobalThisPresent } from "./evm/utils/global";
import { appBundleId } from "./evm/utils/version";

export * from "./evm";

if (isGlobalThisPresent()) {
(globalThis as any).APP_BUNDLE_ID = appBundleId;
}
9 changes: 9 additions & 0 deletions packages/react/src/evm/providers/thirdweb-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import { en } from "../locales/en";
import { ThirdwebLocaleContext } from "./locale-provider";
import { walletIds } from "@thirdweb-dev/wallets";
import { ThirdwebLocale } from "../locales/types";
import packageJson from "../../../package.json";
import { detectOS } from "../utils/isMobile";

export interface ThirdwebProviderProps<TChains extends Chain[]>
extends Omit<
Expand Down Expand Up @@ -479,6 +481,13 @@ export const ThirdwebProvider = <TChains extends Chain[] = DefaultChains>(
...restProps
} = props;

if (typeof globalThis !== "undefined") {
(globalThis as any).X_SDK_NAME = packageJson.name;
(globalThis as any).X_SDK_PLATFORM = "react";
(globalThis as any).X_SDK_VERSION = packageJson.version;
(globalThis as any).X_SDK_OS = detectOS();
}

const wallets: WalletConfig[] = supportedWallets || defaultWallets;
const theme = _theme || "dark";

Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/evm/utils/isMobile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export function isIOS(): boolean {
/**
* @internal
*/
function detectOS() {
export function detectOS() {
const env = detectEnv();
return env?.os ? env.os : undefined;
}
Expand Down
6 changes: 6 additions & 0 deletions packages/unity-js-bridge/src/thirdweb-bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ class ThirdwebBridge implements TWBridge {
}

public initialize(chain: ChainIdOrName, options: string) {
if(typeof globalThis !== "undefined"){
(globalThis as any).X_SDK_NAME = "UnitySDK";
(globalThis as any).X_SDK_PLATFORM = "unity";
(globalThis as any).X_SDK_VERSION = "4.5.1";
(globalThis as any).X_SDK_OS = "webgl";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here we should call detectOS() - 'win' / 'mac' / etc

need to add detect-browser as a dependency and import it here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 110dd8f

}
this.initializedChain = chain;
console.debug("thirdwebSDK initialization:", chain, options);
const sdkOptions = JSON.parse(options);
Expand Down
Loading