Struggling with Web Tracking: How Can I Sync Data Between Web and Mobile Better?

0
8
Asked By CuriousCoder42 On

I'm building a platform for local businesses using Next.js for the web and Expo for the mobile app, with Supabase as the backend. I've run into a big issue with tracking profile views. We track events like `profile_view` and `whatsapp_click` and aggregate them into a `profile_analytics_daily` table using a Daily Aggregation Cron Job at 2 AM. The problem is that tracking on mobile is smooth since most users are authenticated, but on the web, it's a mess. Most users come in through SEO and aren't logged in, so I'm using `localStorage` for session IDs, which feels unreliable. I'm also facing data discrepancies between web and app views, likely due to ad-blockers or issues with event aggregation. I'm looking for advice on using Next.js middleware for server-side tracking, handling real-time stats versus aggregated analytics, and better management of session IDs for anonymous users. Any insights on syncing web and app data in your projects would be greatly appreciated!

1 Answer

Answered By WebGuru99 On

You're encountering a common issue with client-side versus server-side tracking. For anonymous web traffic, relying on localStorage for session IDs is prone to losses due to ad-blockers or browser privacy settings. Here’s what has worked for us:

1. Make tracking server-side using Next.js routes or middleware, which avoids ad-blockers and uses hashed IPs and user-agent data to identify users.
2. Implement a hybrid identity model combining user IDs, device IDs, and short-lived httpOnly cookies to get a more accurate tracking of sessions.
3. For real-time stats, avoid querying raw events directly. Instead, log events to your database and stream lightweight counts for live stats while keeping your aggregation for deeper analytics.
4. To handle late events efficiently, use a rolling aggregation instead of a strict daily cutoff to improve the accuracy of your data.

If you share your current method for generating session IDs, I can provide a detailed flow that fits your needs better!

TechWhiz82 -

This is pure gold! The hybrid identity model you suggested is exactly what I needed. I’m planning to move the profile_view tracking to a Next.js middleware to tackle those client-side issues. Quick question though: regarding the rolling aggregation, are you just running the same Cron job with a filter for recent events, or is there a more efficient way to handle late arrivals without creating duplicates?

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.