satellite/analytics: Associate Hubspot token with new user

If a visitor has accepted cookies on www.storj.io, there might be a
"hubspotutk" cookie in their browser upon account creation. This allows
Hubspot to link website activity with a newly created user.

Change-Id: If06c67fb4d2e5dd3cf46c1fe80a0e9d7f25d6e58
This commit is contained in:
Moby von Briesen 2022-03-29 15:36:06 -04:00
parent 9ef11644fd
commit 0018d62837
3 changed files with 27 additions and 10 deletions

View File

@ -100,18 +100,27 @@ func (q *HubSpotEvents) EnqueueCreateUser(fields TrackCreateUserFields) {
firstName = fullName
}
newField := func(name, value string) map[string]interface{} {
return map[string]interface{}{
"name": name,
"value": value,
}
}
createUser := HubSpotEvent{
Endpoint: "https://api.hubapi.com/crm/v3/objects/contacts?hapikey=" + q.escapedAPIKey,
Endpoint: "https://api.hsforms.com/submissions/v3/integration/submit/20293085/77cfa709-f533-44b8-bf3a-ed1278ca3202?hapikey=" + q.escapedAPIKey,
Data: map[string]interface{}{
"email": fields.Email,
"properties": map[string]interface{}{
"email": fields.Email,
"firstname": firstName,
"lastname": lastName,
"lifecyclestage": "customer",
"origin_header": fields.OriginHeader,
"signup_referrer": fields.Referrer,
"account_created": true,
"context": map[string]interface{}{
"hutk": fields.HubspotUTK,
},
"fields": []map[string]interface{}{
newField("email", fields.Email),
newField("firstname", firstName),
newField("lastname", lastName),
newField("lifecyclestage", "customer"),
newField("origin_header", fields.OriginHeader),
newField("signup_referrer", fields.Referrer),
newField("account_created", "true"),
},
},
}

View File

@ -113,6 +113,7 @@ type TrackCreateUserFields struct {
HaveSalesContact bool
OriginHeader string
Referrer string
HubspotUTK string
}
func (service *Service) enqueueMessage(message segment.Message) {

View File

@ -286,6 +286,12 @@ func (a *Auth) Register(w http.ResponseWriter, r *http.Request) {
if referrer == "" {
referrer = r.Referer()
}
hubspotUTK := ""
hubspotCookie, err := r.Cookie("hubspotutk")
if err == nil {
hubspotUTK = hubspotCookie.Value
}
trackCreateUserFields := analytics.TrackCreateUserFields{
ID: user.ID,
AnonymousID: loadSession(r),
@ -294,6 +300,7 @@ func (a *Auth) Register(w http.ResponseWriter, r *http.Request) {
Type: analytics.Personal,
OriginHeader: origin,
Referrer: referrer,
HubspotUTK: hubspotUTK,
}
if user.IsProfessional {
trackCreateUserFields.Type = analytics.Professional