Overview
Databuddy uses two types of identifiers to track users across sessions and domains:- Anonymous ID - Persistent identifier stored in
localStoragethat survives page reloads and browser sessions - Session ID - Temporary identifier stored in
sessionStoragethat expires after 30 minutes of inactivity
Anonymous ID
The anonymous ID is a persistent identifier that uniquely identifies a user across multiple sessions on the same device and browser.Format
anon_550e8400-e29b-41d4-a716-446655440000
Storage
- Location:
localStoragewith keydid - Expiration: Never expires (persists until manually cleared)
- Scope: Domain-specific (separate for each domain)
Retrieving Anonymous ID
Use thegetAnonymousId() function to access the current anonymous ID:
Function Signature
anonIdURL parameter (ifurlParamsprovided)- Tracker instance value
localStorage.getItem('did')nullif not available
Example: Send to Backend
Session ID
The session ID identifies a single browsing session and expires after 30 minutes of inactivity.Format
sess_7c9e6679-7425-40de-944b-e07fc1f90ae7
Storage
- Location:
sessionStoragewith keydid_session - Expiration: 30 minutes of inactivity
- Scope: Tab-specific (each browser tab has its own session)
Session Lifecycle
- Creation: Generated on first pageview
- Extension: Timestamp updated on each pageview (resets 30-minute timer)
- Expiration: Automatically expires after 30 minutes without activity
- Termination: Cleared when tab/window closes or when
clear()is called
Retrieving Session ID
Use thegetSessionId() function:
Function Signature
sessionIdURL parameter (ifurlParamsprovided)- Tracker instance value
sessionStorage.getItem('did_session')nullif not available
Session Start Time
The session start timestamp is stored insessionStorage as did_session_start and represents when the session was created.
Retrieving Both IDs
Get both identifiers in a single call:Cross-Domain Tracking
When users navigate between different domains you own (e.g., frommarketing.example.com to app.example.com), you can preserve tracking continuity by passing IDs via URL parameters.
Generate Tracking Parameters
UsegetTrackingParams() to create a query string with both IDs:
Function Signature
anonId and sessionId parameters.
React Example
Next.js Example
How It Works
When a user clicks a link with tracking parameters:- The destination page loads with
?anonId=...&sessionId=...in the URL - Databuddy tracker detects the URL parameters
- The IDs from the URL are stored in
localStorageandsessionStorage - Tracking continuity is maintained across domains
/home/daytona/workspace/source/packages/tracker/src/core/tracker.ts:150-155
Clearing Identities
Reset tracking identities when a user logs out or you need a fresh session:What clear() Does
- Removes
didfromlocalStorage(anonymous ID) - Removes
did_sessionfromsessionStorage(session ID) - Removes
did_session_timestampfromsessionStorage - Removes
did_session_startfromsessionStorage - Generates new anonymous and session IDs
- Resets page count and engagement metrics
- Clears global properties
/home/daytona/workspace/source/packages/tracker/src/index.ts:329-346
Function Signature
Checking Tracker Availability
Before accessing tracking IDs, verify the tracker has loaded:Function Signature
true if window.databuddy or window.db exists, false otherwise.
Advanced Usage
Access Tracker Instance
Get the raw tracker instance for advanced operations:Custom Identity Logic
Privacy Considerations
Anonymous by Default
Databuddy uses anonymous identifiers, not personally identifiable information (PII). No emails, names, or addresses are collected by default.
User Consent
Respect user privacy preferences. Use the
disabled option or clear() function to honor opt-out requests.Data Minimization
Only track what you need. Don’t send PII in event properties unless necessary for your use case.
Opt-Out Support
Provide users with an opt-out mechanism using
window.databuddyOptOut() or by disabling tracking entirely.Opt-Out Functionality
Storage Details
localStorage (Anonymous ID)
sessionStorage (Session ID)
Related Documentation
- Sessions - Session lifecycle and management
- Custom Events - Track user actions
- Custom Properties - Event properties and data types