From your web app, you can collect information to build out a user profile, as well as send custom events to your mixpanel project. This can be done by using mixpanel's SDK.
Once installed, configure the SDK to start tracking events by initialising:
//Import Mixpanel SDKimport mixpanel from"mixpanel-browser";// Near entry of your product, init Mixpanelmixpanel.init("YOUR_TOKEN", { debug:true, track_pageview:true, persistence:"localStorage",// Route events from Mixpanelโs SDKs via a proxy in your own domain - prevents adblockers impacting tracking.// See more: https://docs.mixpanel.com/docs/tracking-methods/sdks/javascript#tracking-via-proxy api_host:"YOUR_PROXY_URL",});
Identifying Users and Creating User Profiles
Once this is initialized, you can identify and define attributes for users of your platform. This will populate their user profile in mixpanel, allowing you to track and gather insights on their user journeys through the platform:
constaccount=useAppSelector(userSelectors.getAuthUser)constlinkedEvmWallet=useAppSelector(userSelectors.getEvmLinkedWalletAddress,)constprofile=useAppSelector(userSelectors.getProfile)useEffect(() => {if (account?.uid) {mixpanel.identify(account.uid)mixpanel.people.set({ $email:account.email, $name:profile?.username, $avatar:profile?.profilePictureUrl,// Optional: example of including a user's wallet in their user profile wallet: linkedEvmWallet, userId:account.uid, })
An example of how you might want to sync user profile data to mixpanel can be found in our mixpanel repository. You can also follow mixpanel's documentation on identifying users.
Sending and Tracking Generic Events
You are also able to track events from your web app. An example is shown below: