@@ -62,6 +62,30 @@ type UserLatency struct {
62
62
LatencyMS ConnectionLatency `json:"latency_ms"`
63
63
}
64
64
65
+ // UserActivityInsightsResponse is the response from the user activity insights
66
+ // endpoint.
67
+ type UserActivityInsightsResponse struct {
68
+ Report UserActivityInsightsReport `json:"report"`
69
+ }
70
+
71
+ // UserActivityInsightsReport is the report from the user activity insights
72
+ // endpoint.
73
+ type UserActivityInsightsReport struct {
74
+ StartTime time.Time `json:"start_time" format:"date-time"`
75
+ EndTime time.Time `json:"end_time" format:"date-time"`
76
+ TemplateIDs []uuid.UUID `json:"template_ids" format:"uuid"`
77
+ Users []UserActivity `json:"users"`
78
+ }
79
+
80
+ // UserActivity shows the session time for a user.
81
+ type UserActivity struct {
82
+ TemplateIDs []uuid.UUID `json:"template_ids" format:"uuid"`
83
+ UserID uuid.UUID `json:"user_id" format:"uuid"`
84
+ Username string `json:"username"`
85
+ AvatarURL string `json:"avatar_url" format:"uri"`
86
+ Seconds int64 `json:"seconds" example:"80500"`
87
+ }
88
+
65
89
// ConnectionLatency shows the latency for a connection.
66
90
type ConnectionLatency struct {
67
91
P50 float64 `json:"p50" example:"31.312"`
@@ -100,6 +124,38 @@ func (c *Client) UserLatencyInsights(ctx context.Context, req UserLatencyInsight
100
124
return result , json .NewDecoder (resp .Body ).Decode (& result )
101
125
}
102
126
127
+ type UserActivityInsightsRequest struct {
128
+ StartTime time.Time `json:"start_time" format:"date-time"`
129
+ EndTime time.Time `json:"end_time" format:"date-time"`
130
+ TemplateIDs []uuid.UUID `json:"template_ids" format:"uuid"`
131
+ }
132
+
133
+ func (c * Client ) UserActivityInsights (ctx context.Context , req UserActivityInsightsRequest ) (UserActivityInsightsResponse , error ) {
134
+ qp := url.Values {}
135
+ qp .Add ("start_time" , req .StartTime .Format (insightsTimeLayout ))
136
+ qp .Add ("end_time" , req .EndTime .Format (insightsTimeLayout ))
137
+ if len (req .TemplateIDs ) > 0 {
138
+ var templateIDs []string
139
+ for _ , id := range req .TemplateIDs {
140
+ templateIDs = append (templateIDs , id .String ())
141
+ }
142
+ qp .Add ("template_ids" , strings .Join (templateIDs , "," ))
143
+ }
144
+
145
+ reqURL := fmt .Sprintf ("/api/v2/insights/user-activity?%s" , qp .Encode ())
146
+ resp , err := c .Request (ctx , http .MethodGet , reqURL , nil )
147
+ if err != nil {
148
+ return UserActivityInsightsResponse {}, xerrors .Errorf ("make request: %w" , err )
149
+ }
150
+ defer resp .Body .Close ()
151
+
152
+ if resp .StatusCode != http .StatusOK {
153
+ return UserActivityInsightsResponse {}, ReadBodyAsError (resp )
154
+ }
155
+ var result UserActivityInsightsResponse
156
+ return result , json .NewDecoder (resp .Body ).Decode (& result )
157
+ }
158
+
103
159
// TemplateInsightsResponse is the response from the template insights endpoint.
104
160
type TemplateInsightsResponse struct {
105
161
Report TemplateInsightsReport `json:"report"`
0 commit comments