MCPcopy Create free account
hub / github.com/algolia/cli / Track

Method Track

pkg/telemetry/telemetry.go:259–293  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

257// Track tracks the event with the provided custom properties, merged with the
258// base properties of the invocation
259func (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.
296func (a *AnalyticsTelemetryClient) Close() {

Calls 3

GetEventMetadataFunction · 0.85
AddMethod · 0.80
EnqueueMethod · 0.80