Skip to content

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:

  1. SDK generates an anonymousId (e.g., anon_xyz789...)
  2. Anonymous ID is stored in localStorage (persists across sessions)
  3. All events, page views, and sessions are tracked with anonymousId
  4. User appears in your dashboard as an anonymous user
javascript
// SDK initialized
const tappd = new TappdSDK({ appId: 'YOUR_APP_ID' });

// Anonymous ID automatically created
const anonymousId = tappd.getAnonymousId();
// Output: anon_abc123def456ghi789

2. Anonymous Tracking ​

All tracking happens normally with anonymous ID:

javascript
// 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 anonymousId

3. User Identification ​

When user logs in or signs up:

javascript
// User identifies
await tappd.identify({
  external_id: 'user_123',  // Required: Your internal user ID
  email: '[email protected]',
  name: 'John Doe'
});

// All previous anonymous data is automatically merged with user_123

4. 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 ​

javascript
// Stored in localStorage
localStorage.getItem('_tappd_anonymous_id');
// Returns: anon_abc123def456...

Use Cases ​

E-commerce ​

javascript
// 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: '[email protected]',
  name: 'John Doe'
});

// Cart data and browsing history automatically linked to user_123

SaaS Applications ​

javascript
// 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: '[email protected]'
});

// You can see the complete journey: pricing → signup

Getting Anonymous ID ​

Get Current Anonymous ID ​

javascript
const anonymousId = tappd.getAnonymousId();
console.log('Anonymous ID:', anonymousId);

Check if User is Anonymous ​

javascript
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 purposes

Resetting Anonymous Tracking ​

Reset on Logout ​

javascript
function handleLogout() {
  tappd.reset();
  // Anonymous ID is regenerated
  // User becomes anonymous again
}

Manual Reset ​

javascript
// Clear anonymous data
tappd.reset();

// New anonymous ID is generated
const newAnonymousId = tappd.getAnonymousId();

Best Practices ​

  1. Identify as early as possible - Merge data before it's too late
  2. Don't reset unnecessarily - Preserve anonymous journey
  3. Track before identification - Capture pre-signup behavior
  4. 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

javascript
// 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

javascript
// Good: SDK automatically includes anonymousId internally
await tappd.identify({
  external_id: 'user_123',  // Required: Your internal user ID
  email: '[email protected]'
});

// SDK internally merges anonymous data using the anonymousId

Next Steps ​

Released under the MIT License.