User Identification
Connect your anonymous website visitors to their actual user profiles.
What is "Identify"?
By default, TwoBucks tracks visitors anonymously. If a user visits your site from their phone and then later from their laptop, they count as two separate visitors.
The Identify API solves this by linking these sessions together. When a user logs in, you tell TwoBucks "Hey, this is User 123". We then stitch their history together, giving you a complete picture of their journey across devices and sessions.
Why use it?
Accurate User Counts
Know exactly how many people are using your product, not just how many devices.
Cross-Device Tracking
Track a user's journey as they switch between mobile, tablet, and desktop.
Rich User Profiles
Attach details like "Plan Type" or "Company Name" to filter your analytics by customer segments.
Historical Data
When a user identifies, their past anonymous activity is automatically linked to their new profile.
How to Implement
The best place to call identify() is right after your user successfully logs in or signs up.
1. Basic Identification
At a minimum, send the user's unique ID from your database.
// Call this after login success
window.twobucks.identify('user_123');2. Adding User Details
You can also send a user object with traits like email, name, or plan type. This helps you segment your data later (e.g., "Show me usage for Pro Plan users").
window.twobucks.identify('user_123', {
email: 'alice@example.com',
name: 'Alice Smith',
plan: 'pro_monthly',
company: 'Wonderland Inc'
});Real-World Example
Here is how you might use it in a typical login function:
async function handleLogin(email, password) {
try {
// 1. Authenticate with your backend
const user = await api.login(email, password);
// 2. Identify the user in TwoBucks
if (window.twobucks) {
window.twobucks.identify(user.id, {
email: user.email,
name: user.name,
plan: user.subscription_tier
});
}
// 3. Redirect to dashboard
window.location.href = '/dashboard';
} catch (error) {
console.error('Login failed', error);
}
}Privacy & Consent
Important Note
Identifying users involves collecting Personally Identifiable Information (PII).
- Ensure your Privacy Policy discloses this data collection.
- If you are in the EU (GDPR), you likely need explicit user consent before calling
identify(). - See our Privacy Guide for more details.
Advanced: Queuing Events
If you need to identify a user immediately on page load (before the script has fully downloaded), you can use the queue. This is common for Single Page Apps (SPAs) where the user is already logged in when they arrive.
<script>
// Create queue if it doesn't exist
window.twobucksQueue = window.twobucksQueue || [];
// Push identify event to queue
window.twobucksQueue.push(['identify', 'user_123', {
plan: 'pro'
}]);
</script>
<!-- Load TwoBucks Script -->
<script
src="https://www.twobucks.ai/script.js"
data-website-id="your-website-id"
async
></script>