Implement real-time presence tracking with PubNub
79
Quality
67%
Does it follow best practices?
Impact
98%
1.07xAverage score across 5 eval scenarios
{
"context": "A web application needs to initialize PubNub with proper presence settings and ensure users disappear from the online list promptly when they close the browser tab, rather than lingering for minutes.",
"type": "weighted_checklist",
"checklist": [
{
"name": "beforeunload cleanup",
"description": "Registers a 'beforeunload' event listener on the window that calls pubnub.unsubscribeAll() to ensure clean disconnection when the user closes or navigates away from the page",
"max_score": 25
},
{
"name": "Timeout at least 2x heartbeat",
"description": "The presenceTimeout value is configured to be at least 2x the heartbeatInterval value (e.g., heartbeatInterval: 30 with presenceTimeout: 120 or higher)",
"max_score": 25
},
{
"name": "Event Engine enabled",
"description": "The PubNub constructor includes enableEventEngine: true for better connection management and automatic reconnection",
"max_score": 20
},
{
"name": "Persistent unique userId",
"description": "The userId is generated once and persisted (e.g., in localStorage) for reuse across sessions, not regenerated on every page load",
"max_score": 15
},
{
"name": "Connection status handling",
"description": "A status listener handles PNConnectedCategory to trigger initial presence fetch and PNReconnectedCategory to refresh presence state after reconnection",
"max_score": 15
}
]
}