Behavioral Analysis: The Challenge of the Tab

2026年8月11日1 次浏览来源:Dev.to阅读原文

Currently working on a Saas that reads a user’s behavior on a site.

The goal is keeping it lightweight and privacy centered.

All interactions are recorded in the browser.

When the browser hides the page, a compact summary is calculated and sent to a cloudflare worker for insertion into a D1 DB.

The exit events are strictly bound using this function. 2 attempts are made to send. 1st And 2nd fallback But what about if the user returns to the tab?

The function keeps recording when they return.

But it won't fire again because of the way I set up handleExit.

Because it locks hasSent to true I can't fire another beacon for the session.

I need to turn this._hasSent = false when they return so I can fire again.

But this creates another problem, multiple writes for the same session ID (primary key).

I use write or replace for duplicate session IDs.

This takes the latest data and scrubs the old.

Full project here: Repository: View the code on GitHub Live Site: Check out the SaaS Hopefully my experience with users and their desire to open tabs and jump around like jack rabbits help.

Cheers

分享
Baike.dev

baike.dev helps you discover great languages, frameworks, databases, DevOps and cloud-native tools.

Quick links

About

Contribute

Found a great developer tool? Share it with the community.

Submit a tool
© 2026 baike.dev Developer EncyclopediaUpdated daily · Discover great developer tools