Skip to content
This repository was archived by the owner on Jul 29, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
140 commits
Select commit Hold shift + click to select a range
f647146
Added RN, web and Node all to this project
benjackwhite Jul 1, 2022
08ab2d0
More refactorings
benjackwhite Jul 1, 2022
b9aad7d
Tidying
benjackwhite Jul 1, 2022
b96c27c
Fixed fetch
benjackwhite Jul 3, 2022
e116331
Added tests from node lib
benjackwhite Jul 3, 2022
15cfc49
Added screen tracking helper for RN
benjackwhite Jul 3, 2022
ea3c1df
Moved files and added example expo app
benjackwhite Jul 4, 2022
fe6bf8a
Fixed up to work in expo
benjackwhite Jul 11, 2022
62dde42
Corrected route parsing logic
benjackwhite Jul 11, 2022
0b804f0
Added autocapture
benjackwhite Jul 11, 2022
3e39219
Added no-capture labels
benjackwhite Jul 11, 2022
69fac45
More fixes
benjackwhite Jul 11, 2022
05e4b11
Moved autocapture to core
benjackwhite Jul 12, 2022
5cd017e
Fixed some web bits
benjackwhite Jul 12, 2022
db63985
Added feature flag first pass
benjackwhite Jul 12, 2022
1677711
Added support for pulling stored values out of file system
benjackwhite Jul 12, 2022
0141f16
Added detox tests for E2E testing
benjackwhite Jul 13, 2022
cc2ddd9
Added simple event emitter and sync storage
benjackwhite Jul 14, 2022
a1c367a
Tidying
benjackwhite Jul 14, 2022
f3518d1
Simplified expo example
benjackwhite Jul 14, 2022
658fe89
Styles
benjackwhite Jul 14, 2022
302d19a
More tidying
benjackwhite Jul 15, 2022
d1091e1
Tests. Test everywhere
benjackwhite Jul 15, 2022
0a7cea2
Added test workflow
benjackwhite Jul 15, 2022
ac38a56
Fixed prepublish rubbish
benjackwhite Jul 15, 2022
3212981
Added more tests
benjackwhite Jul 15, 2022
80c20b1
Swapped wrappers over to new format
benjackwhite Jul 15, 2022
f7e6019
Fixed types
benjackwhite Jul 15, 2022
0e3c2b5
More tests and tidying
benjackwhite Jul 15, 2022
0f69c62
Tidying
benjackwhite Jul 15, 2022
d85dac1
Added test for tracking call
benjackwhite Jul 15, 2022
5d6b780
Added single feature flag hook
benjackwhite Jul 15, 2022
e940d32
Removed setImmediate in favour of settimeout with safe unref function
benjackwhite Jul 15, 2022
718c19d
Fixed build commands for web
benjackwhite Jul 18, 2022
8e50296
Persist feature flags
benjackwhite Jul 18, 2022
144528f
Added missing feature flags to common properties
benjackwhite Jul 18, 2022
7ac43e4
Added override function for feature flags
benjackwhite Jul 18, 2022
ebefc0d
Added reset tests
benjackwhite Jul 18, 2022
05f2e6c
Removed callbacks
benjackwhite Jul 18, 2022
f873fd3
Fixed tests
benjackwhite Jul 18, 2022
1f400be
Added wrapper for Node to use shared storage for queue
benjackwhite Jul 18, 2022
722610e
Fixed rollup
benjackwhite Jul 18, 2022
34a2540
Fixes
benjackwhite Jul 18, 2022
0f844e5
Fixes
benjackwhite Jul 18, 2022
8fa977e
Fixed package json
benjackwhite Jul 18, 2022
eb440ce
Added question
benjackwhite Jul 18, 2022
0f5843e
Setup nodejs to work correctly
benjackwhite Jul 19, 2022
ea9bd2c
Added READMEs
benjackwhite Jul 19, 2022
252c615
Fixed types and bundling
benjackwhite Jul 19, 2022
31040a5
Fix opt out logic
benjackwhite Jul 19, 2022
5ff325f
Renaming everything to just PostHog
benjackwhite Jul 19, 2022
fb0d0ce
Fix
benjackwhite Jul 19, 2022
225eb7b
Fix tests
benjackwhite Jul 19, 2022
5672cae
Added concurrency check to tests
benjackwhite Jul 19, 2022
f4efe41
Tests
benjackwhite Jul 19, 2022
143c934
Tests
benjackwhite Jul 19, 2022
c301514
Removed simlink
benjackwhite Jul 19, 2022
3328e1f
Fixed tests
benjackwhite Jul 19, 2022
6c803c8
Fixes
benjackwhite Jul 19, 2022
2310493
CI
benjackwhite Jul 19, 2022
92774e2
CI
benjackwhite Jul 20, 2022
160785d
CO
benjackwhite Jul 20, 2022
c01e3df
CI
benjackwhite Jul 20, 2022
cf7db0d
Fixed retries
benjackwhite Jul 20, 2022
897e79c
Added possible release flow
benjackwhite Jul 20, 2022
afd2374
CI
benjackwhite Jul 20, 2022
1aac185
Removed async storage dep
benjackwhite Jul 20, 2022
7135b47
CI
benjackwhite Jul 20, 2022
c8e8841
Tests
benjackwhite Jul 20, 2022
7e3c94a
fix
benjackwhite Jul 20, 2022
815bb30
CI
benjackwhite Jul 20, 2022
e57af2b
Updated package json
benjackwhite Jul 20, 2022
241258f
Fixed babel bundling for RN
benjackwhite Jul 20, 2022
570ccaf
Fixed autocapture
benjackwhite Jul 21, 2022
e00d342
Fixed preloading of data
benjackwhite Jul 21, 2022
11d929e
Sanitise labels as commas seem to be poorly parsed on the backend
benjackwhite Jul 21, 2022
902d16a
Better label finding
benjackwhite Jul 21, 2022
5892dc1
CI
benjackwhite Jul 21, 2022
5be97bc
Fix initial tracking
benjackwhite Jul 21, 2022
0c9999b
Fixes
benjackwhite Jul 21, 2022
6ca9aea
Fix
benjackwhite Jul 21, 2022
4a968f6
Fix
benjackwhite Jul 21, 2022
c411f2d
Fix
benjackwhite Jul 21, 2022
03a366b
Fixed tests
benjackwhite Jul 21, 2022
4db6b66
CI
benjackwhite Jul 21, 2022
0313f27
Added cache
benjackwhite Jul 21, 2022
c3cfb0d
CI
benjackwhite Jul 21, 2022
91dac0d
Updated README and added sessions
benjackwhite Jul 21, 2022
d8ac185
Moved config for navigation tracking
benjackwhite Jul 21, 2022
a46cb21
Fixes
benjackwhite Jul 21, 2022
cdb00a5
Removed check
benjackwhite Jul 21, 2022
0f2702f
Fixes
benjackwhite Jul 22, 2022
d984dea
Disabled e2e tests on CI for now
benjackwhite Jul 22, 2022
aa32dfe
Prettier and linting
benjackwhite Jul 22, 2022
e8477ed
Fix
benjackwhite Jul 22, 2022
b8cf3c9
Fix tests
benjackwhite Jul 22, 2022
2c6a701
Fixed to correct package name
benjackwhite Jul 22, 2022
53c5702
Fixed Node.js (except feature flags)
benjackwhite Jul 26, 2022
9284411
CI
benjackwhite Jul 26, 2022
52f90ad
Matrix release for all packages
benjackwhite Jul 26, 2022
b4f6050
Fix
benjackwhite Jul 26, 2022
1a4f3d1
Fixes
benjackwhite Jul 26, 2022
180a5c6
Fix
benjackwhite Jul 26, 2022
d535002
Updates
benjackwhite Jul 26, 2022
14c16c0
CI
benjackwhite Jul 26, 2022
6f04008
Fix web stuff
benjackwhite Jul 26, 2022
0376458
Fix
benjackwhite Jul 26, 2022
506aed9
Bump
benjackwhite Jul 26, 2022
8e0c280
Changed default delays
benjackwhite Jul 27, 2022
19eabef
Added enable / disable options
benjackwhite Jul 27, 2022
d1a1992
Fix
benjackwhite Jul 27, 2022
11f1bee
Added debug support
benjackwhite Jul 28, 2022
9ad5d58
Update node
benjackwhite Jul 28, 2022
3a9357a
Added storage options
benjackwhite Jul 28, 2022
e8d0774
Update versions
benjackwhite Jul 28, 2022
89cff3f
Fix for resetting of Node properties
benjackwhite Jul 28, 2022
1474fcd
Skip release for now
benjackwhite Jul 28, 2022
b3d24ce
Added test for feature flags
benjackwhite Jul 28, 2022
f2fdeb5
Bump version
benjackwhite Jul 28, 2022
116f4a2
Small fixes and tweaks
benjackwhite Jul 28, 2022
c33f6bd
Fixed anonymous id calls
benjackwhite Jul 28, 2022
810a596
Added back in valid test
benjackwhite Jul 28, 2022
6007958
Merge pull request #6 from PostHog/feat/anon-id-calls
benjackwhite Jul 28, 2022
25ee224
Fixed featureflags emit location
benjackwhite Aug 1, 2022
5319151
fix: Remove decide timer reloading
benjackwhite Aug 1, 2022
ac695c3
Removed other refs
benjackwhite Aug 1, 2022
71960b0
Limit autocapture to only include specific props
benjackwhite Aug 1, 2022
de7546a
Added autocapture tests
benjackwhite Aug 2, 2022
e8b375b
Fix decide response check
benjackwhite Aug 2, 2022
be48c47
Merge pull request #7 from PostHog/fix/decide-reload
benjackwhite Aug 2, 2022
71b34c5
Fix tests
benjackwhite Aug 2, 2022
9351e7b
Merge pull request #8 from PostHog/feat/simple-autocapture
benjackwhite Aug 2, 2022
5d7f0f2
Fix for publishing release
benjackwhite Aug 2, 2022
e433557
Added README for posthog-web
benjackwhite Aug 2, 2022
7e437df
Fix
benjackwhite Aug 2, 2022
9c3bf51
Fix
benjackwhite Aug 2, 2022
d816326
fix
benjackwhite Aug 2, 2022
3b12ea2
Removed non-optional optionals
benjackwhite Aug 2, 2022
8ef3d1f
Tidying
benjackwhite Aug 2, 2022
1e2567c
Fix
benjackwhite Aug 2, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 101 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/* global module */
module.exports = {
ignorePatterns: ['node_modules', 'examples', 'lib'],
env: {
browser: true,
es6: true,
},
settings: {
react: {
version: 'detect',
},
},
extends: ['plugin:@typescript-eslint/recommended', 'plugin:react/recommended', 'prettier'],
globals: {
Atomics: 'readonly',
SharedArrayBuffer: 'readonly',
},
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaFeatures: {
jsx: true,
},
ecmaVersion: 2018,
sourceType: 'module',
},
plugins: ['prettier', 'react', '@typescript-eslint'],
rules: {
'react/prop-types': [0],
'react/no-unescaped-entities': [0],
'react/jsx-no-target-blank': [0],
'react/self-closing-comp': [
'error',
{
component: true,
html: true,
},
],
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': [
'error',
{
ignoreRestSiblings: true,
},
],
'@typescript-eslint/prefer-ts-expect-error': 'error',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/no-inferrable-types': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/no-non-null-assertion': 'error',
curly: 'error',
'no-restricted-imports': [
'error',
{
paths: [
{
name: 'dayjs',
message: 'Do not directly import dayjs. Only import the dayjs exported from lib/dayjs.',
},
],
},
],
},
overrides: [
{
// enable the rule specifically for TypeScript files
files: ['*Type.ts', '*Type.tsx'],
rules: {
'@typescript-eslint/no-explicit-any': ['off'],
'@typescript-eslint/ban-types': ['off'],
},
},
{
// enable the rule specifically for TypeScript files
files: ['*.ts', '*.tsx'],
rules: {
'@typescript-eslint/no-explicit-any': ['off'],
'@typescript-eslint/explicit-function-return-type': [
'error',
{
allowExpressions: true,
},
],
'@typescript-eslint/explicit-module-boundary-types': [
'error',
{
allowArgumentsExplicitlyTypedAsAny: true,
},
],
},
},
{
files: ['*.js'],
rules: {
'@typescript-eslint/no-var-requires': 'off',
},
},
],
reportUnusedDisableDirectives: true,
}
45 changes: 45 additions & 0 deletions .github/disabled_workflows/ci-e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: CI - E2E

