Advanced
User Identification
Link anonymous visitors to email addresses to enable targeted email campaigns based on user behavior.
Overview
By default, Phi tracks visitors anonymously using a unique visitor_id. When a user provides their email (through login, signup, or a form), you can "identify" them to link their browsing behavior to their email address.
Anonymous Visitor
Tracked by visitor_id, browsing data collected
phi.identify()
Links visitor_id to email address
Targeted Campaigns
Send emails based on user behavior
Basic Usage
Call phi.identify() when a user provides their email:
// Basic identification
phi.identify('user@example.com');
// With additional traits
phi.identify('user@example.com', {
name: 'John Doe',
marketing_consent: true
});When to Identify
Call identify whenever a user provides their email:
// After user signs up
async function handleSignup(email, name) {
await createAccount(email, password);
phi.identify(email, { name, marketing_consent: true });
}
// After user logs in
async function handleLogin(email) {
await login(email, password);
phi.identify(email);
}
// After newsletter signup
function handleNewsletterSignup(email) {
subscribeToNewsletter(email);
phi.identify(email, { marketing_consent: true });
}
// After contact form submission
function handleContactForm(email, name, message) {
submitContactForm({ email, name, message });
phi.identify(email, { name });
}API Reference
phi.identify(email, traits?)Links the current visitor to an email address.
Parameters
| string | User's email address (required) | |
| traits | object | Optional user properties |
Traits Object
| name | string | User's display name |
| marketing_consent | boolean | User consented to marketing emails |
| ... | any | Any custom properties you want to store |
Returns
Promise<boolean> — Resolves to true on success.
phi.getIdentifiedEmail()Returns the email if the user was previously identified.
const email = phi.getIdentifiedEmail();
if (email) {
console.log('User is identified:', email);
}Use Cases
Once users are identified, you can create targeted email campaigns:
Pricing Page Visitors
Send a follow-up email to users who visited /pricing 3+ times but didn't convert.
Re-engagement Campaign
Email users who haven't visited your site in 30 days with a "We miss you" message.
Feature Announcements
Announce new features to users who frequently use a specific part of your app.
Automatic Identification
The Phi SDK automatically identifies users in certain scenarios:
- ✓Chat Widget — When a user provides their email to start a chat session.
For other scenarios (login, signup, forms), you need to call phi.identify() manually.
Privacy Note
- •Only identify users who have consented to tracking.
- •Set
marketing_consent: trueonly if the user explicitly opted in. - •The visitor ID is stored in localStorage and persists across sessions.
- •Users can be unidentified by clearing their browser storage.