Anonymous Tracking
Learn how the Tappd Web SDK tracks anonymous users and merges data upon identification.
Overview
The SDK automatically tracks users even before they're identified, allowing you to capture the full customer journey from first visit to conversion.
Note: If identify() is never called, the user remains anonymous and all events are tracked with an automatically generated anonymousId. This is the default behavior when users haven't logged in or signed up yet.
How Anonymous Tracking Works
1. First Visit
When a user first visits your site:
- SDK generates an
anonymousId(e.g.,anon_xyz789...) - Anonymous ID is stored in
localStorage(persists across sessions) - All events, page views, and sessions are tracked with
anonymousId - User appears in your dashboard as an anonymous user
// SDK initialized
const tappd = new TappdSDK({ appId: 'YOUR_APP_ID' });
// Anonymous ID automatically created
const anonymousId = tappd.getAnonymousId();
// Output: anon_abc123def456ghi7892. Anonymous Tracking
All tracking happens normally with anonymous ID:
// User browses site (anonymous)
await tappd.track('page_view'); // Tracked with anonymousId
await tappd.track('button_click', { buttonId: 'cta' }); // Tracked with anonymousId
await tappd.track('add_to_cart', { productId: 'prod_123' }); // Tracked with anonymousId3. User Identification
When user logs in or signs up:
// User identifies
await tappd.identify({
external_id: 'user_123', // Required: Your internal user ID
email: 'john@example.com',
name: 'John Doe'
});
// All previous anonymous data is automatically merged with user_1234. Data Merging
After identification:
- All anonymous events are linked to the identified user (via
external_id) - Anonymous ID is stored as an alias for future matching
- SDK automatically uses the identified user for future events
- User journey is complete from first visit to conversion
Anonymous ID Behavior
Persistence
Anonymous ID persists across:
- ✅ Browser sessions
- ✅ Tab refreshes
- ✅ Browser restarts
- ✅ Device reboots (same browser)
Anonymous ID is cleared when:
- ❌ User clears browser data
- ❌ User uses incognito/private mode and closes
- ❌
reset()is called
Storage Location
// Stored in localStorage
localStorage.getItem('_tappd_anonymous_id');
// Returns: anon_abc123def456...Use Cases
E-commerce
// Anonymous user browses products
await tappd.track('product_viewed', { productId: 'prod_123' });
await tappd.track('add_to_cart', { productId: 'prod_123' });
// User creates account
await tappd.identify({
external_id: 'user_123', // Required: Your internal user ID
email: 'john@example.com',
name: 'John Doe'
});
// Cart data and browsing history automatically linked to user_123SaaS Applications
// Anonymous user views pricing page
await tappd.track('page_view', { page: '/pricing' });
await tappd.track('button_click', { buttonId: 'start-trial' });
// User signs up
await tappd.identify({
external_id: 'user_123', // Required: Your internal user ID
email: 'john@example.com'
});
// You can see the complete journey: pricing → signupGetting Anonymous ID
Get Current Anonymous ID
const anonymousId = tappd.getAnonymousId();
console.log('Anonymous ID:', anonymousId);Check if User is Anonymous
const sessionId = tappd.getSessionId();
const anonymousId = tappd.getAnonymousId();
// If user not identified, only anonymousId exists
// After identify(), events are tracked with the identified user (external_id)
// Anonymous ID is preserved for data merging purposesResetting Anonymous Tracking
Reset on Logout
function handleLogout() {
tappd.reset();
// Anonymous ID is regenerated
// User becomes anonymous again
}Manual Reset
// Clear anonymous data
tappd.reset();
// New anonymous ID is generated
const newAnonymousId = tappd.getAnonymousId();Best Practices
- Identify as early as possible - Merge data before it's too late
- Don't reset unnecessarily - Preserve anonymous journey
- Track before identification - Capture pre-signup behavior
- Use external_id - Link with your internal user IDs
Data Privacy
Anonymous tracking respects privacy:
- ✅ No personal information stored in anonymous ID
- ✅ GDPR compliant
- ✅ Users can opt-out via browser settings
- ✅ Data can be deleted on request
Troubleshooting
Anonymous ID Not Persisting
Problem: Anonymous ID changes on every page load
Solution: Check browser localStorage is enabled
// Check localStorage support
if (typeof Storage !== 'undefined') {
console.log('localStorage supported');
} else {
console.log('localStorage not supported');
}Data Not Merging
Problem: Anonymous events not appearing after identification
Solution: Ensure identify() is called with the same anonymous context
// Good: SDK automatically includes anonymousId internally
await tappd.identify({
external_id: 'user_123', // Required: Your internal user ID
email: 'john@example.com'
});
// SDK internally merges anonymous data using the anonymousIdNext Steps
- Session Management - How sessions work with anonymous tracking
- API Reference -
getAnonymousId()method - Examples - Anonymous tracking examples
