satellite/analytics: Add anonymous ID to TrackCreateUser
If a visitor to the website (run through the reverse proxy) consented to cookies, read the ID stored in that cookie and send it along with the Identify/Track calls sent to Segment upon account creation. This allows us to connect referral information gathered when visitors land on our website with account activity, helping us improve our onboarding flow. Change-Id: I0ece717ab5bba67901e50a9b4229c1d4ed7e46b7
This commit is contained in:
parent
b907aab0ad
commit
51d667a65e
@ -75,6 +75,7 @@ const (
|
||||
// TrackCreateUserFields contains input data for tracking a create user event.
|
||||
type TrackCreateUserFields struct {
|
||||
ID uuid.UUID
|
||||
AnonymousID string
|
||||
FullName string
|
||||
Email string
|
||||
Type UserType
|
||||
@ -101,8 +102,9 @@ func (service *Service) TrackCreateUser(fields TrackCreateUserFields) {
|
||||
traits.SetEmail(fields.Email)
|
||||
|
||||
service.enqueueMessage(segment.Identify{
|
||||
UserId: fields.ID.String(),
|
||||
Traits: traits,
|
||||
UserId: fields.ID.String(),
|
||||
AnonymousId: fields.AnonymousID,
|
||||
Traits: traits,
|
||||
})
|
||||
|
||||
props := segment.NewProperties()
|
||||
@ -118,9 +120,10 @@ func (service *Service) TrackCreateUser(fields TrackCreateUserFields) {
|
||||
}
|
||||
|
||||
service.enqueueMessage(segment.Track{
|
||||
UserId: fields.ID.String(),
|
||||
Event: eventAccountCreated,
|
||||
Properties: props,
|
||||
UserId: fields.ID.String(),
|
||||
AnonymousId: fields.AnonymousID,
|
||||
Event: eventAccountCreated,
|
||||
Properties: props,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -167,10 +167,11 @@ func (a *Auth) Register(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
trackCreateUserFields := analytics.TrackCreateUserFields{
|
||||
ID: user.ID,
|
||||
FullName: user.FullName,
|
||||
Email: user.Email,
|
||||
Type: analytics.Personal,
|
||||
ID: user.ID,
|
||||
AnonymousID: loadSession(r),
|
||||
FullName: user.FullName,
|
||||
Email: user.Email,
|
||||
Type: analytics.Personal,
|
||||
}
|
||||
if user.IsProfessional {
|
||||
trackCreateUserFields.Type = analytics.Professional
|
||||
@ -210,6 +211,16 @@ func (a *Auth) Register(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
// loadSession looks for a cookie for the session id.
|
||||
// this cookie is set from the reverse proxy if the user opts into cookies from Storj.
|
||||
func loadSession(req *http.Request) string {
|
||||
sessionCookie, err := req.Cookie("webtraf-sid")
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return sessionCookie.Value
|
||||
}
|
||||
|
||||
// UpdateAccount updates user's full name and short name.
|
||||
func (a *Auth) UpdateAccount(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
|
Loading…
Reference in New Issue
Block a user