Skip to content

Commit

Permalink
satellite/analytics: use new minimal sign up form ID
Browse files Browse the repository at this point in the history
This change uses a new minimal sign up form from hubspot. It also
removes code that submits data to legacy professional and basic forms
for the old sign up flow.

Issue: #6907

Change-Id: I474a601f571a676d145cbb97684b5a2d02fc0c1b
  • Loading branch information
wilfred-asomanii authored and andriikotko committed Apr 15, 2024
1 parent 045913e commit 98aaeb3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 102 deletions.
104 changes: 4 additions & 100 deletions satellite/analytics/hubspot.go
Expand Up @@ -10,7 +10,6 @@ import (
"fmt"
"net/http"
"net/url"
"strconv"
"strings"
"sync"
"time"
Expand All @@ -25,18 +24,14 @@ import (
var mon = monkit.Package()

const (
eventPrefix = "pe20293085"
eventPrefix = "pe44965639"
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"
hubspotFormTemplate = "https://api.hsforms.com/submissions/v3/integration/submit/44965639/%s"
// this form ID is the minimal account form.
minimalFormID = "926d1b53-f21f-486b-9f15-3b3d341cc4e1"
minimalFormID = "ad4cd7b6-1c9c-44b9-b41f-b48611739620"
// The hubspot lifecycle stage of all new accounts (Product Qualified Lead).
lifecycleStage = "66198674"
lifecycleStage = "170987588"
)

// HubSpotConfig is a configuration struct for Concurrent Sending of Events.
Expand Down Expand Up @@ -118,97 +113,6 @@ func (q *HubSpotEvents) Run(ctx context.Context) error {
}
}

// EnqueueCreateUser for creating user in HubSpot.
func (q *HubSpotEvents) EnqueueCreateUser(fields TrackCreateUserFields) {
fullName := fields.FullName
names := strings.SplitN(fullName, " ", 2)

var firstName string
var lastName string

if len(names) > 1 {
firstName = names[0]
lastName = names[1]
} else {
firstName = fullName
}

newField := func(name string, value interface{}) map[string]interface{} {
return map[string]interface{}{
"name": name,
"value": value,
}
}

formFields := []map[string]interface{}{
newField("email", fields.Email),
newField("firstname", firstName),
newField("lastname", lastName),
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),
newField("lifecyclestage", lifecycleStage),
}
if fields.SignupCaptcha != nil {
formFields = append(formFields, newField("signup_captcha_score", *fields.SignupCaptcha))
}

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("company", fields.CompanyName))
formFields = append(formFields, newField("storage_needs", fields.StorageNeeds))

properties["storage_needs"] = fields.StorageNeeds

formURL = fmt.Sprintf(hubspotFormTemplate, professionalFormID)
} else {
formURL = fmt.Sprintf(hubspotFormTemplate, basicFormID)
}

data := map[string]interface{}{
"fields": formFields,
}

if fields.HubspotUTK != "" {
data["context"] = map[string]interface{}{
"hutk": fields.HubspotUTK,
}
}

createUser := HubSpotEvent{
Endpoint: formURL,
Data: data,
}

sendUserEvent := HubSpotEvent{
Endpoint: "https://api.hubapi.com/events/v3/send",
Data: map[string]interface{}{
"email": fields.Email,
"eventName": eventPrefix + "_" + strings.ToLower(q.satelliteName) + "_" + "account_created",
"properties": properties,
},
}
select {
case q.events <- []HubSpotEvent{createUser, sendUserEvent}:
default:
q.log.Error("create user hubspot event failed, event channel is full")
}
}

// EnqueueCreateUserMinimal is for creating user in HubSpot using the minimal form.
func (q *HubSpotEvents) EnqueueCreateUserMinimal(fields TrackCreateUserFields) {
newField := func(name string, value interface{}) map[string]interface{} {
Expand Down
2 changes: 0 additions & 2 deletions satellite/analytics/service.go
Expand Up @@ -358,9 +358,7 @@ func (service *Service) TrackCreateUser(fields TrackCreateUserFields) {
if fields.FullName == "" {
// the new minimal signup flow does not require a name.
service.hubspot.EnqueueCreateUserMinimal(fields)
return
}
service.hubspot.EnqueueCreateUser(fields)
}

// TrackUserOnboardingInfo sends onboarding info to Hubspot.
Expand Down

0 comments on commit 98aaeb3

Please sign in to comment.