Security News
The Risks of Misguided Research in Supply Chain Security
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
posthog-js
Advanced tools
Posthog-js allows you to automatically capture usage and send events to PostHog.
The posthog-js npm package is a JavaScript library for integrating PostHog analytics into web applications. It allows you to track user interactions, capture events, and analyze user behavior in real-time.
Initialization
Initialize the PostHog library with your API key and optional configuration settings.
const posthog = require('posthog-js');
posthog.init('YOUR_API_KEY', { api_host: 'https://app.posthog.com' });
Capture Events
Capture custom events with properties to track user interactions and behaviors.
posthog.capture('event_name', { property1: 'value1', property2: 'value2' });
Identify Users
Identify users with unique IDs and associate them with properties like email and name.
posthog.identify('user_id', { email: 'user@example.com', name: 'John Doe' });
Set User Properties
Set properties for identified users to enrich user profiles with additional information.
posthog.people.set({ property1: 'value1', property2: 'value2' });
Feature Flags
Check if a feature flag is enabled for the current user to implement feature toggling.
const isEnabled = posthog.isFeatureEnabled('feature_flag_key');
Mixpanel is a powerful analytics tool that offers similar functionalities to PostHog, such as event tracking, user identification, and property setting. Mixpanel also provides advanced features like A/B testing and user segmentation.
Amplitude is an analytics platform focused on product intelligence. It offers event tracking, user identification, and behavioral analytics. Amplitude provides advanced features like cohort analysis and user journey mapping, which can be more detailed than PostHog's offerings.
Please see PostHog Docs. Specifically, browser JS library details.
Unit tests: run yarn test
.
Cypress: run yarn serve
to have a test server running and separately yarn cypress
to launch Cypress test engine.
Testing on IE11 requires a bit more setup.
posthog
locally on port 8000 (DEBUG=1 TEST=1 ./bin/start
).python manage.py setup_dev --no-data
on posthog repo, which sets up a demo account.nodemon -w src/ --exec bash -c "yarn build-array"
.export BROWSERSTACK_USERNAME=xxx BROWSERSTACK_ACCESS_KEY=xxx
.npx testcafe "browserstack:ie" testcafe/e2e.spec.js
.Use yarn link
. Run yarn link
in posthog-js
, and then yarn link posthog-js
in posthog
. Once you're done, remember to yarn unlink posthog-js
in posthog
, and yarn unlink
in posthog-js
.
An alternative is to update dependency in package.json to e.g. "posthog-js": "link:../posthog-js"
, yarn
and run yarn build && yarn build-module
The posthog-js
snippet for a website loads static js from the main PostHog/posthog
repo. Which means, when testing the snippet with a website, there's a bit of extra setup required:
PostHog/posthog
locallyposthog-js
dependency to your local version (see above)yarn serve
in posthog-js
. (This ensures dist/array.js
is being generated)PostHog/posthog
build, run yarn copy-scripts
. (This copies the scripts generated in step 3 to the static assets folder for PostHog/posthog
)Further, it's a good idea to modify start-http
script to add development mode: webpack serve --mode development
, which doesn't minify the resulting js (which you can then read in your browser).
Just bump up version
in package.json
on the main branch and the new version will be published automatically,
with a matching PR in the main PostHog repo created.
It's advised to use bump patch/minor/major
label on PRs - that way the above will be done automatically
when the PR is merged.
Courtesy of GitHub Actions.
To release a new version, make sure you're logged into npm (npm login
).
We tend to follow the following steps:
npm version 1.x.x-beta.0
npm publish --tag beta
git push --tags
npm version 1.x.x
npm publish
git push --tags
1.13.2 - 2021-09-02
FAQs
Posthog-js allows you to automatically capture usage and send events to PostHog.
The npm package posthog-js receives a total of 546,341 weekly downloads. As such, posthog-js popularity was classified as popular.
We found that posthog-js demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.