kansoku-js 0.0.0-stage → 0.1.1
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 +16 -0
- package/LICENSE +21 -0
- package/README.md +210 -2
- package/THIRD_PARTY_NOTICES +206 -0
- package/dist/attribution.d.ts +5 -0
- package/dist/bot.d.ts +1 -0
- package/dist/client.d.ts +63 -0
- package/dist/context.d.ts +4 -0
- package/dist/contract/events.d.ts +12 -0
- package/dist/contract/validate.d.ts +6 -0
- package/dist/contract/wire.d.ts +18 -0
- package/dist/envelope.d.ts +24 -0
- package/dist/errors.d.ts +4 -0
- package/dist/experiment.d.ts +3 -0
- package/dist/generated/identifier-kinds.d.ts +1 -0
- package/dist/generated/schema.d.ts +4957 -0
- package/dist/generated/trait-schema.d.ts +12 -0
- package/dist/handoff.d.ts +3 -0
- package/dist/identity-api.d.ts +10 -0
- package/dist/identity.d.ts +12 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +33 -0
- package/dist/lifecycle.d.ts +1 -0
- package/dist/navigation.d.ts +4 -0
- package/dist/page.d.ts +33 -0
- package/dist/queue.d.ts +100 -0
- package/dist/retry.d.ts +17 -0
- package/dist/session.d.ts +12 -0
- package/dist/storage.d.ts +11 -0
- package/dist/transport.d.ts +11 -0
- package/dist/types.d.ts +100 -0
- package/dist/version.d.ts +1 -0
- package/dist/vitals-capture.d.ts +9 -0
- package/dist/vitals-gbna46ed.js +4 -0
- package/dist/vitals-gbna46ed.js.map +11 -0
- package/dist/vitals.d.ts +9 -0
- package/package.json +44 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# kansoku-js
|
|
2
|
+
|
|
3
|
+
## 0.1.1
|
|
4
|
+
|
|
5
|
+
No changes in this release.
|
|
6
|
+
|
|
7
|
+
## 0.1.0
|
|
8
|
+
|
|
9
|
+
### Minor Changes
|
|
10
|
+
|
|
11
|
+
- b1c1458: Initial browser SDK: page views with navigation and attribution capture, session
|
|
12
|
+
and identity helpers (including set-once traits and keyed email), experiment exposure,
|
|
13
|
+
bounded persistent batching with retries, and lifecycle-safe beacon/keepalive exit delivery
|
|
14
|
+
with `page_leave`. Cross-origin identity via parent-domain cookies and `linkTo` handoff,
|
|
15
|
+
configurable bot flagging, and opt-in client error and web vitals capture (measurement code
|
|
16
|
+
loads on demand). React provider and hooks support StrictMode and server rendering.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Nadeem Bitar
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,211 @@
|
|
|
1
|
-
#
|
|
1
|
+
# kansoku-js
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Browser SDK for the Kansoku analytics service. Zero runtime dependencies; ESM with TypeScript declarations.
|
|
4
|
+
|
|
5
|
+
```typescript
|
|
6
|
+
import { createKansoku } from "kansoku-js"
|
|
7
|
+
|
|
8
|
+
const analytics = createKansoku({
|
|
9
|
+
baseUrl: "https://analytics.example.com",
|
|
10
|
+
writeKey: "ksk_w_public_write_key",
|
|
11
|
+
})
|
|
12
|
+
analytics.track("signup_started", { plan: "team" })
|
|
13
|
+
await analytics.flush()
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Browser capture
|
|
17
|
+
|
|
18
|
+
By default the client records the initial `page_view`, History API navigations and
|
|
19
|
+
`session_start`. Each view can emit one best-effort `page_leave` on navigation or exit,
|
|
20
|
+
with a monotonic duration and the original page identity/session. BFCache restoration starts
|
|
21
|
+
a new view interval. Set `autocapture.pageLeave: false` to disable it. Initialise after the page title is set. Page views include the full URL,
|
|
22
|
+
path, title, document referrer and UTM attribution (`utmSource`, `utmMedium`, `utmCampaign`,
|
|
23
|
+
`utmContent`, `utmTerm`). History changes are captured on the next task so a router's
|
|
24
|
+
push/replace pair records once; hash-only changes are ignored.
|
|
25
|
+
|
|
26
|
+
Call `page(properties?, options?)` for explicit page views. Disable automatic capture with
|
|
27
|
+
`autocapture: { pageViews: false, sessions: false, pageLeave: false }`. `autoStart: false` defers the initial
|
|
28
|
+
page view and History patch until `start()`. `stop()` removes the patch; restarting on the
|
|
29
|
+
same URL does not record another initial view.
|
|
30
|
+
|
|
31
|
+
Each event collects locale, timezone, screen size, viewport size, user agent and library
|
|
32
|
+
version. `options.context` can override these values. No IP address, fingerprint or precise
|
|
33
|
+
location is collected by the SDK. URLs and caller-supplied properties may contain personal
|
|
34
|
+
data: use `beforeSend` to redact them.
|
|
35
|
+
|
|
36
|
+
The default `botDetection: "flag"` adds Boolean context.bot using a bounded synthetic v1
|
|
37
|
+
matcher and preserves an existing true. `"drop"` reports bot drops through onDrop/statistics;
|
|
38
|
+
`"off"` adds no client flag. Privacy gates run first. The server independently classifies its
|
|
39
|
+
request user agent, so client off does not turn off server bot handling.
|
|
40
|
+
|
|
41
|
+
See [one account across several properties](../../docs/guides/cross-origin-identity.md) for
|
|
42
|
+
parent-domain cookies, open-tab reset/opt-out synchronization and explicit allowlisted linkTo
|
|
43
|
+
handoff. Cross-site handoff acceptance is opt-in; it is not authentication.
|
|
44
|
+
|
|
45
|
+
## Identity and experiments
|
|
46
|
+
|
|
47
|
+
`identify(userId, traits?, options?)` persists the user ID and sends governed set traits with
|
|
48
|
+
explicit schema version 2. `identifyOnce(userId, traits?, options?)` does the same with set-once
|
|
49
|
+
version 1. Both preserve the anonymous ID for server stitching. Governed string traits are
|
|
50
|
+
`plan`, `signup_source`, `initial_plan`, `country` and `role`; `company_size` is a finite,
|
|
51
|
+
nonnegative integer. Omitted traits stay unchanged and null is rejected. Set-once initializes
|
|
52
|
+
an unset value; a later set replaces it. An explicit `{ schemaVersion: 1 }` on identify retains
|
|
53
|
+
identity-only behavior. Current traits can reclassify historical metrics and are public
|
|
54
|
+
analytics observations, never access-control facts.
|
|
55
|
+
`alias(previousId, newId, properties?)` links identities for one event and leaves the stored
|
|
56
|
+
user unchanged. Its ID arguments override any same-named custom properties.
|
|
57
|
+
`group(organizationId, properties?)` persists the organisation for later
|
|
58
|
+
events. `setIdentifiers({ device, fingerprint, email_hmac, email_sha256, cookie })` replaces optional
|
|
59
|
+
identity signals; provide only the keys needed. Values must contain 1–256 printable,
|
|
60
|
+
non-space ASCII characters. The anonymous ID already supplies the implicit cookie signal.
|
|
61
|
+
|
|
62
|
+
`reset()` clears user, organisation, signals and exposure history and rotates anonymous and
|
|
63
|
+
session IDs. Events already queued retain their original attribution. Call it explicitly at logout.
|
|
64
|
+
|
|
65
|
+
`experiment(name, variant, properties?, { force?: boolean })` records `experiment_viewed`
|
|
66
|
+
when a variant is actually shown. Names match `^[a-z0-9_.:-]{1,128}$`. The same pair is sent
|
|
67
|
+
once per session unless `force: true` is given; it can be recorded again after `reset()`.
|
|
68
|
+
The SDK records exposure and does not assign variants or evaluate feature flags.
|
|
69
|
+
|
|
70
|
+
`respectGlobalPrivacyControl: true` honors `navigator.globalPrivacyControl === true`.
|
|
71
|
+
`respectDoNotTrack: true` honors the legacy DNT signal. Both default to false. These gates
|
|
72
|
+
and opt-out silently skip automatic capture; explicit calls report `opted_out` drops.
|
|
73
|
+
|
|
74
|
+
## Core API
|
|
75
|
+
|
|
76
|
+
`track(name, properties?, options?)` queues an event with anonymous and session IDs.
|
|
77
|
+
`flush()` waits for pending batches. `stats` reports queued, accepted, bestEffortQueued, rejected and dropped
|
|
78
|
+
counts. `onDrop(info)` receives `bot`, `queue_full`, `rejected`, `permanent_error`,
|
|
79
|
+
`retries_exhausted`, `before_send`, `opted_out` or `invalid` and the affected events.
|
|
80
|
+
`beforeSend(event)` can redact fields or return `null` to drop an event.
|
|
81
|
+
|
|
82
|
+
The client starts automatically. Pass `autoStart: false` to defer listeners and timers;
|
|
83
|
+
call `start()` to activate them and `stop()` to remove them and begin a final flush.
|
|
84
|
+
Both calls are idempotent and reversible. Framework integrations should pair them in their
|
|
85
|
+
effect setup and cleanup. `shutdown()` stops, awaits the final flush and permanently closes
|
|
86
|
+
the client. Explicit tracking while stopped still queues events.
|
|
87
|
+
|
|
88
|
+
`optOut()` persists suppression and drops queued events; `optIn()` resumes acceptance.
|
|
89
|
+
`getAnonymousId()`, `getUserId()` and `getSessionId()` expose current identity.
|
|
90
|
+
Sessions renew after thirty minutes of inactivity by default.
|
|
91
|
+
|
|
92
|
+
## Delivery and storage
|
|
93
|
+
|
|
94
|
+
Normal deliveries use `POST /v1/batch` with the public write key in `X-Api-Key`.
|
|
95
|
+
HTTP 202 ends delivery, including individual rejections, which are counted as drops.
|
|
96
|
+
400, 401, 403, 404 and non-retryable 503 responses are permanent. Oversized batches (413)
|
|
97
|
+
are split; an oversized single event is dropped. Unknown outcomes, transient 503 responses,
|
|
98
|
+
network failures and timeouts retry with the same IDs and bounded exponential full jitter.
|
|
99
|
+
A positive whole-second 429 Retry-After is a minimum delay. Every transmission stamps a
|
|
100
|
+
serialization copy with sentAt from the same injected now clock; producer content and IDs stay fixed.
|
|
101
|
+
|
|
102
|
+
Defaults: flush at 20 events or every five seconds, 100 events and 1 MiB per request,
|
|
103
|
+
1000 queued events, five retries, ten-second request timeout. The newest event is dropped
|
|
104
|
+
when the queue is full. `schemaVersions` supplies event-level pins; a call's
|
|
105
|
+
`options.schemaVersion` takes precedence. Supported versions are integers in `1..65535`.
|
|
106
|
+
|
|
107
|
+
Identity, session and opt-out state use localStorage by default. Choose `storage: "cookie"`,
|
|
108
|
+
`"memory"` or a custom `{ get, set, remove }` adapter. Keys use `storageKeyPrefix` (`kansoku`):
|
|
109
|
+
`.anonymous_id`, `.user_id`, `.organization_id`, `.identifiers`, `.session`, `.opt_out`.
|
|
110
|
+
The `.queue` mirror always uses per-tab sessionStorage (`persistQueue: false` disables it).
|
|
111
|
+
Blocked browser storage falls back to memory. No fingerprint is generated. Keyed email identifiers are opaque backend-produced values; never expose the HMAC pepper to browser code. The normalization and rotation contract is owned by `mori://shinzui/kansoku` (`docs/guides/send-events.md`; artifact-level URI pending).
|
|
112
|
+
|
|
113
|
+
On page exit, `exitTransport: "keepalive"` is the default. Opt into `"beacon"` with a server
|
|
114
|
+
containing `mori://shinzui/kansoku/plans/39-beacon-ingest-route-for-page-exit-delivery`.
|
|
115
|
+
Beacon sends a text/plain UTF-8 `{writeKey,batch}` envelope at `/v1/beacon`. No query-string
|
|
116
|
+
credential or auth header is used. A true return increments `bestEffortQueued` and retains
|
|
117
|
+
every mirrored event; it never increments accepted or permits HTTP-status fallback. False,
|
|
118
|
+
missing or throwing APIs try keepalive fetch if the shared allowance permits. A later normal
|
|
119
|
+
acknowledged retry removes the same IDs using server deduplication.
|
|
120
|
+
|
|
121
|
+
All client instances share a conservative 60 KiB allowance per document, measuring complete
|
|
122
|
+
UTF-8 serialized bodies including sentAt and body credentials. Keepalive reservations release
|
|
123
|
+
when fetch settles; beacon has no completion callback, so its reservation lasts for that
|
|
124
|
+
document, including BFCache restoration. Oversized events remain queued for normal delivery.
|
|
125
|
+
Visibilitychange followed by pagehide performs one exit attempt. Other scripts can still consume
|
|
126
|
+
the browser's shared quota; both exit transports may fail. Pending events are bounded by queue
|
|
127
|
+
capacity, remain in per-tab sessionStorage when enabled, and can be lost when the tab closes.
|
|
128
|
+
|
|
129
|
+
The package imports safely without browser globals. Supported Node versions can use
|
|
130
|
+
`require(esm)` (Node 20.19+, or 22.12+ on Node 22). Jest's default CommonJS mode needs an
|
|
131
|
+
ESM transform allowlist or native ESM configuration.
|
|
132
|
+
|
|
133
|
+
## TypeScript reference
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
export interface KansokuOptions {
|
|
137
|
+
baseUrl: string
|
|
138
|
+
writeKey: string
|
|
139
|
+
sourceService?: string
|
|
140
|
+
autoStart?: boolean
|
|
141
|
+
flushAt?: number
|
|
142
|
+
flushIntervalMs?: number
|
|
143
|
+
maxQueueSize?: number
|
|
144
|
+
maxBatchEvents?: number
|
|
145
|
+
maxBatchBytes?: number
|
|
146
|
+
maxRetries?: number
|
|
147
|
+
retryBaseDelayMs?: number
|
|
148
|
+
requestTimeoutMs?: number
|
|
149
|
+
persistQueue?: boolean
|
|
150
|
+
storage?: "localStorage" | "cookie" | "memory" | StorageAdapter
|
|
151
|
+
storageKeyPrefix?: string
|
|
152
|
+
cookieDomain?: string
|
|
153
|
+
sessionTimeoutMs?: number
|
|
154
|
+
schemaVersions?: Record<string, number>
|
|
155
|
+
autocapture?: { pageViews?: boolean; sessions?: boolean }
|
|
156
|
+
optOut?: boolean
|
|
157
|
+
respectDoNotTrack?: boolean
|
|
158
|
+
respectGlobalPrivacyControl?: boolean
|
|
159
|
+
beforeSend?: (event: AnalyticsEvent) => AnalyticsEvent | null
|
|
160
|
+
onDrop?: (info: DropInfo) => void
|
|
161
|
+
fetch?: typeof globalThis.fetch
|
|
162
|
+
now?: () => number
|
|
163
|
+
timers?: { setTimeout: typeof setTimeout; clearTimeout: typeof clearTimeout }
|
|
164
|
+
debug?: boolean
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export interface KansokuClient {
|
|
168
|
+
page(properties?: JsonObject, options?: TrackOptions): void
|
|
169
|
+
identify(userId: string, traits?: JsonObject, options?: TrackOptions): void
|
|
170
|
+
identifyOnce(userId: string, traits?: JsonObject, options?: TrackOptions): void
|
|
171
|
+
alias(previousId: string, newId: string, properties?: JsonObject): void
|
|
172
|
+
group(organizationId: string, properties?: JsonObject): void
|
|
173
|
+
experiment(
|
|
174
|
+
experiment: string,
|
|
175
|
+
variant: string,
|
|
176
|
+
properties?: JsonObject,
|
|
177
|
+
options?: ExperimentOptions,
|
|
178
|
+
): void
|
|
179
|
+
setIdentifiers(identifiers: Partial<Record<IdentifierKind, string>>): void
|
|
180
|
+
reset(): void
|
|
181
|
+
track(eventName: string, properties?: JsonObject, options?: TrackOptions): void
|
|
182
|
+
flush(): Promise<void>
|
|
183
|
+
start(): void
|
|
184
|
+
stop(): void
|
|
185
|
+
shutdown(): Promise<void>
|
|
186
|
+
optOut(): void
|
|
187
|
+
optIn(): void
|
|
188
|
+
isOptedOut(): boolean
|
|
189
|
+
getAnonymousId(): string
|
|
190
|
+
getUserId(): string | undefined
|
|
191
|
+
getSessionId(): string
|
|
192
|
+
readonly stats: Readonly<KansokuStats>
|
|
193
|
+
readonly config: ResolvedKansokuOptions
|
|
194
|
+
}
|
|
195
|
+
export interface ExperimentOptions {
|
|
196
|
+
force?: boolean
|
|
197
|
+
}
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
### Optional browser diagnostics
|
|
201
|
+
|
|
202
|
+
`autocapture.clientErrors` and `autocapture.webVitals` are independent Boolean options, both
|
|
203
|
+
`false` by default. Set either to `true` to capture sanitized uncaught errors or document-scoped
|
|
204
|
+
performance measurements through the usual queue and `beforeSend`. Errors are bounded to ten
|
|
205
|
+
per recorded view and thirty per minute. Vitals load a separate measurement file on demand;
|
|
206
|
+
FCP/TTFB report immediately and LCP/CLS/INP finalize once on exit. They describe the first page
|
|
207
|
+
view of a document or BFCache restore, not later SPA routes. Reset/opt-out retire pending
|
|
208
|
+
attribution. Both event types count as server engagement and can change bounce and duration
|
|
209
|
+
reports. Read the [delivery and privacy guide](../../docs/guides/delivery-and-privacy.md#optional-client-errors-and-web-vitals)
|
|
210
|
+
for sanitization, units, exclusions, lifecycle and privacy details. The vanilla example's
|
|
211
|
+
`?capture=1` switch enables both and exposes a **Throw error** button.
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
web-vitals 6.2.3
|
|
2
|
+
Copyright 2020 Google LLC
|
|
3
|
+
https://github.com/GoogleChrome/web-vitals
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
Apache License
|
|
7
|
+
Version 2.0, January 2004
|
|
8
|
+
http://www.apache.org/licenses/
|
|
9
|
+
|
|
10
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
11
|
+
|
|
12
|
+
1. Definitions.
|
|
13
|
+
|
|
14
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
15
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
16
|
+
|
|
17
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
18
|
+
the copyright owner that is granting the License.
|
|
19
|
+
|
|
20
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
21
|
+
other entities that control, are controlled by, or are under common
|
|
22
|
+
control with that entity. For the purposes of this definition,
|
|
23
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
24
|
+
direction or management of such entity, whether by contract or
|
|
25
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
26
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
27
|
+
|
|
28
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
29
|
+
exercising permissions granted by this License.
|
|
30
|
+
|
|
31
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
32
|
+
including but not limited to software source code, documentation
|
|
33
|
+
source, and configuration files.
|
|
34
|
+
|
|
35
|
+
"Object" form shall mean any form resulting from mechanical
|
|
36
|
+
transformation or translation of a Source form, including but
|
|
37
|
+
not limited to compiled object code, generated documentation,
|
|
38
|
+
and conversions to other media types.
|
|
39
|
+
|
|
40
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
41
|
+
Object form, made available under the License, as indicated by a
|
|
42
|
+
copyright notice that is included in or attached to the work
|
|
43
|
+
(an example is provided in the Appendix below).
|
|
44
|
+
|
|
45
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
46
|
+
form, that is based on (or derived from) the Work and for which the
|
|
47
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
48
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
49
|
+
of this License, Derivative Works shall not include works that remain
|
|
50
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
51
|
+
the Work and Derivative Works thereof.
|
|
52
|
+
|
|
53
|
+
"Contribution" shall mean any work of authorship, including
|
|
54
|
+
the original version of the Work and any modifications or additions
|
|
55
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
56
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
57
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
58
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
59
|
+
means any form of electronic, verbal, or written communication sent
|
|
60
|
+
to the Licensor or its representatives, including but not limited to
|
|
61
|
+
communication on electronic mailing lists, source code control systems,
|
|
62
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
63
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
64
|
+
excluding communication that is conspicuously marked or otherwise
|
|
65
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
66
|
+
|
|
67
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
68
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
69
|
+
subsequently incorporated within the Work.
|
|
70
|
+
|
|
71
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
72
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
73
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
74
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
75
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
76
|
+
Work and such Derivative Works in Source or Object form.
|
|
77
|
+
|
|
78
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
79
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
80
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
81
|
+
(except as stated in this section) patent license to make, have made,
|
|
82
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
83
|
+
where such license applies only to those patent claims licensable
|
|
84
|
+
by such Contributor that are necessarily infringed by their
|
|
85
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
86
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
87
|
+
institute patent litigation against any entity (including a
|
|
88
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
89
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
90
|
+
or contributory patent infringement, then any patent licenses
|
|
91
|
+
granted to You under this License for that Work shall terminate
|
|
92
|
+
as of the date such litigation is filed.
|
|
93
|
+
|
|
94
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
95
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
96
|
+
modifications, and in Source or Object form, provided that You
|
|
97
|
+
meet the following conditions:
|
|
98
|
+
|
|
99
|
+
(a) You must give any other recipients of the Work or
|
|
100
|
+
Derivative Works a copy of this License; and
|
|
101
|
+
|
|
102
|
+
(b) You must cause any modified files to carry prominent notices
|
|
103
|
+
stating that You changed the files; and
|
|
104
|
+
|
|
105
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
106
|
+
that You distribute, all copyright, patent, trademark, and
|
|
107
|
+
attribution notices from the Source form of the Work,
|
|
108
|
+
excluding those notices that do not pertain to any part of
|
|
109
|
+
the Derivative Works; and
|
|
110
|
+
|
|
111
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
112
|
+
distribution, then any Derivative Works that You distribute must
|
|
113
|
+
include a readable copy of the attribution notices contained
|
|
114
|
+
within such NOTICE file, excluding those notices that do not
|
|
115
|
+
pertain to any part of the Derivative Works, in at least one
|
|
116
|
+
of the following places: within a NOTICE text file distributed
|
|
117
|
+
as part of the Derivative Works; within the Source form or
|
|
118
|
+
documentation, if provided along with the Derivative Works; or,
|
|
119
|
+
within a display generated by the Derivative Works, if and
|
|
120
|
+
wherever such third-party notices normally appear. The contents
|
|
121
|
+
of the NOTICE file are for informational purposes only and
|
|
122
|
+
do not modify the License. You may add Your own attribution
|
|
123
|
+
notices within Derivative Works that You distribute, alongside
|
|
124
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
125
|
+
that such additional attribution notices cannot be construed
|
|
126
|
+
as modifying the License.
|
|
127
|
+
|
|
128
|
+
You may add Your own copyright statement to Your modifications and
|
|
129
|
+
may provide additional or different license terms and conditions
|
|
130
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
131
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
132
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
133
|
+
the conditions stated in this License.
|
|
134
|
+
|
|
135
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
136
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
137
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
138
|
+
this License, without any additional terms or conditions.
|
|
139
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
140
|
+
the terms of any separate license agreement you may have executed
|
|
141
|
+
with Licensor regarding such Contributions.
|
|
142
|
+
|
|
143
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
144
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
145
|
+
except as required for reasonable and customary use in describing the
|
|
146
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
147
|
+
|
|
148
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
149
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
150
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
151
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
152
|
+
implied, including, without limitation, any warranties or conditions
|
|
153
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
154
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
155
|
+
appropriateness of using or redistributing the Work and assume any
|
|
156
|
+
risks associated with Your exercise of permissions under this License.
|
|
157
|
+
|
|
158
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
159
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
160
|
+
unless required by applicable law (such as deliberate and grossly
|
|
161
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
162
|
+
liable to You for damages, including any direct, indirect, special,
|
|
163
|
+
incidental, or consequential damages of any character arising as a
|
|
164
|
+
result of this License or out of the use or inability to use the
|
|
165
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
166
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
167
|
+
other commercial damages or losses), even if such Contributor
|
|
168
|
+
has been advised of the possibility of such damages.
|
|
169
|
+
|
|
170
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
171
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
172
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
173
|
+
or other liability obligations and/or rights consistent with this
|
|
174
|
+
License. However, in accepting such obligations, You may act only
|
|
175
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
176
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
177
|
+
defend, and hold each Contributor harmless for any liability
|
|
178
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
179
|
+
of your accepting any such warranty or additional liability.
|
|
180
|
+
|
|
181
|
+
END OF TERMS AND CONDITIONS
|
|
182
|
+
|
|
183
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
184
|
+
|
|
185
|
+
To apply the Apache License to your work, attach the following
|
|
186
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
187
|
+
replaced with your own identifying information. (Don't include
|
|
188
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
189
|
+
comment syntax for the file format. We also recommend that a
|
|
190
|
+
file or class name and description of purpose be included on the
|
|
191
|
+
same "printed page" as the copyright notice for easier
|
|
192
|
+
identification within third-party archives.
|
|
193
|
+
|
|
194
|
+
Copyright 2020 Google LLC
|
|
195
|
+
|
|
196
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
197
|
+
you may not use this file except in compliance with the License.
|
|
198
|
+
You may obtain a copy of the License at
|
|
199
|
+
|
|
200
|
+
https://www.apache.org/licenses/LICENSE-2.0
|
|
201
|
+
|
|
202
|
+
Unless required by applicable law or agreed to in writing, software
|
|
203
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
204
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
205
|
+
See the License for the specific language governing permissions and
|
|
206
|
+
limitations under the License.
|
package/dist/bot.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isBot(userAgent: string): boolean;
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { AnalyticsEvent, JsonObject } from "./contract/wire.js";
|
|
2
|
+
import type { WebFields } from "./envelope.js";
|
|
3
|
+
import type { DropReason, KansokuClient, KansokuOptions, ResolvedKansokuOptions, TrackOptions } from "./types.js";
|
|
4
|
+
export declare function resolveOptions(options: KansokuOptions): ResolvedKansokuOptions;
|
|
5
|
+
export declare function createInternalClient(options: KansokuOptions, deferStart?: boolean): {
|
|
6
|
+
config: Readonly<Required<Omit<KansokuOptions, "beforeSend" | "onDrop" | "cookieDomain">> & Pick<KansokuOptions, "beforeSend" | "onDrop" | "cookieDomain">>;
|
|
7
|
+
readonly stats: Readonly<{
|
|
8
|
+
accepted: number;
|
|
9
|
+
bestEffortQueued: number;
|
|
10
|
+
rejected: number;
|
|
11
|
+
dropped: number;
|
|
12
|
+
queued: number;
|
|
13
|
+
}>;
|
|
14
|
+
track(name: string, properties?: JsonObject, trackOptions?: TrackOptions): void;
|
|
15
|
+
flush: () => Promise<void>;
|
|
16
|
+
start(): void;
|
|
17
|
+
stop(): void;
|
|
18
|
+
shutdown(): Promise<void>;
|
|
19
|
+
optOut(): void;
|
|
20
|
+
optIn(): void;
|
|
21
|
+
isOptedOut: () => boolean;
|
|
22
|
+
getAnonymousId: () => string;
|
|
23
|
+
getUserId: () => string | undefined;
|
|
24
|
+
getSessionId: () => string;
|
|
25
|
+
buildEvent: (name: string, properties?: JsonObject, trackOptions?: TrackOptions, webFields?: WebFields, ids?: {
|
|
26
|
+
anonymousId?: string;
|
|
27
|
+
userId?: string;
|
|
28
|
+
}) => AnalyticsEvent;
|
|
29
|
+
enqueueBuilt: (event: AnalyticsEvent, save?: boolean) => boolean;
|
|
30
|
+
enqueueMany(events: AnalyticsEvent[]): void;
|
|
31
|
+
registerContextProvider(provider: () => JsonObject): () => void;
|
|
32
|
+
onStart: (install: () => (() => void) | void) => void;
|
|
33
|
+
onExit(listener: () => void): () => void;
|
|
34
|
+
drop: (reason: DropReason, events: AnalyticsEvent[], detail?: string) => void;
|
|
35
|
+
isSuppressed: () => boolean;
|
|
36
|
+
isStarted: () => boolean;
|
|
37
|
+
setSuppression(check: () => boolean): void;
|
|
38
|
+
identity: {
|
|
39
|
+
hadPersistedIdentity: boolean;
|
|
40
|
+
adoptAnonymousId(value: string): void;
|
|
41
|
+
snapshot(): import("./envelope.js").IdentitySnapshot;
|
|
42
|
+
setUserId(value: string): void;
|
|
43
|
+
setOrganizationId(value: string): void;
|
|
44
|
+
setIdentifiers(value: Partial<Record<import("./types.js").IdentifierKind, string>>): void;
|
|
45
|
+
rotateAnonymousId(): string;
|
|
46
|
+
clearUser(): void;
|
|
47
|
+
};
|
|
48
|
+
session: {
|
|
49
|
+
current(nowMs: number): {
|
|
50
|
+
id: string;
|
|
51
|
+
started: boolean;
|
|
52
|
+
};
|
|
53
|
+
touch(nowMs: number): void;
|
|
54
|
+
rotate: (nowMs: number) => {
|
|
55
|
+
id: string;
|
|
56
|
+
started: boolean;
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
storage: import("./types.js").StorageAdapter;
|
|
60
|
+
rotateSession(): void;
|
|
61
|
+
};
|
|
62
|
+
export type InternalClient = ReturnType<typeof createInternalClient>;
|
|
63
|
+
export declare function createKansoku(options: KansokuOptions): KansokuClient;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const PAGE_VIEW = "page_view";
|
|
2
|
+
export declare const SESSION_START = "session_start";
|
|
3
|
+
export declare const EXPERIMENT_VIEWED = "experiment_viewed";
|
|
4
|
+
export declare const IDENTIFY = "identify";
|
|
5
|
+
export declare const IDENTIFY_ONCE = "identify_once";
|
|
6
|
+
export declare const ALIAS = "alias";
|
|
7
|
+
export declare const GROUP = "group";
|
|
8
|
+
export declare const BUILT_IN_SCHEMA_VERSIONS: Readonly<Record<string, number>>;
|
|
9
|
+
export { IDENTIFIER_KINDS } from "../generated/identifier-kinds.js";
|
|
10
|
+
export declare const MIN_SCHEMA_VERSION = 1;
|
|
11
|
+
export declare const MAX_SCHEMA_VERSION = 65535;
|
|
12
|
+
export declare const EXPERIMENT_NAME_PATTERN: RegExp;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { AnalyticsEvent } from "./wire.js";
|
|
2
|
+
export declare function isPlainObject(value: unknown): value is Record<string, unknown>;
|
|
3
|
+
export declare function validateIdentifiers(value: unknown): string[];
|
|
4
|
+
export declare function validateExperimentName(value: unknown): boolean;
|
|
5
|
+
export declare function validateEvent(event: AnalyticsEvent): string[];
|
|
6
|
+
export declare function validateGovernedTraits(event: Pick<AnalyticsEvent, "eventName" | "schemaVersion" | "userId" | "properties">): string[];
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { components } from "../generated/schema.js";
|
|
2
|
+
export type JsonValue = string | number | boolean | null | JsonObject | JsonValue[];
|
|
3
|
+
export interface JsonObject {
|
|
4
|
+
[key: string]: JsonValue;
|
|
5
|
+
}
|
|
6
|
+
export type { paths } from "../generated/schema.js";
|
|
7
|
+
export type AnalyticsEvent = components["schemas"]["AnalyticsEvent"];
|
|
8
|
+
export type BeaconEnvelope = components["schemas"]["BeaconEnvelope"];
|
|
9
|
+
export type BatchAck = components["schemas"]["BatchAck"];
|
|
10
|
+
export type RejectedEvent = components["schemas"]["RejectedEvent"];
|
|
11
|
+
export type ProblemDetails = components["schemas"]["ProblemDetails"];
|
|
12
|
+
export type SchemaCatalog = components["schemas"]["SchemaCatalog"];
|
|
13
|
+
export type EventVersions = components["schemas"]["EventVersions"];
|
|
14
|
+
export type VersionedEventSchema = components["schemas"]["VersionedEventSchema"];
|
|
15
|
+
export type ContractProperty = components["schemas"]["ContractProperty"];
|
|
16
|
+
export type EventSource = components["schemas"]["EventSource"];
|
|
17
|
+
export type IngestAck = components["schemas"]["IngestAck"];
|
|
18
|
+
export type MetricPoint = components["schemas"]["MetricPoint"];
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { AnalyticsEvent, JsonObject } from "./contract/wire.js";
|
|
2
|
+
import type { IdentifierKind, TrackOptions } from "./types.js";
|
|
3
|
+
export interface IdentitySnapshot {
|
|
4
|
+
anonymousId: string;
|
|
5
|
+
userId?: string;
|
|
6
|
+
organizationId?: string;
|
|
7
|
+
identifiers?: Partial<Record<IdentifierKind, string>>;
|
|
8
|
+
}
|
|
9
|
+
export type WebFields = Pick<AnalyticsEvent, "url" | "referrer" | "utmSource" | "utmMedium" | "utmCampaign" | "utmContent" | "utmTerm">;
|
|
10
|
+
export interface EnvelopeDependencies {
|
|
11
|
+
identity: IdentitySnapshot;
|
|
12
|
+
sessionId: string;
|
|
13
|
+
config: {
|
|
14
|
+
sourceService?: string;
|
|
15
|
+
schemaVersions: Readonly<Record<string, number>>;
|
|
16
|
+
now: () => number;
|
|
17
|
+
};
|
|
18
|
+
baseContext?: JsonObject;
|
|
19
|
+
}
|
|
20
|
+
export declare function randomId(): string;
|
|
21
|
+
export declare function buildEvent(deps: EnvelopeDependencies, eventName: string, properties?: JsonObject, options?: TrackOptions, webFields?: WebFields, ids?: {
|
|
22
|
+
anonymousId?: string;
|
|
23
|
+
userId?: string;
|
|
24
|
+
}): AnalyticsEvent;
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { InternalClient } from "./client.js";
|
|
2
|
+
import type { AnalyticsEvent, JsonObject } from "./types.js";
|
|
3
|
+
export declare function errorProperties(value: unknown, rejection?: boolean, crossOrigin?: boolean): JsonObject;
|
|
4
|
+
export declare function createErrorCapture(core: InternalClient, snapshot: () => AnalyticsEvent | undefined, copy: (original: AnalyticsEvent, name: string, properties: JsonObject) => AnalyticsEvent): () => void;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { InternalClient } from "./client.js";
|
|
2
|
+
import type { ExperimentOptions, JsonObject } from "./types.js";
|
|
3
|
+
export declare function recordExposure(client: InternalClient, experiment: string, variant: string, properties?: JsonObject, options?: ExperimentOptions): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const IDENTIFIER_KINDS: readonly ["cookie", "device", "fingerprint", "email_sha256", "email_hmac"];
|