mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-11 10:49:43 +08:00
feat: use unique machine ID for reporting GA
This commit is contained in:
@@ -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