Skip to content

Commit e6b234d

Browse files
committed
use new session id format
1 parent 53f0f40 commit e6b234d

File tree

4 files changed

+10
-19
lines changed

4 files changed

+10
-19
lines changed

packages/web/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.3.1
2+
3+
- use new session id format
4+
15
## 0.3.0
26

37
- Added an option to specify `isDebug` at init time

packages/web/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@aptabase/web",
3-
"version": "0.3.0",
3+
"version": "0.3.1",
44
"type": "module",
55
"description": "JavaScript SDK for Aptabase: Open Source, Privacy-First and Simple Analytics for Mobile, Desktop and Web Apps",
66
"main": "./dist/index.cjs",

packages/web/src/session.ts

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,5 @@
1-
export function newSessionId() {
2-
if (typeof crypto !== 'undefined' && crypto && crypto.randomUUID) {
3-
return crypto.randomUUID();
4-
}
5-
6-
return [randomStr(8), randomStr(4), randomStr(4), randomStr(4), randomStr(12)].join('-');
7-
}
8-
9-
const characters = 'abcdefghijklmnopqrstuvwxyz0123456789';
10-
const charactersLength = characters.length;
11-
12-
function randomStr(len: number) {
13-
let result = '';
14-
for (let i = 0; i < len; i++) {
15-
result += characters.charAt(Math.floor(Math.random() * charactersLength));
16-
}
17-
return result;
1+
export function newSessionId(): string {
2+
const epochInSeconds = BigInt(Math.floor(Date.now() / 1000));
3+
const random = BigInt(Math.floor(Math.random() * 100000000));
4+
return (epochInSeconds * 100000000n + random).toString();
185
}

packages/web/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"compilerOptions": {
3-
"target": "es6",
3+
"target": "es2020",
44
"strict": true,
55
"moduleResolution": "node",
66
"esModuleInterop": true,

0 commit comments

Comments
 (0)