on:
- pull_request

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
e2e:
runs-on: macos-latest
timeout-minutes: 15

steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: 16

- uses: actions/cache@v2
with:
path: '**/node_modules'
key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}

- name: Install Global Dependencies
run: yarn install

- working-directory: examples/example-expo
run: ls -al && ./e2e/tools/downloadApp.sh

- name: Install Dependencies
working-directory: examples/example-expo
run: |
yarn global add yalc
yarn global add expo-cli
yarn global add detox-cli
yarn install

- run: brew tap wix/brew
- run: brew install applesimutils
- working-directory: examples/example-expo
run: |
open -a simulator
yarn start & yarn test
36 changes: 36 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: CI

on:
- pull_request

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
tests:
timeout-minutes: 3
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: 16

- run: yarn install
- run: yarn test
- run: yarn test:rn

lint:
timeout-minutes: 3
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: 16

- run: yarn install
- run: yarn compile
- run: yarn lint
- run: yarn prettier:check
73 changes: 73 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: 'Release'

on:
push:
branches:
- main
- master
- feat/multi-domain-support # TODO: Remove this once merged

jobs:
release:
name: Publish
runs-on: ubuntu-latest
strategy:
matrix:
package:
- name: posthog-react-native
npm_token_secret: NPM_TOKEN_BEN_WHITE # TODO: Change to standard token once able
- name: posthog-node
npm_token_secret: NPM_TOKEN_BEN_WHITE # TODO: Change to standard token once able
- name: posthog-web
npm_token_secret: NPM_TOKEN # TODO: Change to standard token once able

