posthog-node
Advanced tools
Comparing version 1.0.1 to 1.0.3
{ | ||
"name": "posthog-node", | ||
"version": "1.0.1", | ||
"version": "1.0.3", | ||
"description": "PostHog Node.js integration", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
103
README.md
# PostHog NodeJS | ||
Official PostHog NodeJS library to capture and send events to any PostHog instance (including posthog.com). | ||
Please see the main [PostHog docs](https://posthog.com/docs). | ||
This library uses an internal queue to make calls non-blocking and fast. It also batches requests and flushes asynchronously, making it perfect to use in any part of your web app or other server side application that needs performance. | ||
## Installation | ||
Run either the `yarn` or `npm` program to add it to your project | ||
```shell script | ||
npm install posthog-node | ||
yarn add posthog-node | ||
``` | ||
In your app, set your api key **before** making any calls. | ||
```javascript | ||
// const PostHog = require('posthog-node') | ||
import PostHog from 'posthog-node' | ||
const client = new PostHog('API key') | ||
``` | ||
You can find your key in the /setup page in PostHog. | ||
## Making calls | ||
### Capture | ||
Capture allows you to capture anything a user does within your system, which you can later use in PostHog to find patterns in usage, work out which features to improve or where people are giving up. | ||
A `capture` call requires | ||
- `distinct id` which uniquely identifies your user | ||
- `event name` to make sure | ||
- We recommend using [verb] [noun], like `movie played` or `movie updated` to easily identify what your events mean later on. | ||
Optionally you can submit | ||
- `properties`, which can be a dict with any information you'd like to add | ||
For example: | ||
```ruby | ||
client.capture({ | ||
distinctId: 'distinct id', | ||
event: 'movie played', | ||
properties: { | ||
movieId: '123', | ||
category: 'romcom' | ||
} | ||
}) | ||
``` | ||
### Identify | ||
Identify lets you add metadata on your users so you can more easily identify who they are in PostHog, and even do things like segment users by these properties. | ||
An `identify` call requires | ||
- `distinct id` which uniquely identifies your user | ||
- `properties` with a dict with any key: value pairs | ||
For example: | ||
```ruby | ||
client.identify({ | ||
distinctId: "user:123", | ||
properties: { | ||
email: 'john@doe.com', | ||
proUser: false | ||
} | ||
}) | ||
``` | ||
The most obvious place to make this call is whenever a user signs up, or when they update their information. | ||
### Alias | ||
To marry up whatever a user does before they sign up or log in with what they do after you need to make an alias call. This will allow you to answer questions like "Which marketing channels leads to users churning after a month?" or "What do users do on our website before signing up?" | ||
In a purely back-end implementation, this means whenever an anonymous user does something, you'll want to send a session ID with the capture call. Then, when that users signs up, you want to do an alias call with the session ID and the newly created user ID. | ||
The same concept applies for when a user logs in. | ||
If you're using PostHog in the front-end and back-end, doing the `identify` call in the frontend will be enough. | ||
An `alias` call requires | ||
- `distinct id` the current unique id | ||
- `alias` the unique ID of the user before | ||
For example: | ||
```ruby | ||
client.alias({ | ||
distinctId: "user:123", | ||
alias: "user:12345", | ||
}) | ||
``` | ||
# Development | ||
## How to release | ||
1. Run "npm version patch" (or minor/major) | ||
2. Run "npm publish" | ||
## Thank you | ||
This library is largely based on the `analytics-node` package. | ||
Specifically, the [NodeJS integration](https://posthog.com/docs/integrations/node-integration) details. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
0
13275
6