mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-14 08:37:36 +08:00
72 lines
1.9 KiB
Go
72 lines
1.9 KiB
Go
package ga
|
|
|
|
import (
|
|
"fmt"
|
|
"net/url"
|
|
"time"
|
|
|
|
"github.com/httprunner/hrp/internal/version"
|
|
)
|
|
|
|
type IEvent interface {
|
|
ToUrlValues() url.Values
|
|
}
|
|
|
|
type EventTracking struct {
|
|
HitType string `form:"t"` // Event hit type = event
|
|
Category string `form:"ec"` // Required. Event Category.
|
|
Action string `form:"ea"` // Required. Event Action.
|
|
Label string `form:"el"` // Optional. Event label, used as version.
|
|
Value string `form:"ev"` // Optional. Event value, must be digits, "123"
|
|
}
|
|
|
|
func (e EventTracking) StartTiming(variable string) UserTimingTracking {
|
|
return UserTimingTracking{
|
|
HitType: "timing",
|
|
Category: e.Category,
|
|
Variable: variable,
|
|
Label: e.Label,
|
|
startTime: time.Now(), // starts the timer
|
|
}
|
|
}
|
|
|
|
func (e EventTracking) ToUrlValues() url.Values {
|
|
e.HitType = "event"
|
|
e.Label = version.VERSION
|
|
return structToUrlValues(e)
|
|
}
|
|
|
|
type UserTimingTracking struct {
|
|
HitType string `form:"t"` // Timing hit type
|
|
Category string `form:"utc"` // Required. user timing category. e.g. jsonLoader
|
|
Variable string `form:"utv"` // Required. timing variable. e.g. load
|
|
Duration string `form:"utt"` // Required. time took duration. Required.
|
|
Label string `form:"utl"` // Optional. user timing label. e.g jQuery
|
|
startTime time.Time
|
|
duration time.Duration // time took duration
|
|
}
|
|
|
|
func (e UserTimingTracking) ToUrlValues() url.Values {
|
|
e.HitType = "timing"
|
|
e.Label = version.VERSION
|
|
e.Duration = fmt.Sprintf("%d", int64(e.duration.Seconds()*1000))
|
|
return structToUrlValues(e)
|
|
}
|
|
|
|
type Exception struct {
|
|
HitType string `form:"t"` // Hit Type = exception
|
|
Description string `form:"exd"` // exception description. i.e. IOException
|
|
IsFatal string `form:"exf"` // if the exception was fatal
|
|
isFatal bool
|
|
}
|
|
|
|
func (e Exception) ToUrlValues() url.Values {
|
|
e.HitType = "exception"
|
|
if e.isFatal {
|
|
e.IsFatal = "1"
|
|
} else {
|
|
e.IsFatal = "0"
|
|
}
|
|
return structToUrlValues(e)
|
|
}
|