@daybook/analytics 0.3.0 → 0.4.0
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/CHANGELOG.md +66 -47
- package/LICENSE +21 -21
- package/README.md +536 -447
- package/dist/browser.js +99 -8
- package/dist/client.d.ts +32 -2
- package/dist/client.js +51 -11
- package/dist/daybook.js +1 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.js +10 -1
- package/dist/module.d.ts +17 -0
- package/dist/module.js +70 -0
- package/dist/storage.d.ts +11 -0
- package/dist/storage.js +40 -0
- package/dist/types.d.ts +4 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +85 -80
package/dist/storage.js
CHANGED
|
@@ -4,6 +4,7 @@ export function memoryStore() {
|
|
|
4
4
|
get: (name) => values.get(name) ?? null,
|
|
5
5
|
set: (name, value) => void values.set(name, value),
|
|
6
6
|
remove: (name) => void values.delete(name),
|
|
7
|
+
names: () => [...values.keys()],
|
|
7
8
|
};
|
|
8
9
|
}
|
|
9
10
|
/**
|
|
@@ -43,6 +44,14 @@ export function webStore(kind) {
|
|
|
43
44
|
}
|
|
44
45
|
catch { /* blocked */ }
|
|
45
46
|
},
|
|
47
|
+
names: () => {
|
|
48
|
+
try {
|
|
49
|
+
return Array.from({ length: storage.length }, (_, i) => storage.key(i)).filter((n) => typeof n === 'string');
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return [];
|
|
53
|
+
}
|
|
54
|
+
},
|
|
46
55
|
};
|
|
47
56
|
}
|
|
48
57
|
/**
|
|
@@ -77,6 +86,14 @@ export function cookieStore(domain) {
|
|
|
77
86
|
}
|
|
78
87
|
catch { /* blocked */ }
|
|
79
88
|
},
|
|
89
|
+
names: () => {
|
|
90
|
+
try {
|
|
91
|
+
return document.cookie.split('; ').map((c) => c.split('=')[0] ?? '').filter(Boolean);
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
return [];
|
|
95
|
+
}
|
|
96
|
+
},
|
|
80
97
|
};
|
|
81
98
|
}
|
|
82
99
|
/** The store a persistence choice gets, falling back to memory where the browser refuses it. */
|
|
@@ -100,3 +117,26 @@ export function readState(store, name) {
|
|
|
100
117
|
return null;
|
|
101
118
|
}
|
|
102
119
|
}
|
|
120
|
+
/**
|
|
121
|
+
* The state this browser kept under another key of the same site, newest first by its session: what a
|
|
122
|
+
* site that started analytics with its hub key (`dak_…`) has when it moves to the site's one key
|
|
123
|
+
* (`dbk_…`). The stored name carries the key's first letters, so a new key is a new name, and without
|
|
124
|
+
* this the visitor would be somebody new (PM-T-0971).
|
|
125
|
+
*/
|
|
126
|
+
export function earlierState(store, ownName) {
|
|
127
|
+
let found = null;
|
|
128
|
+
for (const name of store.names()) {
|
|
129
|
+
if (name === ownName || !/^dbk_[A-Za-z0-9]{1,8}$/.test(name))
|
|
130
|
+
continue;
|
|
131
|
+
const state = readState(store, name);
|
|
132
|
+
if (!state || (typeof state.anon !== 'string' && state.consent === undefined))
|
|
133
|
+
continue;
|
|
134
|
+
if (!found || (state.session?.last ?? 0) > (found.session?.last ?? 0))
|
|
135
|
+
found = state;
|
|
136
|
+
}
|
|
137
|
+
return found;
|
|
138
|
+
}
|
|
139
|
+
/** The name a key's state is kept under: two projects on one site keep apart by the key's first letters. */
|
|
140
|
+
export function stateNameOf(key) {
|
|
141
|
+
return `dbk_${key.trim().replace(/^dak_/, '').slice(0, 8)}`;
|
|
142
|
+
}
|
package/dist/types.d.ts
CHANGED
|
@@ -57,7 +57,10 @@ export interface AnalyticsEvent {
|
|
|
57
57
|
/** Where the SDK keeps the anonymous id, the session, registered properties and the consent choice. */
|
|
58
58
|
export type Persistence = 'localStorage' | 'cookie' | 'memory';
|
|
59
59
|
export interface AnalyticsOptions {
|
|
60
|
-
/**
|
|
60
|
+
/**
|
|
61
|
+
* The project's ingest key, `dak_…`, from Analytics → Settings, or the site's own key, `dbk_…`, from
|
|
62
|
+
* the project's settings. Either is public: it only says which project events are for.
|
|
63
|
+
*/
|
|
61
64
|
key: string;
|
|
62
65
|
/** Where Daybook's API is. Only for a self-hosted Daybook or a proxy of your own. */
|
|
63
66
|
apiUrl?: string;
|
package/dist/version.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* of the SDK its pages run. A constant rather than read from package.json at build time, because the
|
|
4
4
|
* npm build is plain tsc; test/version.test.js refuses a build where the two disagree.
|
|
5
5
|
*/
|
|
6
|
-
export declare const SDK_VERSION = "0.
|
|
6
|
+
export declare const SDK_VERSION = "0.4.0";
|
|
7
7
|
/**
|
|
8
8
|
* What the API records as every event's `source`, and one of the names it knows as a Daybook SDK
|
|
9
9
|
* (PM-T-0528): only those may send `$pageview` and `$pageleave`.
|
package/dist/version.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* of the SDK its pages run. A constant rather than read from package.json at build time, because the
|
|
4
4
|
* npm build is plain tsc; test/version.test.js refuses a build where the two disagree.
|
|
5
5
|
*/
|
|
6
|
-
export const SDK_VERSION = '0.
|
|
6
|
+
export const SDK_VERSION = '0.4.0';
|
|
7
7
|
/**
|
|
8
8
|
* What the API records as every event's `source`, and one of the names it knows as a Daybook SDK
|
|
9
9
|
* (PM-T-0528): only those may send `$pageview` and `$pageleave`.
|
package/package.json
CHANGED
|
@@ -1,80 +1,85 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@daybook/analytics",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Product analytics for the web: page views, sessions, attribution and your own events, sent to Daybook's Analytics hub. Plain JS, React and Vue.",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"main": "dist/index.js",
|
|
7
|
-
"types": "dist/index.d.ts",
|
|
8
|
-
"unpkg": "dist/daybook.js",
|
|
9
|
-
"jsdelivr": "dist/daybook.js",
|
|
10
|
-
"files": [
|
|
11
|
-
"dist",
|
|
12
|
-
"README.md",
|
|
13
|
-
"CHANGELOG.md"
|
|
14
|
-
],
|
|
15
|
-
"scripts": {
|
|
16
|
-
"build": "tsc -p tsconfig.json && npm run bundle",
|
|
17
|
-
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
18
|
-
"test": "node --test test/*.test.js",
|
|
19
|
-
"bundle": "esbuild
|
|
20
|
-
"prepublishOnly": "npm run build && npm test",
|
|
21
|
-
"release": "node ../../devops/publish-sdk.mjs analytics"
|
|
22
|
-
},
|
|
23
|
-
"peerDependencies": {
|
|
24
|
-
"react": ">=17",
|
|
25
|
-
"vue": ">=3.3"
|
|
26
|
-
},
|
|
27
|
-
"peerDependenciesMeta": {
|
|
28
|
-
"react": {
|
|
29
|
-
"optional": true
|
|
30
|
-
},
|
|
31
|
-
"vue": {
|
|
32
|
-
"optional": true
|
|
33
|
-
}
|
|
34
|
-
},
|
|
35
|
-
"devDependencies": {
|
|
36
|
-
"@types/react": "^19.3.0",
|
|
37
|
-
"esbuild": "^0.28.2",
|
|
38
|
-
"react": "^19.3.1",
|
|
39
|
-
"react-dom": "^19.3.1",
|
|
40
|
-
"typescript": "^5.7.2",
|
|
41
|
-
"vue": "^3.5.13"
|
|
42
|
-
},
|
|
43
|
-
"allowScripts": {
|
|
44
|
-
"esbuild@0.28.2": true
|
|
45
|
-
},
|
|
46
|
-
"exports": {
|
|
47
|
-
".": {
|
|
48
|
-
"types": "./dist/index.d.ts",
|
|
49
|
-
"import": "./dist/index.js"
|
|
50
|
-
},
|
|
51
|
-
"./react": {
|
|
52
|
-
"types": "./dist/react.d.ts",
|
|
53
|
-
"import": "./dist/react.js"
|
|
54
|
-
},
|
|
55
|
-
"./vue": {
|
|
56
|
-
"types": "./dist/vue.d.ts",
|
|
57
|
-
"import": "./dist/vue.js"
|
|
58
|
-
},
|
|
59
|
-
"./browser": "./dist/daybook.js"
|
|
60
|
-
},
|
|
61
|
-
"sideEffects": [
|
|
62
|
-
"./dist/
|
|
63
|
-
"./dist/
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
"
|
|
74
|
-
"
|
|
75
|
-
"
|
|
76
|
-
"
|
|
77
|
-
"
|
|
78
|
-
"
|
|
79
|
-
|
|
80
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@daybook/analytics",
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"description": "Product analytics for the web: page views, sessions, attribution and your own events, sent to Daybook's Analytics hub. Plain JS, React and Vue.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"unpkg": "dist/daybook.js",
|
|
9
|
+
"jsdelivr": "dist/daybook.js",
|
|
10
|
+
"files": [
|
|
11
|
+
"dist",
|
|
12
|
+
"README.md",
|
|
13
|
+
"CHANGELOG.md"
|
|
14
|
+
],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "tsc -p ../core/tsconfig.json && tsc -p tsconfig.json && npm run bundle",
|
|
17
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
18
|
+
"test": "node --test test/*.test.js",
|
|
19
|
+
"bundle": "esbuild dist/browser.js --bundle --format=iife --minify --target=es2019 --outfile=dist/daybook.js",
|
|
20
|
+
"prepublishOnly": "npm run build && npm test",
|
|
21
|
+
"release": "node ../../devops/publish-sdk.mjs analytics"
|
|
22
|
+
},
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"react": ">=17",
|
|
25
|
+
"vue": ">=3.3"
|
|
26
|
+
},
|
|
27
|
+
"peerDependenciesMeta": {
|
|
28
|
+
"react": {
|
|
29
|
+
"optional": true
|
|
30
|
+
},
|
|
31
|
+
"vue": {
|
|
32
|
+
"optional": true
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@types/react": "^19.3.0",
|
|
37
|
+
"esbuild": "^0.28.2",
|
|
38
|
+
"react": "^19.3.1",
|
|
39
|
+
"react-dom": "^19.3.1",
|
|
40
|
+
"typescript": "^5.7.2",
|
|
41
|
+
"vue": "^3.5.13"
|
|
42
|
+
},
|
|
43
|
+
"allowScripts": {
|
|
44
|
+
"esbuild@0.28.2": true
|
|
45
|
+
},
|
|
46
|
+
"exports": {
|
|
47
|
+
".": {
|
|
48
|
+
"types": "./dist/index.d.ts",
|
|
49
|
+
"import": "./dist/index.js"
|
|
50
|
+
},
|
|
51
|
+
"./react": {
|
|
52
|
+
"types": "./dist/react.d.ts",
|
|
53
|
+
"import": "./dist/react.js"
|
|
54
|
+
},
|
|
55
|
+
"./vue": {
|
|
56
|
+
"types": "./dist/vue.d.ts",
|
|
57
|
+
"import": "./dist/vue.js"
|
|
58
|
+
},
|
|
59
|
+
"./browser": "./dist/daybook.js"
|
|
60
|
+
},
|
|
61
|
+
"sideEffects": [
|
|
62
|
+
"./dist/index.js",
|
|
63
|
+
"./dist/module.js",
|
|
64
|
+
"./dist/browser.js",
|
|
65
|
+
"./dist/daybook.js"
|
|
66
|
+
],
|
|
67
|
+
"license": "MIT",
|
|
68
|
+
"publishConfig": {
|
|
69
|
+
"access": "public"
|
|
70
|
+
},
|
|
71
|
+
"homepage": "https://daybook.team",
|
|
72
|
+
"keywords": [
|
|
73
|
+
"analytics",
|
|
74
|
+
"product-analytics",
|
|
75
|
+
"events",
|
|
76
|
+
"pageviews",
|
|
77
|
+
"react",
|
|
78
|
+
"vue",
|
|
79
|
+
"nextjs",
|
|
80
|
+
"nuxt"
|
|
81
|
+
],
|
|
82
|
+
"dependencies": {
|
|
83
|
+
"@daybook/core": "^0.1.0"
|
|
84
|
+
}
|
|
85
|
+
}
|