| 141 | } |
| 142 | |
| 143 | func (c *Client) UserActivityInsights(ctx context.Context, req UserActivityInsightsRequest) (UserActivityInsightsResponse, error) { |
| 144 | qp := url.Values{} |
| 145 | qp.Add("start_time", req.StartTime.Format(insightsTimeLayout)) |
| 146 | qp.Add("end_time", req.EndTime.Format(insightsTimeLayout)) |
| 147 | if len(req.TemplateIDs) > 0 { |
| 148 | var templateIDs []string |
| 149 | for _, id := range req.TemplateIDs { |
| 150 | templateIDs = append(templateIDs, id.String()) |
| 151 | } |
| 152 | qp.Add("template_ids", strings.Join(templateIDs, ",")) |
| 153 | } |
| 154 | |
| 155 | reqURL := fmt.Sprintf("/api/v2/insights/user-activity?%s", qp.Encode()) |
| 156 | resp, err := c.Request(ctx, http.MethodGet, reqURL, nil) |
| 157 | if err != nil { |
| 158 | return UserActivityInsightsResponse{}, xerrors.Errorf("make request: %w", err) |
| 159 | } |
| 160 | defer resp.Body.Close() |
| 161 | |
| 162 | if resp.StatusCode != http.StatusOK { |
| 163 | return UserActivityInsightsResponse{}, ReadBodyAsError(resp) |
| 164 | } |
| 165 | var result UserActivityInsightsResponse |
| 166 | return result, json.NewDecoder(resp.Body).Decode(&result) |
| 167 | } |
| 168 | |
| 169 | // TemplateInsightsResponse is the response from the template insights endpoint. |
| 170 | type TemplateInsightsResponse struct { |