-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(web): Hub spot identify (#6547)
- Loading branch information
Showing
8 changed files
with
120 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { AnalyticsService } from '@novu/application-generic'; | ||
import { HttpModule } from '@nestjs/axios'; | ||
import { AnalyticsController } from './analytics.controller'; | ||
import { SharedModule } from '../shared/shared.module'; | ||
import { AuthModule } from '../auth/auth.module'; | ||
import { HubspotIdentifyFormUsecase } from './usecases/hubspot-identify-form/hubspot-identify-form.usecase'; | ||
|
||
@Module({ | ||
imports: [SharedModule, AuthModule], | ||
imports: [HttpModule], | ||
controllers: [AnalyticsController], | ||
providers: [], | ||
providers: [AnalyticsService, HubspotIdentifyFormUsecase], | ||
}) | ||
export class AnalyticsModule {} |
28 changes: 28 additions & 0 deletions
28
apps/api/src/app/analytics/usecases/hubspot-identify-form/hubspot-identify-form.command.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,28 @@ | ||
import { BaseCommand } from '@novu/application-generic'; | ||
import { IsDefined, IsString, IsOptional } from 'class-validator'; | ||
|
||
export class HubspotIdentifyFormCommand extends BaseCommand { | ||
@IsDefined() | ||
@IsString() | ||
email: string; | ||
|
||
@IsOptional() | ||
@IsString() | ||
lastName?: string; | ||
|
||
@IsOptional() | ||
@IsString() | ||
firstName?: string; | ||
|
||
@IsOptional() | ||
@IsString() | ||
hubspotContext?: string; | ||
|
||
@IsOptional() | ||
@IsString() | ||
pageUri?: string; | ||
|
||
@IsOptional() | ||
@IsString() | ||
pageName?: string; | ||
} |
36 changes: 36 additions & 0 deletions
36
apps/api/src/app/analytics/usecases/hubspot-identify-form/hubspot-identify-form.usecase.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,36 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { HttpService } from '@nestjs/axios'; | ||
import { firstValueFrom } from 'rxjs'; | ||
import { HubspotIdentifyFormCommand } from './hubspot-identify-form.command'; | ||
|
||
@Injectable() | ||
export class HubspotIdentifyFormUsecase { | ||
private readonly hubspotPortalId = '44416662'; | ||
private readonly hubspotFormId = 'fc39aa98-4285-4322-9514-52da978baae8'; | ||
|
||
constructor(private httpService: HttpService) {} | ||
|
||
async execute(command: HubspotIdentifyFormCommand): Promise<{ success: boolean; hubspotResponse?: any }> { | ||
const hubspotSubmitUrl = `https://api.hsforms.com/submissions/v3/integration/submit/${this.hubspotPortalId}/${this.hubspotFormId}`; | ||
|
||
const hubspotData = { | ||
fields: [ | ||
{ name: 'email', value: command.email }, | ||
{ name: 'lastname', value: command.lastName || 'Unknown' }, | ||
{ name: 'firstname', value: command.firstName || 'Unknown' }, | ||
], | ||
context: { | ||
hutk: command.hubspotContext, | ||
pageUri: command.pageUri, | ||
pageName: command.pageName, | ||
}, | ||
}; | ||
|
||
const response = await firstValueFrom(this.httpService.post(hubspotSubmitUrl, hubspotData)); | ||
|
||
return { | ||
success: true, | ||
hubspotResponse: response.data, | ||
}; | ||
} | ||
} |
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,11 @@ | ||
import { api } from './api.client'; | ||
|
||
export const identifyUser = async (userData) => { | ||
try { | ||
const response = await api.post('/v1/telemetry/identify', userData); | ||
|
||
return response.data; | ||
} catch (error) { | ||
console.error('Error identifying user:', error); | ||
} | ||
}; |
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