MCPcopy Create free account
hub / github.com/GetStream/stream-go2 / TestAnalyticsTrackEngagement

Function TestAnalyticsTrackEngagement

analytics_test.go:15–43  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

13)
14
15func TestAnalyticsTrackEngagement(t *testing.T) {
16 ctx := context.Background()
17 client, requester := newClient(t)
18 analytics := client.Analytics()
19 event1 := stream.EngagementEvent{}.
20 WithLabel("click").
21 WithForeignID("abcdef").
22 WithUserData(stream.NewUserData().Int(12345).Alias("John Doe")).
23 WithFeedID("timeline:123").
24 WithLocation("hawaii").
25 WithPosition(42).
26 WithBoost(10)
27
28 event2 := stream.EngagementEvent{}.
29 WithLabel("share").
30 WithForeignID("aabbccdd").
31 WithUserData(stream.NewUserData().String("bob")).
32 WithFeedID("timeline:123").
33 WithFeatures(
34 stream.NewEventFeature("color", "red"),
35 stream.NewEventFeature("size", "xxl"),
36 )
37
38 _, err := analytics.TrackEngagement(ctx, event1, event2)
39 require.NoError(t, err)
40 expectedURL := "https://analytics.stream-io-api.com/analytics/v1.0/engagement/?api_key=key"
41 expectedBody := `{"content_list":[{"boost":10,"content":"abcdef","feed_id":"timeline:123","label":"click","location":"hawaii","position":42,"user_data":{"alias":"John Doe","id":12345}},{"content":"aabbccdd","features":[{"group":"color","value":"red"},{"group":"size","value":"xxl"}],"feed_id":"timeline:123","label":"share","user_data":"bob"}]}`
42 testRequest(t, requester.req, http.MethodPost, expectedURL, expectedBody)
43}
44
45func TestAnalyticsTrackImpression(t *testing.T) {
46 ctx := context.Background()

Callers

nothing calls this directly

Calls 15

newClientFunction · 0.85
testRequestFunction · 0.85
AnalyticsMethod · 0.80
WithBoostMethod · 0.80
WithForeignIDMethod · 0.80
WithLabelMethod · 0.80
AliasMethod · 0.80
IntMethod · 0.80
TrackEngagementMethod · 0.80
WithPositionMethod · 0.45
WithLocationMethod · 0.45
WithFeedIDMethod · 0.45

Tested by

no test coverage detected