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

Function TestAnalyticsRedirectAndTrack

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

Source from the content-addressed store, hash-verified

65}
66
67func TestAnalyticsRedirectAndTrack(t *testing.T) {
68 client, _ := newClient(t)
69 analytics := client.Analytics()
70 event1 := stream.EngagementEvent{}.
71 WithLabel("click").
72 WithForeignID("abcdef").
73 WithUserData(stream.NewUserData().Int(12345).Alias("John Doe")).
74 WithFeedID("timeline:123").
75 WithLocation("hawaii").
76 WithPosition(42).
77 WithBoost(10)
78 event2 := stream.EngagementEvent{}.
79 WithLabel("share").
80 WithForeignID("aabbccdd").
81 WithUserData(stream.NewUserData().String("bob")).
82 WithFeedID("timeline:123").
83 WithFeatures(
84 stream.NewEventFeature("color", "red"),
85 stream.NewEventFeature("size", "xxl"),
86 )
87 imp := stream.ImpressionEventsData{}.
88 WithForeignIDs("a", "b", "c", "d").
89 WithUserData(stream.NewUserData().Int(123)).
90 WithFeedID("timeline:123").
91 WithFeatures(
92 stream.NewEventFeature("color", "red"),
93 stream.NewEventFeature("size", "xxl"),
94 ).
95 WithLocation("hawaii").
96 WithPosition(42)
97
98 link, err := analytics.RedirectAndTrack("foo.bar.baz", event1, event2, imp)
99 require.NoError(t, err)
100 query, err := url.ParseQuery(`api_key=key&authorization=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhY3Rpb24iOiIqIiwicmVzb3VyY2UiOiJyZWRpcmVjdF9hbmRfdHJhY2siLCJ1c2VyX2lkIjoiKiJ9.A1vy9pFwLw5s6qn0chkhRcoy974A16a0lE-x5Vtxb-o&events=[{"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"},{"content_list":["a","b","c","d"],"features":[{"group":"color","value":"red"},{"group":"size","value":"xxl"}],"feed_id":"timeline:123","location":"hawaii","position":42,"user_data":123}]&stream-auth-type=jwt&url=foo.bar.baz`)
101 require.NoError(t, err)
102 expected := "https://analytics.stream-io-api.com/analytics/v1.0/redirect/?" + query.Encode()
103 assert.Equal(t, expected, link)
104}

Callers

nothing calls this directly

Calls 15

newClientFunction · 0.85
AnalyticsMethod · 0.80
WithBoostMethod · 0.80
WithForeignIDMethod · 0.80
WithLabelMethod · 0.80
AliasMethod · 0.80
IntMethod · 0.80
WithForeignIDsMethod · 0.80
RedirectAndTrackMethod · 0.80
WithPositionMethod · 0.45
WithLocationMethod · 0.45
WithFeedIDMethod · 0.45

Tested by

no test coverage detected