1.1.2 ā€¢ Published 3 years ago

nestjs-posthog v1.1.2

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
3 years ago

code style: prettier Commitizen friendly Release

Language grade: JavaScript codecov

Posthog for Nestjs makes it easier to implement analytics with Posthog into your Nestjs application.

:space_invader: Ā  Usage

ā–¶ yarn add nestjs-posthog
import { Module } from '@nestjs/common';
import { PosthogModule } from 'nestjs-posthog';

@Module({
  imports: [
    PosthogModule.forRoot({
      apiKey: '<ph_project_api_key>',
      options: {
        host: '<ph_instance_address>',
      },
    }),
  ],
})
export class AppModule {}

Example

You can easily inject PosthogService to be used in your services, controllers, etc.

import { Injectable } from '@nestjs/common';
import { PosthogService } from 'nestjs-posthog';

@Injectable()
export class AuthService {
  constructor(private service: PosthogService) {}

  helloWorldMethod() {
    this.service.capture({
      distinctId: 'distinct id',
      event: 'movie played',
      properties: {
        movieId: '123',
        category: 'romcom',
      },
    });
    return 'hello world';
  }
}

Read more about the methods in Posthogs Node.js client documentation.

Contribute & Disclaimer

We love to get help šŸ™ Read more about how to get started in CONTRIBUTING šŸŒ³

This is a community-driven Open Source project with no ties with Posthog. It's supported on a volunteer-basis, but frequently used in commerical projects.