-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 🔥 integration with mixpanel
integration with mixpanel
- Loading branch information
Tal Rofe
committed
Jun 21, 2022
1 parent
66efddd
commit 7c5c0c4
Showing
56 changed files
with
7,927 additions
and
2,975 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
apps/backend/src/modules/user/modules/auth/events/contracts/login-mixpanel.contract.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export class LoginMixpanelContract { | ||
constructor(public readonly userId: string, public readonly ip: string) {} | ||
} |
3 changes: 3 additions & 0 deletions
3
apps/backend/src/modules/user/modules/auth/events/contracts/signup-mixpanel.contract.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export class SignupMixpanelContract { | ||
constructor(public readonly userId: string, public readonly ip: string) {} | ||
} |
4 changes: 4 additions & 0 deletions
4
apps/backend/src/modules/user/modules/auth/events/handlers/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { LoginMixpanelHandler } from './login-mixpanel.handler'; | ||
import { SignupMixpanelHandler } from './signup-mixpanel.handler'; | ||
|
||
export const EventHandlers = [SignupMixpanelHandler, LoginMixpanelHandler]; |
24 changes: 24 additions & 0 deletions
24
apps/backend/src/modules/user/modules/auth/events/handlers/login-mixpanel.handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { ConfigService } from '@nestjs/config'; | ||
import { CommandHandler, ICommandHandler } from '@nestjs/cqrs'; | ||
import Mixpanel from 'mixpanel'; | ||
|
||
import { IEnvironment } from '@/config/env.interface'; | ||
|
||
import { USER_LOGIN } from '../../models/mixpanel-events'; | ||
import { LoginMixpanelContract } from '../contracts/login-mixpanel.contract'; | ||
|
||
@CommandHandler(LoginMixpanelContract) | ||
export class LoginMixpanelHandler implements ICommandHandler<LoginMixpanelContract> { | ||
constructor(private readonly configService: ConfigService<IEnvironment, true>) {} | ||
|
||
execute(contract: LoginMixpanelContract): Promise<void> { | ||
const mixpanel = Mixpanel.init(this.configService.get('mixpanelToken', { infer: true })); | ||
|
||
mixpanel.track(USER_LOGIN, { | ||
distinct_id: contract.userId, | ||
ip: contract.ip, | ||
}); | ||
|
||
return Promise.resolve(); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
apps/backend/src/modules/user/modules/auth/events/handlers/signup-mixpanel.handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { ConfigService } from '@nestjs/config'; | ||
import { CommandHandler, ICommandHandler } from '@nestjs/cqrs'; | ||
import Mixpanel from 'mixpanel'; | ||
|
||
import { IEnvironment } from '@/config/env.interface'; | ||
|
||
import { SignupMixpanelContract } from '../contracts/signup-mixpanel.contract'; | ||
import { USER_SIGNUP } from '../../models/mixpanel-events'; | ||
|
||
@CommandHandler(SignupMixpanelContract) | ||
export class SignupMixpanelHandler implements ICommandHandler<SignupMixpanelContract> { | ||
constructor(private readonly configService: ConfigService<IEnvironment, true>) {} | ||
|
||
execute(contract: SignupMixpanelContract): Promise<void> { | ||
const mixpanel = Mixpanel.init(this.configService.get('mixpanelToken', { infer: true })); | ||
|
||
mixpanel.track(USER_SIGNUP, { | ||
distinct_id: contract.userId, | ||
ip: contract.ip, | ||
}); | ||
|
||
return Promise.resolve(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
apps/backend/src/modules/user/modules/auth/models/mixpanel-events.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const USER_LOGIN = 'User_Login'; | ||
|
||
export const USER_SIGNUP = 'User_Signup'; |
1 change: 1 addition & 0 deletions
1
apps/backend/src/modules/user/modules/auth/queries/contracts/create-github-user.contract.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
apps/backend/src/modules/user/modules/auth/queries/contracts/create-google-user.contract.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
...ackend/src/modules/user/modules/groups/events/contracts/create-group-mixpanel.contract.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export class CreateGroupMixpanelContract { | ||
constructor(public readonly userId: string, public readonly ip: string) {} | ||
} |
24 changes: 24 additions & 0 deletions
24
.../backend/src/modules/user/modules/groups/events/handlers/create-group-mixpanel.handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { ConfigService } from '@nestjs/config'; | ||
import { CommandHandler, ICommandHandler } from '@nestjs/cqrs'; | ||
import Mixpanel from 'mixpanel'; | ||
|
||
import { IEnvironment } from '@/config/env.interface'; | ||
|
||
import { CreateGroupMixpanelContract } from '../contracts/create-group-mixpanel.contract'; | ||
import { GROUP_CREATE } from '../../models/mixpanel-events'; | ||
|
||
@CommandHandler(CreateGroupMixpanelContract) | ||
export class CreateGroupMixpanelHandler implements ICommandHandler<CreateGroupMixpanelContract> { | ||
constructor(private readonly configService: ConfigService<IEnvironment, true>) {} | ||
|
||
execute(contract: CreateGroupMixpanelContract): Promise<void> { | ||
const mixpanel = Mixpanel.init(this.configService.get('mixpanelToken', { infer: true })); | ||
|
||
mixpanel.track(GROUP_CREATE, { | ||
distinct_id: contract.userId, | ||
ip: contract.ip, | ||
}); | ||
|
||
return Promise.resolve(); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
apps/backend/src/modules/user/modules/groups/events/handlers/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { CreateGroupMixpanelHandler } from './create-group-mixpanel.handler'; | ||
|
||
export const EventHandlers = [CreateGroupMixpanelHandler]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
apps/backend/src/modules/user/modules/groups/models/mixpanel-events.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const GROUP_CREATE = 'Group_Create'; |
2 changes: 1 addition & 1 deletion
2
apps/backend/src/modules/user/modules/groups/queries/contracts/create-group.contact.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export class CreateGroupContract { | ||
constructor(public readonly userId: string) {} | ||
constructor(public readonly userId: string, public readonly ip: string) {} | ||
} |
Oops, something went wrong.