Browse Source

new user pipeline

sunguroku 5 năm trước cách đây
mục cha
commit
652919fca9

+ 0 - 8
dashboard/src/main/home/Home.tsx

@@ -197,18 +197,10 @@ class Home extends Component<PropsType, StateType> {
   };
 
   componentDidMount() {
-    let { user, projects } = this.context;
-
     // Handle redirect from DO
     let queryString = window.location.search;
     let urlParams = new URLSearchParams(queryString);
 
-    window.analytics.identify(user.userId, {
-      email: user.email,
-      createdAt: Date.now(),
-      projects,
-    });
-
     let err = urlParams.get("error");
     if (err) {
       this.context.setCurrentError(err);

+ 6 - 1
dashboard/src/main/home/sidebar/ClusterSection.tsx

@@ -38,12 +38,17 @@ class ClusterSection extends Component<PropsType, StateType> {
   };
 
   updateClusters = () => {
-    let { currentProject, setCurrentCluster } = this.context;
+    let { user, currentProject, setCurrentCluster } = this.context;
 
     // TODO: query with selected filter once implemented
     api
       .getClusters("<token>", {}, { id: currentProject.id })
       .then((res) => {
+        window.analytics.identify(user.userId, {
+          currentProject,
+          clusters: res.data,
+        });
+
         this.props.setWelcome(false);
         // TODO: handle uninitialized kubeconfig
         if (res.data) {

+ 2 - 2
go.mod

@@ -57,9 +57,9 @@ require (
 	github.com/pelletier/go-toml v1.8.1 // indirect
 	github.com/pkg/errors v0.9.1
 	github.com/rs/zerolog v1.20.0
-	github.com/sendgrid/rest v2.6.3+incompatible // indirect
-	github.com/sendgrid/sendgrid-go v3.8.0+incompatible // indirect
 	github.com/segmentio/backo-go v0.0.0-20200129164019-23eae7c10bd3 // indirect
+	github.com/sendgrid/rest v2.6.3+incompatible // indirect
+	github.com/sendgrid/sendgrid-go v3.8.0+incompatible
 	github.com/sirupsen/logrus v1.7.0
 	github.com/spf13/cobra v1.0.0
 	github.com/spf13/viper v1.4.0

+ 18 - 0
server/api/oauth_github_handler.go

@@ -17,6 +17,7 @@ import (
 	"golang.org/x/oauth2"
 
 	"github.com/porter-dev/porter/internal/models/integrations"
+	segment "gopkg.in/segmentio/analytics-go.v3"
 )
 
 // HandleGithubOAuthStartUser starts the oauth2 flow for a user login request.
@@ -129,6 +130,23 @@ func (app *App) HandleGithubOAuthCallback(w http.ResponseWriter, r *http.Request
 			return
 		}
 
+		// send to segment
+		client := *app.segmentClient
+		client.Enqueue(segment.Identify{
+			UserId: fmt.Sprintf("%v", user.ID),
+			Traits: segment.NewTraits().
+				SetEmail(user.Email).
+				Set("github", "false"),
+		})
+
+		client.Enqueue(segment.Track{
+			UserId: fmt.Sprintf("%v", user.ID),
+			Event: "New User",
+			Properties: segment.NewProperties().
+				Set("email", user.Email),
+		})
+
+
 		// log the user in
 		app.Logger.Info().Msgf("New user created: %d", user.ID)
 

+ 18 - 0
server/api/user_handler.go

@@ -21,6 +21,7 @@ import (
 	"github.com/porter-dev/porter/internal/integrations/email"
 	"github.com/porter-dev/porter/internal/models"
 	"github.com/porter-dev/porter/internal/repository"
+	segment "gopkg.in/segmentio/analytics-go.v3"
 )
 
 // Enumeration of user API error codes, represented as int64
@@ -50,6 +51,23 @@ func (app *App) HandleCreateUser(w http.ResponseWriter, r *http.Request) {
 	)
 
 	if err == nil {
+		// send to segment
+		client := *app.segmentClient
+		
+		client.Enqueue(segment.Identify{
+			UserId: fmt.Sprintf("%v", user.ID),
+			Traits: segment.NewTraits().
+				SetEmail(user.Email).
+				Set("github", "false"),
+		})
+
+		client.Enqueue(segment.Track{
+			UserId: fmt.Sprintf("%v", user.ID),
+			Event: "New User",
+			Properties: segment.NewProperties().
+				Set("email", user.Email),
+		})
+
 		app.Logger.Info().Msgf("New user created: %d", user.ID)
 		var redirect string