Skip to main content

Overview

Cryptique provides specialized methods for tracking wallet connections in Web3 applications. The SDK automatically detects wallet connections via EIP-6963 and window.ethereum, but you can also manually trigger wallet tracking.
When a wallet connects, Cryptique automatically links the wallet address to the current session and user profile. This enables unified analytics across off-chain behavior and on-chain transactions.

Automatic Wallet Detection

Cryptique automatically detects:
  • Wallet Connection: When window.ethereum or EIP-6963 providers connect
  • Account Changes: When user switches accounts (accountsChanged event)
  • Chain Changes: When user switches networks (chainChanged event)
  • Wallet Type: MetaMask, Coinbase Wallet, WalletConnect, etc.
This data is captured in session data without any code required.

Cryptique.walletAddress()

Associate a wallet address with the current user. Use this when you have the wallet address from your connection flow.
Cryptique.walletAddress(address)
address
string
required
The wallet address to associate with the current user (e.g., 0x742d35Cc6634C0532925a3b844Bc9e7595f5bB21).

Returns

void

How It Works

When you call walletAddress():
  1. The address is linked to the current session
  2. If this address exists for another user profile, the profiles are merged via CQ Intelligence
  3. The wallet becomes available for enrichment (if enabled)

Examples

// After your own wallet connection logic
const address = await connectWallet();
Cryptique.walletAddress(address);

// With ethers.js
const provider = new ethers.BrowserProvider(window.ethereum);
const signer = await provider.getSigner();
const address = await signer.getAddress();
Cryptique.walletAddress(address);

// With wagmi
const { address } = useAccount();
useEffect(() => {
  if (address) {
    Cryptique.walletAddress(address);
  }
}, [address]);

// With RainbowKit
const { address, isConnected } = useAccount();
useEffect(() => {
  if (isConnected && address) {
    Cryptique.walletAddress(address);
  }
}, [isConnected, address]);

Multiple Wallets

Users can connect multiple wallets. Each call to walletAddress() adds to the user’s wallet collection:
// User connects first wallet
Cryptique.walletAddress('0x111...');

// User connects second wallet  
Cryptique.walletAddress('0x222...');

// Both wallets are now linked to this user profile
The user profile accumulates all connected wallets. You can see all associated wallets in the Cryptique dashboard under the user’s profile.

Wallet Disconnect Behavior

There is no explicit disconnect method. Disconnection is handled automatically:
  1. SDK listens to accountsChanged events
  2. When accounts become empty (disconnected), session data updates
  3. wallet_connected session field becomes false
  4. Last wallet data is retained for the session

Combining with identify()

You can use wallet address as the user’s identity:
// Option 1: Wallet as primary identity
function handleWalletConnect(address) {
  Cryptique.identify(address);
  Cryptique.walletAddress(address);
}

// Option 2: Separate user ID + wallet
function handleWalletConnect(userId, walletAddress) {
  Cryptique.identify(userId);
  Cryptique.walletAddress(walletAddress);
}

Session Data Fields

When a wallet is connected, these fields are captured in session data:
FieldTypeDescription
wallet_connectedbooleanWhether a wallet is currently connected
wallet_addressstringThe connected wallet address
wallet_typestringDetected wallet provider (MetaMask, etc.)
chain_idnumberConnected chain ID

Integration Examples

import { useAccount } from 'wagmi';
import { useEffect } from 'react';
import Cryptique from 'cryptique-sdk';

function WalletTracker() {
  const { address, isConnected, connector } = useAccount();
  
  useEffect(() => {
    if (isConnected && address) {
      Cryptique.walletAddress(address);
      Cryptique.track('wallet_connected', {
        address: address,
        wallet_type: connector?.name
      });
    }
  }, [isConnected, address, connector]);
  
  return null;
}

// Use in your app
function App() {
  return (
    <>
      <WalletTracker />
      {/* rest of app */}
    </>
  );
}

Best Practices

Track Connection Events

// Track the connection as an event too
function handleWalletConnect(address, chainId) {
  Cryptique.walletAddress(address);
  
  Cryptique.track('wallet_connected', {
    address: address,
    chain_id: chainId,
    connection_method: 'metamask'
  });
}

Handle Multiple Chains

// Track chain switches
window.ethereum?.on('chainChanged', (chainId) => {
  Cryptique.track('chain_switched', {
    new_chain_id: parseInt(chainId, 16),
    chain_name: getChainName(chainId)
  });
});

Store Primary Wallet

// If user has multiple wallets, track the primary one
function setPrimaryWallet(address) {
  Cryptique.people.set({
    primary_wallet: address
  });
}

Identify Users

Link wallets to user identities

Wallet Enrichment

Get on-chain wallet data