posthog-js-lite 2.0.0-alpha5 → 2.0.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 +3 -0
- package/README.md +68 -0
- package/lib/index.cjs.js +269 -85
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +55 -12
- package/lib/index.esm.js +269 -85
- package/lib/index.esm.js.map +1 -1
- package/lib/posthog-core/src/index.d.ts +33 -9
- package/lib/posthog-core/src/types.d.ts +26 -3
- package/lib/posthog-core/src/utils.d.ts +0 -1
- package/lib/posthog-web/src/storage.d.ts +1 -5
- package/package.json +2 -2
- package/src/posthog-web.ts +5 -1
- package/src/storage.ts +18 -9
package/CHANGELOG.md
ADDED
package/README.md
CHANGED
|
@@ -1,3 +1,71 @@
|
|
|
1
1
|
# PostHog Web
|
|
2
2
|
|
|
3
3
|
> 🚧 This is a WIP. Currently the only officially supported way of using PostHog on the web is [posthog-js](https://github.com/PostHog/posthog-js)
|
|
4
|
+
|
|
5
|
+
This package is currently published to npm as [posthog-js-lite](https://www.npmjs.com/package/posthog-js-lite) and is a simplified version of the recommended and offically supported `posthog-js`.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm i -s posthog-js-lite
|
|
11
|
+
# or
|
|
12
|
+
yarn add posthog-js-lite
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
It is entirely written in Typescript and has a minimal API as follows:
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import PostHog from 'posthog-js-lite'
|
|
19
|
+
|
|
20
|
+
const posthog = new PostHog('my-api-key', {
|
|
21
|
+
/* options, e.g. for self-hosted users */
|
|
22
|
+
// host: "https://my-posthog.app.com"
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
// Capture generic events
|
|
26
|
+
posthog.capture('my-event', { myProperty: 'foo' })
|
|
27
|
+
|
|
28
|
+
// Identify a user (e.g. on login)
|
|
29
|
+
posthog.identify('my-unique-user-id', { email: 'exampke@posthog.com', name: 'Jane Doe' })
|
|
30
|
+
|
|
31
|
+
// Reset a user (e.g. on logout)
|
|
32
|
+
posthog.reset()
|
|
33
|
+
|
|
34
|
+
// Register properties to be sent with all subsequent events
|
|
35
|
+
posthog.register({ itemsInBasket: 3 })
|
|
36
|
+
// ...or get rid of them if you don't want them anymore
|
|
37
|
+
posthog.unregister('itemsInBasket')
|
|
38
|
+
|
|
39
|
+
// Add the user to a group
|
|
40
|
+
posthog.group('organisations', 'org-1')
|
|
41
|
+
// ...or multiple groups at once
|
|
42
|
+
posthog.group({ organisations: 'org-1', project: 'project-1' })
|
|
43
|
+
|
|
44
|
+
// Simple feature flags
|
|
45
|
+
if (posthog.isFeatureEnabled('my-feature-flag')) {
|
|
46
|
+
renderFlaggedFunctionality()
|
|
47
|
+
} else {
|
|
48
|
+
renderDefaultFunctionality()
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Multivariate feature flags
|
|
52
|
+
if (posthog.getFeatureFlag('my-feature-flag-with-variants') === 'variant1') {
|
|
53
|
+
renderVariant1()
|
|
54
|
+
} else if (posthog.getFeatureFlag('my-feature-flag-with-variants') === 'variant2') {
|
|
55
|
+
renderVariant1()
|
|
56
|
+
} else if (posthog.getFeatureFlag('my-feature-flag-with-variants') === 'control') {
|
|
57
|
+
renderControl()
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Override a feature flag for a specific user (e.g. for testing or user preference)
|
|
61
|
+
posthog.overrideFeatureFlag('my-feature-flag', true)
|
|
62
|
+
|
|
63
|
+
// Listen reactively to feature flag changes
|
|
64
|
+
posthog.onFeatureFlag('my-feature-flag', (value) => {
|
|
65
|
+
respondToFeatureFlagChange(value)
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
// Opt users in or out, persisting across sessions (default is they are opted in)
|
|
69
|
+
posthog.optOut() // Will stop tracking
|
|
70
|
+
posthog.optIn() // Will stop tracking
|
|
71
|
+
```
|