Day 1, 10:00 AM - Page view (user_456, was anon_abc123)Day 1, 10:05 AM - Product viewed (user_456, was anon_abc123)Day 1, 10:10 AM - Add to cart (user_456, was anon_abc123)Day 1, 10:15 AM - Signup (user_456)
DATALYR retroactively links all past anonymous events to the user ID.
// User clicks Meta ad on phone// anonymous_id: anon_mobile_123// fbclid captured: abc123// Browse productsdatalyr.track('view_item', { product_id: 'SKU123' });// Add to cartdatalyr.track('add_to_cart', { product_id: 'SKU123' });// User leaves without purchasing
Desktop (Day 2):
// User types URL directly on desktop// anonymous_id: anon_desktop_456// source: direct// User logs indatalyr.identify('user_789', { email: '[email protected]'});// DATALYR links anon_desktop_456 → user_789// Complete purchasedatalyr.track('purchase', { order_id: 'ORDER123', revenue: 99.99});
Mobile Phone (Day 3):
// User opens app on phone again// anonymous_id: anon_mobile_123// User logs indatalyr.identify('user_789');// DATALYR links anon_mobile_123 → user_789
Result:
DATALYR now knows all three anonymous IDs belong to user_789 and attributes the purchase to the original Meta ad (fbclid from Day 1).
// Good: Call on every page for logged-in usersif (currentUser) { datalyr.identify(currentUser.id);}// Bad: Only calling once during signup// (Users will be anonymous after page reload)
Use consistent user IDs
// Good: Same ID across all platformsdatalyr.identify('user_123'); // WebDatalyrSDK.shared.identify("user_123") // iOSDatalyr.identify('user_123'); // React Native// Bad: Different IDs per platform// (DATALYR won't link them together)
Include email in traits
// Good: Email helps with Meta/Google enhanced matchingdatalyr.identify('user_123', { email: '[email protected]'});// OK: Works but no enhanced matchingdatalyr.identify('user_123');
Don’t identify anonymous users
// Bad: Don't call identify() without a real user IDdatalyr.identify(anonymousId); // NO!// Good: Only call when you know who the user isif (userId) { datalyr.identify(userId);}
Hash sensitive data
// Bad: Don't send passwords or SSNsdatalyr.identify('user_123', { password: 'secret123' // DON'T DO THIS});// Good: Only send safe user attributesdatalyr.identify('user_123', { email: '[email protected]', plan: 'pro'});