Skip to content

Commit

Permalink
Move cartridgeTag to analyticsOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
WyattMufson committed Oct 15, 2024
1 parent c5ce956 commit d3b3cc6
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 8 deletions.
4 changes: 0 additions & 4 deletions examples/connect-react/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ const ERC20_MINTABLE_ABI = [
},
] as const;

const cartridgeTag = "tdk-examples-connect-react";

export const App = () => {
const { client, chain, tdk, user, contractAddresses, trackCustomEvent } =
useTreasure();
Expand Down Expand Up @@ -111,7 +109,6 @@ export const App = () => {
setTracking(true);
try {
const result = await trackCustomEvent({
cartridgeTag,
name: "test-click",
properties: { test: "test-value" },
});
Expand All @@ -134,7 +131,6 @@ export const App = () => {
console.log("Connect successful:", { method, wallet, nextUser });
trackCustomEvent({
address: nextUser?.address,
cartridgeTag,
name: "wallet-connect",
properties: {
method,
Expand Down
1 change: 1 addition & 0 deletions examples/connect-react/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ if (root) {
app_version: "1.0.0",
app_environment: 0,
},
cartridgeTag: "tdk-examples-connect-react",
}}
>
<App />
Expand Down
7 changes: 6 additions & 1 deletion packages/core/src/analytics/AnalyticsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export class AnalyticsManager {

app!: AppInfo;

cartridgeTag!: string;

private constructor() {}

public static get instance(): AnalyticsManager {
Expand All @@ -34,10 +36,12 @@ export class AnalyticsManager {
apiUri = DEFAULT_TDK_DARKMATTER_BASE_URI,
apiKey,
app,
}: { apiUri?: string; apiKey: string; app: AppInfo }) {
cartridgeTag,
}: { apiUri?: string; apiKey: string; app: AppInfo; cartridgeTag: string }) {
this.apiUri = apiUri;
this.apiKey = apiKey;
this.app = app;
this.cartridgeTag = cartridgeTag;
this.initialized = true;

setInterval(
Expand Down Expand Up @@ -88,6 +92,7 @@ export class AnalyticsManager {
const payload: AnalyticsPayload = {
...event,
id: eventId,
cartridge_tag: this.cartridgeTag,
time_server: serverTime,
time_local: localTime,
app: this.app,
Expand Down
1 change: 0 additions & 1 deletion packages/core/src/analytics/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ export type AnalyticsPayload = PlayerIdPayload & {
};

export type TrackableEvent = PlayerIdPayload & {
cartridge_tag: string;
name: string;
properties: { [key: string]: PropertyValue | PropertyValue[] };
};
2 changes: 1 addition & 1 deletion packages/react/src/contexts/treasure.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ const TreasureProviderInner = ({
apiUri: analyticsOptions.apiUri,
apiKey: analyticsOptions.apiKey,
app: analyticsOptions.appInfo,
cartridgeTag: analyticsOptions.cartridgeTag,
});

return AnalyticsManager.instance;
Expand Down Expand Up @@ -147,7 +148,6 @@ const TreasureProviderInner = ({

const trackableEvent: TrackableEvent = {
...playerId,
cartridge_tag: event.cartridgeTag,
name: event.name,
properties: event.properties,
};
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import type { Wallet } from "thirdweb/dist/types/exports/wallets";
import type { SupportedLanguage } from "./i18n";

export type AnalyticsEvent = {
cartridgeTag: string;
name: string;
userId?: string;
address?: string;
Expand All @@ -30,6 +29,7 @@ type AnalyticsOptions = {
apiUri?: string;
apiKey: string;
appInfo: AppInfo;
cartridgeTag: string;
};

export type Config = {
Expand Down

0 comments on commit d3b3cc6

Please sign in to comment.