mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-12 02:21:29 +08:00
feat: use unique machine ID for reporting GA
This commit is contained in:
1
go.mod
1
go.mod
@@ -3,6 +3,7 @@ module github.com/httprunner/hrp
|
||||
go 1.16
|
||||
|
||||
require (
|
||||
github.com/denisbrodbeck/machineid v1.0.1
|
||||
github.com/getsentry/sentry-go v0.11.0
|
||||
github.com/go-ole/go-ole v1.2.6 // indirect
|
||||
github.com/google/uuid v1.3.0
|
||||
|
||||
2
go.sum
2
go.sum
@@ -78,6 +78,8 @@ github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsr
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/denisbrodbeck/machineid v1.0.1 h1:geKr9qtkB876mXguW2X6TU4ZynleN6ezuMSRhl4D7AQ=
|
||||
github.com/denisbrodbeck/machineid v1.0.1/go.mod h1:dJUwb7PTidGDeYyUBmXZ2GphQBbjJCrnectwCyxcUSI=
|
||||
github.com/dgraph-io/badger v1.6.0/go.mod h1:zwt7syl517jmP8s94KqSxTlM6IMsdhYy6psNgSztDR4=
|
||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
|
||||
github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
|
||||
|
||||
@@ -6,8 +6,6 @@ import (
|
||||
"net/url"
|
||||
"reflect"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -23,11 +21,10 @@ type GAClient struct {
|
||||
}
|
||||
|
||||
// NewGAClient creates a new GAClient object with the trackingID and clientID.
|
||||
func NewGAClient(trackingID string) *GAClient {
|
||||
nodeUUID, _ := uuid.NewUUID()
|
||||
func NewGAClient(trackingID, clientID string) *GAClient {
|
||||
return &GAClient{
|
||||
TrackingID: trackingID,
|
||||
ClientID: nodeUUID.String(),
|
||||
ClientID: clientID,
|
||||
Version: "1", // constant v1
|
||||
httpClient: &http.Client{
|
||||
Timeout: 5 * time.Second,
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
package ga
|
||||
|
||||
import (
|
||||
"github.com/denisbrodbeck/machineid"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
const (
|
||||
trackingID = "UA-114587036-1" // Tracking ID for Google Analytics
|
||||
)
|
||||
@@ -7,7 +12,12 @@ const (
|
||||
var gaClient *GAClient
|
||||
|
||||
func init() {
|
||||
gaClient = NewGAClient(trackingID)
|
||||
clientID, err := machineid.ProtectedID("hrp")
|
||||
if err != nil {
|
||||
nodeUUID, _ := uuid.NewUUID()
|
||||
clientID = nodeUUID.String()
|
||||
}
|
||||
gaClient = NewGAClient(trackingID, clientID)
|
||||
}
|
||||
|
||||
func SendEvent(e IEvent) error {
|
||||
|
||||
Reference in New Issue
Block a user