steps:
- name: Checkout the repository
uses: actions/checkout@v2

- name: Check package version and detect an update
id: check-package-version
uses: PostHog/check-package-version@v2
with:
path: ${{ matrix.package.name }}

- name: Set up Node 14
uses: actions/setup-node@v2
if: steps.check-package-version.outputs.is-new-version == 'true'
with:
node-version: 14
registry-url: https://registry.npmjs.org

- name: Install dependencies
if: steps.check-package-version.outputs.is-new-version == 'true'
run: yarn --frozen-lockfile

- name: Build
if: steps.check-package-version.outputs.is-new-version == 'true'
run: yarn build

- name: Publish the package in the npm registry
id: publish-package
if: steps.check-package-version.outputs.is-new-version == 'true'
working-directory: ${{ matrix.package.name }}
run: |
tag="alpha"
echo ::set-output name=is_latest::alpha
if [[ $VERSION =~ ^[0-9]+(\.[0-9]+){2,3}$ ]]; then
echo ::set-output name=is_latest::latest
tag="latest"
fi

npm publish --access public --tag $tag
env:
NODE_AUTH_TOKEN: ${{ secrets[matrix.package.npm_token_secret] }}
VERSION: ${{ steps.check-package-version.outputs.committed-version }}

- name: Create GitHub release
if: steps.check-package-version.outputs.is-new-version == 'true' && steps.publish-package.outputs.tag == 'latest'
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ matrix.package.name }}-v${{ steps.check-package-version.outputs.committed-version }}
release_name: ${{ matrix.package.name }}-${{ steps.check-package-version.outputs.committed-version }}
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@ node_modules
.vscode
dist/
yarn-error.log
*.tsbuildinfo
coverage/
lib/
.yalc
yalc.lock
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lib
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"trailingComma": "es5",
"tabWidth": 4,
"tabWidth": 2,
"semi": false,
"singleQuote": true,
"printWidth": 120
Expand Down
19 changes: 19 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2022 PostHog (part of Hiberly Inc)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
65 changes: 43 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,50 @@
[![NPM Version](https://img.shields.io/npm/v/posthog-js-lite.svg)](https://www.npmjs.com/package/posthog-js-lite)
[![minified](https://badgen.net/bundlephobia/min/posthog-js-lite)](https://bundlephobia.com/result?p=posthog-js-lite)
[![minified + gzipped](https://badgen.net/bundlephobia/minzip/posthog-js-lite)](https://bundlephobia.com/result?p=posthog-js-lite)

**This library is still a work in progress!**

Reimplementation of posthog-js to be as light and modular as possible.
# posthog-js-lite

The next generation of PostHog client libraries within the JS/TS ecosystem.

The lofty goals of this codebase is to solve the core client logic of our various JS based libraries in one place (web, node, React Native).

The short-term goal is to have a dedicated React Native library free from any platform-specific installations (the previous client library is a wrapper for the `posthog-ios` and `posthog-android` libraries). This enables a few things:

1. Installation to Expo managed projects without any separate compilation / ejecting
2. Tighter integration to RN enabling hooks, context, autocapture etc.

## Development

This repository is broken into different packages

- **/posthog-core** > All common code goes here.
- **/posthog-node** > Node.js specific code
- **/posthog-react-native** > React Native specific code
- **/posthog-web** > Web (DOM) specific code

## Running tests

```sh
yarn test
# Run the RN tests - these are separate due to specific babel configs
yarn test:rn
```

### Running E2E tests with Detox

See [Example Expo Readme](./examples/example-expo/README.md)

Goals:
- simple api
- can do autocapture, but enabled via a plugin (not yet)
- runs in the oldest browsers (not yet)
- might break some APIs (if not now, then when?)
### Examples

Supports already:
- very simple api
- capture & identify calls
- $context from window
- only send events after optin if needed
- payload compression
- 10kb (includes 5kb compression code)
#### React Native

Browser support:
- This library ES6 compatible browsers (everything except IE). If you need to support IE,
feel free to transpile the source to ES5 after including it in your bundle.
```sh
cd examples/example-expo
yarn && yarn start
```

## Questions?
#### Node.js

### [Join our Slack community.](https://join.slack.com/t/posthogusers/shared_invite/enQtOTY0MzU5NjAwMDY3LTc2MWQ0OTZlNjhkODk3ZDI3NDVjMDE1YjgxY2I4ZjI4MzJhZmVmNjJkN2NmMGJmMzc2N2U3Yjc3ZjI5NGFlZDQ)
```sh
cd examples/example-node
yarn && yarn start
# example-expo has some buttons that will talk to this server
```
Loading