Skip to main content
This page tracks the account flow of a React app with Analytics Web and its hooks from @grainql/analytics-web/react. Every block uses Analytics Web. trackSignup sends the signup event and trackLogin sends the login event. login and logout set and clear the user ID. Read Identify users.

Signup

Call trackSignup with the result of the signup. On success, call login with the new user ID and set the properties that the dashboard segments by. trackSignup takes method, source, plan, success, and errorMessage.
login runs before trackSignup, so the signup event holds the new user ID.

Login

trackLogin takes method, success, errorMessage, loginAttempt, rememberMe, and twoFactorEnabled. Count the attempts in the component, so a failed login and the retry after it show as one sequence.
If your backend returns a JWT for Grain, pass it as authToken. login({ userId, authToken }) switches the client to the JWT strategy. Read Authentication.

Social login

The provider name goes in method. The rest of the flow is the same as the email login.

Logout

Track the logout while the user ID is still set, with { flush: true }. Then call logout. logout clears the user ID and returns the client to an anonymous ID.
Call logout on every sign-out. If the user ID stays set, the events of the next user on the same browser go to the previous user.

Password reset

There is no template method for a password reset. Use track. The visitor is not logged in, so the event holds the anonymous ID.
createUser, authenticateUser, loginWithProvider, signOut, and sendPasswordResetEmail are functions of your app. Read Template events.