satellite/analytics: separate hubspot form for personal vs business

This change separates hubspot form submission for personal and business
accounts, with new company name and storage needs fields.

Issue: https://github.com/storj/storj-private/issues/220

Change-Id: Ieb0fb64f87614c7327dc5f894140fb8a54ededa0
This commit is contained in:
Wilfred Asomani 2023-04-03 10:17:09 +00:00 committed by Storj Robot
parent bebfb91b66
commit 771d2269ab
3 changed files with 58 additions and 24 deletions

View File

@ -7,6 +7,7 @@ import (
"bytes"
"context"
"encoding/json"
"fmt"
"net/http"
"net/url"
"strconv"
@ -26,6 +27,16 @@ var mon = monkit.Package()
const (
eventPrefix = "pe20293085"
expiryBufferTime = 5 * time.Minute
// string template for hubspot submission form. %s is a placeholder for the form(ID) being submitted.
hubspotFormTemplate = "https://api.hsforms.com/submissions/v3/integration/submit/20293085/%s"
// This form(ID) is the business account form.
professionalFormID = "cc693502-9d55-4204-ae61-406a19148cfe"
// This form(ID) is the personal account form.
basicFormID = "77cfa709-f533-44b8-bf3a-ed1278ca3202"
// The hubspot lifecycle stage of business accounts (Product Qualified Lead).
businessLifecycleStage = "66198674"
// The hubspot lifecycle stage of personal accounts.
personalLifecycleStage = "other"
)
// HubSpotConfig is a configuration struct for Concurrent Sending of Events.
@ -128,18 +139,46 @@ func (q *HubSpotEvents) EnqueueCreateUser(fields TrackCreateUserFields) {
}
}
data := map[string]interface{}{
"fields": []map[string]interface{}{
formFields := []map[string]interface{}{
newField("email", fields.Email),
newField("firstname", firstName),
newField("lastname", lastName),
newField("lifecyclestage", "other"),
newField("origin_header", fields.OriginHeader),
newField("signup_referrer", fields.Referrer),
newField("account_created", "true"),
newField("have_sales_contact", strconv.FormatBool(fields.HaveSalesContact)),
newField("signup_partner", fields.UserAgent),
},
}
properties := map[string]interface{}{
"userid": fields.ID.String(),
"email": fields.Email,
"name": fields.FullName,
"satellite_selected": q.satelliteName,
"account_type": string(fields.Type),
"company_size": fields.EmployeeCount,
"company_name": fields.CompanyName,
"job_title": fields.JobTitle,
}
var formURL string
if fields.Type == Professional {
formFields = append(formFields, newField("lifecyclestage", businessLifecycleStage))
formFields = append(formFields, newField("company", fields.CompanyName))
formFields = append(formFields, newField("storage_needs", fields.StorageNeeds))
properties["storage_needs"] = fields.StorageNeeds
formURL = fmt.Sprintf(hubspotFormTemplate, professionalFormID)
} else {
formFields = append(formFields, newField("lifecyclestage", personalLifecycleStage))
formURL = fmt.Sprintf(hubspotFormTemplate, basicFormID)
}
data := map[string]interface{}{
"fields": formFields,
}
if fields.HubspotUTK != "" {
@ -149,7 +188,7 @@ func (q *HubSpotEvents) EnqueueCreateUser(fields TrackCreateUserFields) {
}
createUser := HubSpotEvent{
Endpoint: "https://api.hsforms.com/submissions/v3/integration/submit/20293085/77cfa709-f533-44b8-bf3a-ed1278ca3202",
Endpoint: formURL,
Data: data,
}
@ -158,16 +197,7 @@ func (q *HubSpotEvents) EnqueueCreateUser(fields TrackCreateUserFields) {
Data: map[string]interface{}{
"email": fields.Email,
"eventName": eventPrefix + "_" + strings.ToLower(q.satelliteName) + "_" + "account_created",
"properties": map[string]interface{}{
"userid": fields.ID.String(),
"email": fields.Email,
"name": fields.FullName,
"satellite_selected": q.satelliteName,
"account_type": string(fields.Type),
"company_size": fields.EmployeeCount,
"company_name": fields.CompanyName,
"job_title": fields.JobTitle,
},
"properties": properties,
},
}
select {

View File

@ -176,6 +176,7 @@ type TrackCreateUserFields struct {
Type UserType
EmployeeCount string
CompanyName string
StorageNeeds string
JobTitle string
HaveSalesContact bool
OriginHeader string
@ -244,6 +245,7 @@ func (service *Service) TrackCreateUser(fields TrackCreateUserFields) {
props.Set("company_size", fields.EmployeeCount)
props.Set("company_name", fields.CompanyName)
props.Set("job_title", fields.JobTitle)
props.Set("storage_needs", fields.StorageNeeds)
}
service.enqueueMessage(segment.Track{

View File

@ -203,6 +203,7 @@ func (a *Auth) Register(w http.ResponseWriter, r *http.Request) {
IsProfessional bool `json:"isProfessional"`
Position string `json:"position"`
CompanyName string `json:"companyName"`
StorageNeeds string `json:"storageNeeds"`
EmployeeCount string `json:"employeeCount"`
HaveSalesContact bool `json:"haveSalesContact"`
CaptchaResponse string `json:"captchaResponse"`
@ -336,6 +337,7 @@ func (a *Auth) Register(w http.ResponseWriter, r *http.Request) {
trackCreateUserFields.Type = analytics.Professional
trackCreateUserFields.EmployeeCount = user.EmployeeCount
trackCreateUserFields.CompanyName = user.CompanyName
trackCreateUserFields.StorageNeeds = registerData.StorageNeeds
trackCreateUserFields.JobTitle = user.Position
trackCreateUserFields.HaveSalesContact = user.HaveSalesContact
}