mirror of
https://github.com/tulir/mautrix-whatsapp
synced 2024-12-14 09:23:51 +01:00
Allow setting segment_user_id in config
This commit is contained in:
parent
e5d32cc1e2
commit
fa0a69d746
4 changed files with 16 additions and 2 deletions
|
@ -24,7 +24,8 @@ import (
|
||||||
type Config struct {
|
type Config struct {
|
||||||
*bridgeconfig.BaseConfig `yaml:",inline"`
|
*bridgeconfig.BaseConfig `yaml:",inline"`
|
||||||
|
|
||||||
SegmentKey string `yaml:"segment_key"`
|
SegmentKey string `yaml:"segment_key"`
|
||||||
|
SegmentUserId string `yaml:"segment_user_id"`
|
||||||
|
|
||||||
Metrics struct {
|
Metrics struct {
|
||||||
Enabled bool `yaml:"enabled"`
|
Enabled bool `yaml:"enabled"`
|
||||||
|
|
|
@ -72,6 +72,8 @@ appservice:
|
||||||
|
|
||||||
# Segment API key to track some events, like provisioning API login and encryption errors.
|
# Segment API key to track some events, like provisioning API login and encryption errors.
|
||||||
segment_key: null
|
segment_key: null
|
||||||
|
# Optional user_id to use when sending Segment events. If null, defaults to using mxID.
|
||||||
|
segment_user_id: null
|
||||||
|
|
||||||
# Prometheus config.
|
# Prometheus config.
|
||||||
metrics:
|
metrics:
|
||||||
|
|
4
main.go
4
main.go
|
@ -93,8 +93,12 @@ func (br *WABridge) Init() {
|
||||||
|
|
||||||
Segment.log = br.Log.Sub("Segment")
|
Segment.log = br.Log.Sub("Segment")
|
||||||
Segment.key = br.Config.SegmentKey
|
Segment.key = br.Config.SegmentKey
|
||||||
|
Segment.userID = br.Config.SegmentUserId
|
||||||
if Segment.IsEnabled() {
|
if Segment.IsEnabled() {
|
||||||
Segment.log.Infoln("Segment metrics are enabled")
|
Segment.log.Infoln("Segment metrics are enabled")
|
||||||
|
if Segment.userID != "" {
|
||||||
|
Segment.log.Infoln("Overriding Segment user_id with %v", Segment.userID)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
br.DB = database.New(br.Bridge.DB, br.Log.Sub("Database"))
|
br.DB = database.New(br.Bridge.DB, br.Log.Sub("Database"))
|
||||||
|
|
|
@ -30,6 +30,7 @@ const SegmentURL = "https://api.segment.io/v1/track"
|
||||||
|
|
||||||
type SegmentClient struct {
|
type SegmentClient struct {
|
||||||
key string
|
key string
|
||||||
|
userID string
|
||||||
log log.Logger
|
log log.Logger
|
||||||
client http.Client
|
client http.Client
|
||||||
}
|
}
|
||||||
|
@ -38,8 +39,14 @@ var Segment SegmentClient
|
||||||
|
|
||||||
func (sc *SegmentClient) trackSync(userID id.UserID, event string, properties map[string]interface{}) error {
|
func (sc *SegmentClient) trackSync(userID id.UserID, event string, properties map[string]interface{}) error {
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
|
var segmentUserID string
|
||||||
|
if Segment.userID != "" {
|
||||||
|
segmentUserID = Segment.userID
|
||||||
|
} else {
|
||||||
|
segmentUserID = userID.String()
|
||||||
|
}
|
||||||
err := json.NewEncoder(&buf).Encode(map[string]interface{}{
|
err := json.NewEncoder(&buf).Encode(map[string]interface{}{
|
||||||
"userId": userID,
|
"userId": segmentUserID,
|
||||||
"event": event,
|
"event": event,
|
||||||
"properties": properties,
|
"properties": properties,
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue