humanbehavior-js 0.2.7 → 0.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +52 -3
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/react/index.js.map +1 -1
- package/dist/esm/index.js +52 -4
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/react/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/types/index.d.ts +24 -4
- package/package.json +1 -1
- package/src/index.ts +3 -0
- package/src/react/index.tsx +5 -0
- package/src/server.ts +51 -0
- package/src/tracker.ts +11 -3
package/dist/cjs/index.js
CHANGED
|
@@ -5763,8 +5763,9 @@ class HumanBehaviorTracker {
|
|
|
5763
5763
|
}
|
|
5764
5764
|
}
|
|
5765
5765
|
/**
|
|
5766
|
-
*
|
|
5767
|
-
* This
|
|
5766
|
+
* Clear user data and reset session when user signs out of the site
|
|
5767
|
+
* This should be called when a user logs out of your application to prevent
|
|
5768
|
+
* data contamination between different users
|
|
5768
5769
|
*/
|
|
5769
5770
|
logout() {
|
|
5770
5771
|
if (!isBrowser)
|
|
@@ -5779,7 +5780,13 @@ class HumanBehaviorTracker {
|
|
|
5779
5780
|
// Reset user-related properties
|
|
5780
5781
|
this.endUserId = null;
|
|
5781
5782
|
this.userProperties = {};
|
|
5782
|
-
|
|
5783
|
+
// Generate a new session ID for the next user
|
|
5784
|
+
this.sessionId = v1();
|
|
5785
|
+
if (isBrowser) {
|
|
5786
|
+
localStorage.setItem('human_behavior_session_id', this.sessionId);
|
|
5787
|
+
localStorage.setItem('human_behavior_last_activity', Date.now().toString());
|
|
5788
|
+
}
|
|
5789
|
+
logInfo('User logged out - cleared all user data and started fresh session');
|
|
5783
5790
|
}
|
|
5784
5791
|
catch (error) {
|
|
5785
5792
|
logError('Error during logout:', error);
|
|
@@ -5934,6 +5941,47 @@ if (isBrowser) {
|
|
|
5934
5941
|
window.HumanBehaviorTracker = HumanBehaviorTracker;
|
|
5935
5942
|
}
|
|
5936
5943
|
|
|
5944
|
+
/**
|
|
5945
|
+
* Server-side utilities for HumanBehavior SDK
|
|
5946
|
+
*/
|
|
5947
|
+
/**
|
|
5948
|
+
* Identify user from server-side (NextAuth, Firebase, etc.)
|
|
5949
|
+
* Use this in your auth events to track users immediately on sign-in
|
|
5950
|
+
*/
|
|
5951
|
+
function identifyUser(userData, apiKey) {
|
|
5952
|
+
return __awaiter$1(this, void 0, void 0, function* () {
|
|
5953
|
+
try {
|
|
5954
|
+
const response = yield fetch('https://ingest.humanbehavior.co/api/ingestion/user', {
|
|
5955
|
+
method: 'POST',
|
|
5956
|
+
headers: {
|
|
5957
|
+
'Content-Type': 'application/json',
|
|
5958
|
+
'Authorization': `Bearer ${apiKey}`
|
|
5959
|
+
},
|
|
5960
|
+
body: JSON.stringify({
|
|
5961
|
+
userId: userData.email,
|
|
5962
|
+
userAttributes: userData,
|
|
5963
|
+
sessionId: null, // Will be set by client-side session recording
|
|
5964
|
+
posthogName: userData.email || userData.name || null // Update posthogName with email
|
|
5965
|
+
})
|
|
5966
|
+
});
|
|
5967
|
+
if (!response.ok) {
|
|
5968
|
+
const errorText = yield response.text();
|
|
5969
|
+
return {
|
|
5970
|
+
success: false,
|
|
5971
|
+
error: `Failed to identify user: ${response.status} ${response.statusText} - ${errorText}`
|
|
5972
|
+
};
|
|
5973
|
+
}
|
|
5974
|
+
return { success: true };
|
|
5975
|
+
}
|
|
5976
|
+
catch (error) {
|
|
5977
|
+
return {
|
|
5978
|
+
success: false,
|
|
5979
|
+
error: error instanceof Error ? error.message : 'Unknown error'
|
|
5980
|
+
};
|
|
5981
|
+
}
|
|
5982
|
+
});
|
|
5983
|
+
}
|
|
5984
|
+
|
|
5937
5985
|
/**
|
|
5938
5986
|
* Main entry point for the HumanBehavior SDK
|
|
5939
5987
|
*/
|
|
@@ -5947,6 +5995,7 @@ exports.HumanBehaviorTracker = HumanBehaviorTracker;
|
|
|
5947
5995
|
exports.MAX_CHUNK_SIZE_BYTES = MAX_CHUNK_SIZE_BYTES;
|
|
5948
5996
|
exports.RedactionManager = RedactionManager;
|
|
5949
5997
|
exports.default = HumanBehaviorTracker;
|
|
5998
|
+
exports.identifyUser = identifyUser;
|
|
5950
5999
|
exports.isChunkSizeExceeded = isChunkSizeExceeded;
|
|
5951
6000
|
exports.logDebug = logDebug;
|
|
5952
6001
|
exports.logError = logError;
|