Skip to content

Commit

Permalink
add tracking for provider (#19946)
Browse files Browse the repository at this point in the history
## Description 

Describe the changes or additions included in this PR.

## Test plan 

How did you test the new or updated feature?

---

## Release notes

Check each box that your changes affect. If none of the boxes relate to
your changes, release notes aren't required.

For each box you select, include information after the relevant heading
that describes the impact of your changes that a user might notice and
any actions they must take to implement updates.

- [ ] Protocol: 
- [ ] Nodes (Validators and Full nodes): 
- [ ] Indexer: 
- [ ] JSON-RPC: 
- [ ] GraphQL: 
- [ ] CLI: 
- [ ] Rust SDK:
- [ ] REST API:
  • Loading branch information
plam-ml authored Oct 22, 2024
1 parent 368fc4b commit 4092045
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
45 changes: 45 additions & 0 deletions apps/wallet/src/shared/analytics/ampli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,18 @@ export interface ClickedSwapCoinProperties {
totalBalance?: number;
}

export interface ClickedTokenClaimsBannerProperties {
/**
* A generic name property that can be used across events.
*/
name: string;
/**
* The ID of an object on Sui.
*/
objectId: string;
objectType: string;
}

export interface ClickedUnstakeSuiProperties {
/**
* The amount of SUI staked.
Expand Down Expand Up @@ -514,6 +526,10 @@ export interface SwappedCoinProperties {
*/
estimatedReturnBalance: number;
fromCoinType: string;
/**
* swap provider name
*/
provider?: string;
toCoinType: string;
/**
* The total balance of the selected coin that the user has.
Expand All @@ -537,6 +553,10 @@ export interface SwappedCoinFailedProperties {
*/
estimatedReturnBalance: number;
fromCoinType: string;
/**
* swap provider name
*/
provider?: string;
toCoinType: string;
/**
* The total balance of the selected coin that the user has.
Expand Down Expand Up @@ -691,6 +711,14 @@ export class ClickedSwapCoin implements BaseEvent {
}
}

export class ClickedTokenClaimsBanner implements BaseEvent {
event_type = 'clicked token claims banner';

constructor(public event_properties: ClickedTokenClaimsBannerProperties) {
this.event_properties = event_properties;
}
}

export class ClickedUnstakeSui implements BaseEvent {
event_type = 'clicked unstake SUI';

Expand Down Expand Up @@ -1300,6 +1328,23 @@ export class Ampli {
return this.track(new ClickedSwapCoin(properties), options);
}

/**
* clicked token claims banner
*
* [View in Tracking Plan](https://data.amplitude.com/mystenlabs/Sui%20Wallet/events/main/latest/clicked%20token%20claims%20banner)
*
* Event has no description in tracking plan.
*
* @param properties The event's properties (e.g. name)
* @param options Amplitude event options.
*/
clickedTokenClaimsBanner(
properties: ClickedTokenClaimsBannerProperties,
options?: EventOptions,
) {
return this.track(new ClickedTokenClaimsBanner(properties), options);
}

/**
* clicked unstake SUI
*
Expand Down
11 changes: 11 additions & 0 deletions apps/wallet/src/ui/app/pages/swap/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,24 @@ export function SwapPage() {
toCoinType: toCoinType || '',
totalBalance: Number(amount),
estimatedReturnBalance: inputAmountInUSD || 0,
provider: swapData?.provider,
});

const receiptUrl = `/receipt?txdigest=${encodeURIComponent(
response.digest,
)}&from=transactions`;
return navigate(receiptUrl);
},
onError: (error) => {
ampli.swappedCoinFailed({
estimatedReturnBalance: Number(swapData?.formattedToAmount || 0),
fromCoinType: fromCoinType!,
toCoinType: toCoinType!,
totalBalance: Number(amount || 0),
errorMessage: error.message,
provider: swapData?.provider,
});
},
});

const handleOnsubmit: SubmitHandler<FormType> = (formData) => {
Expand Down

0 comments on commit 4092045

Please sign in to comment.