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

Feat: Add walletType to event data #640

Merged
merged 6 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
35 changes: 21 additions & 14 deletions apps/base-docs/src/theme/NavbarItem/ComponentTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,21 @@ import { ConnectButton } from '@rainbow-me/rainbowkit';
import '@rainbow-me/rainbowkit/styles.css';
import styles from './styles.module.css';
import { WalletAvatar } from '../../components/WalletAvatar';
import logEvent, { ActionType, AnalyticsEventImportance, ComponentType, identify } from "base-ui/utils/logEvent";
import logEvent, {
ActionType,
AnalyticsEventImportance,
ComponentType,
identify,
} from 'base-ui/utils/logEvent';
import sanitizeEventString from 'base-ui/utils/sanitizeEventString';

export const CustomConnectButton = ({ className }) => {
return (
<ConnectButton.Custom>
{({ account, chain, openAccountModal, openChainModal, openConnectModal, mounted }) => {
const ready = mounted;
const connected = ready && account && chain;
const { address } = useAccount();
const { address, connector } = useAccount();

useEffect(() => {
if (address) {
Expand All @@ -32,6 +38,7 @@ export const CustomConnectButton = ({ className }) => {
action: ActionType.change,
context: 'navbar',
address,
walletType: sanitizeEventString(connector?.name),
},
AnalyticsEventImportance.low,
);
Expand Down Expand Up @@ -144,8 +151,8 @@ export const CustomNavbarLink = (props) => {
<a
href={props.to}
target={props.target ?? '_self'}
className='navbar__item navbar__link'
style={{ cursor: 'pointer'}}
className="navbar__item navbar__link"
style={{ cursor: 'pointer' }}
onClick={() => {
logEvent(
props.eventLabel,
Expand All @@ -154,23 +161,23 @@ export const CustomNavbarLink = (props) => {
componentType: ComponentType.link,
context: props.eventContext,
},
AnalyticsEventImportance.high
)
AnalyticsEventImportance.high,
);
}}
>
{props.label}
</a>
)
}
);
};

export const CustomDropdownLink = (props) => {
return (
<li>
<a
href={props.to}
target={props.target ?? '_self'}
className='dropdown__link'
style={{ cursor: 'pointer'}}
className="dropdown__link"
style={{ cursor: 'pointer' }}
onClick={() => {
logEvent(
props.eventLabel,
Expand All @@ -179,15 +186,15 @@ export const CustomDropdownLink = (props) => {
componentType: ComponentType.link,
context: props.eventContext,
},
AnalyticsEventImportance.high
)
AnalyticsEventImportance.high,
);
}}
>
{props.label}
</a>
</li>
)
}
);
};

const ComponentTypes = {
default: DefaultNavbarItem,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ConnectButton, useConnectModal } from '@rainbow-me/rainbowkit';

import { UserAvatar } from 'apps/web/src/components/ConnectWalletButton/UserAvatar';
import { ShinyButton } from 'apps/web/src/components/ShinyButton/ShinyButton';
import sanitizeEventString from 'base-ui/utils/sanitizeEventString';
import logEvent, {
ActionType,
AnalyticsEventImportance,
Expand All @@ -23,19 +24,20 @@ const colorVariant: Record<'white' | 'black', 'white' | 'black'> = {

export function ConnectWalletButton({ color, className }: ConnectWalletButtonProps) {
const { openConnectModal } = useConnectModal();
const { address } = useAccount();
const { address, connector } = useAccount();

useEffect(() => {
if (address) {
logEvent(
'wallet_connected',
{
{
action: ActionType.change,
context: 'navbar',
address
},
AnalyticsEventImportance.low
);
address,
walletType: sanitizeEventString(connector?.name),
},
AnalyticsEventImportance.low,
);
identify({ userId: address });
}
}, [address]);
Expand All @@ -47,9 +49,9 @@ export function ConnectWalletButton({ color, className }: ConnectWalletButtonPro
{
action: ActionType.click,
componentType: ComponentType.button,
context: 'navbar'
context: 'navbar',
},
AnalyticsEventImportance.low
AnalyticsEventImportance.low,
);
}, [openConnectModal]);

Expand Down
1 change: 1 addition & 0 deletions libs/base-ui/utils/logEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ type CCAEventData = {
address?: string;
context?: string;
userId?: string;
walletType?: string;
};

type AnalyticsEventData = {
Expand Down
7 changes: 7 additions & 0 deletions libs/base-ui/utils/sanitizeEventString.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function sanitizeEventString(str: string | undefined) {
if (!str) {
return '';
}

return str.toLowerCase().replace(/[ \-\/\.]/g, '_');
};
Loading