Track tracks the event with the provided custom properties, merged with the base properties of the invocation
( ctx context.Context, event string, properties map[string]any, )
| 257 | // Track tracks the event with the provided custom properties, merged with the |
| 258 | // base properties of the invocation |
| 259 | func (a *AnalyticsTelemetryClient) Track( |
| 260 | ctx context.Context, |
| 261 | event string, |
| 262 | properties map[string]any, |
| 263 | ) error { |
| 264 | metadata := GetEventMetadata(ctx) |
| 265 | |
| 266 | props := make(map[string]any, len(properties)+5) |
| 267 | for k, v := range properties { |
| 268 | props[k] = v |
| 269 | } |
| 270 | // Base properties are set last so custom ones can never override them. |
| 271 | props["invocation_id"] = metadata.InvocationID |
| 272 | props["app_id"] = metadata.AppID |
| 273 | props["command"] = metadata.CommandPath |
| 274 | props["flags"] = metadata.CommandFlags |
| 275 | props["sequence"] = a.sequence.Add(1) |
| 276 | |
| 277 | track := analytics.Track{ |
| 278 | Event: event, |
| 279 | AnonymousId: metadata.AnonymousID, |
| 280 | Properties: props, |
| 281 | Context: &analytics.Context{ |
| 282 | Device: analytics.DeviceInfo{ |
| 283 | Id: metadata.AnonymousID, |
| 284 | }, |
| 285 | }, |
| 286 | } |
| 287 | |
| 288 | if metadata.UserID != "" { |
| 289 | track.UserId = metadata.UserID |
| 290 | } |
| 291 | |
| 292 | return a.client.Enqueue(track) |
| 293 | } |
| 294 | |
| 295 | // Close closes the client, waiting for all pending events to be sent. |
| 296 | func (a *AnalyticsTelemetryClient) Close() { |