Skip to content

Commit 577da03

Browse files
authored
Split "page_url" into "domain", "path", and "params" (#1183)
1 parent e4df1fb commit 577da03

File tree

4 files changed

+41
-14
lines changed

4 files changed

+41
-14
lines changed

handlers/analytics.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ type AnalyticsLog struct {
3131
SessionID string `json:"session_id"`
3232
PlaybackID string `json:"playback_id"`
3333
Protocol string `json:"protocol"`
34-
PageURL string `json:"page_url"`
34+
Domain string `json:"domain"`
35+
Path string `json:"path"`
36+
Params string `json:"params"`
3537
SourceURL string `json:"source_url"`
3638
Player string `json:"player"`
3739
Version string `json:"version"`
@@ -211,7 +213,9 @@ func (c *AnalyticsHandlersCollection) toAnalyticsData(log *AnalyticsLog, geo Ana
211213
PlaybackID: log.PlaybackID,
212214
ViewerHash: hashViewer(log, geo),
213215
Protocol: log.Protocol,
214-
PageURL: log.PageURL,
216+
Domain: log.Domain,
217+
Path: log.Path,
218+
Params: log.Params,
215219
SourceURL: log.SourceURL,
216220
Player: log.Player,
217221
Version: log.Version,
@@ -284,6 +288,6 @@ func hashViewer(log *AnalyticsLog, geo AnalyticsGeo) string {
284288
// If user defined the unique viewer ID, then we just use it
285289
return log.UID
286290
}
287-
// If user didn't define the unique viewer ID, then we hash IP and user agent data
288-
return fmt.Sprintf("%x", sha256.Sum256([]byte(log.UserAgent+geo.IP)))
291+
// If user didn't define the unique viewer ID, then we hash domain, IP and user agent data
292+
return fmt.Sprintf("%x", sha256.Sum256([]byte(log.Domain+log.UserAgent+geo.IP)))
289293
}

handlers/analytics/log_processor.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ type LogData struct {
5858
PlaybackID string `json:"playback_id"`
5959
ViewerHash string `json:"viewer_hash"`
6060
Protocol string `json:"protocol"`
61-
PageURL string `json:"page_url"`
61+
Domain string `json:"domain"`
62+
Path string `json:"path"`
63+
Params string `json:"params"`
64+
Hash string `json:"hash"`
6265
SourceURL string `json:"source_url"`
6366
Player string `json:"player"`
6467
Version string `json:"version"`

handlers/analytics_test.go

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,13 @@ func TestHandleLog(t *testing.T) {
4141
wantProcessedLogs []analytics.LogData
4242
}{
4343
{
44-
name: "valid payload",
4544
requestBody: `{
4645
"session_id": "abcdef",
4746
"playback_id": "123456",
4847
"protocol": "video/mp4",
49-
"page_url": "https://www.fishtank.live/",
48+
"domain" :"www.fishtank.live",
49+
"path": "/some-path",
50+
"params": "a=1",
5051
"source_url": "https://vod-cdn.lp-playback.studio/raw/jxf4iblf6wlsyor6526t4tcmtmqa/catalyst-vod-com/hls/362f9l7ekeoze518/1080p0.mp4?tkn=8b140ec6b404a",
5152
"player": "video",
5253
"version": "3.1.9",
@@ -89,6 +90,7 @@ func TestHandleLog(t *testing.T) {
8990
}
9091
]
9192
}`,
93+
name: "valid payload",
9294
wantHttpCode: 200,
9395
wantExtFetchedPlaybackID: "123456",
9496
wantProcessedLogs: []analytics.LogData{
@@ -97,7 +99,9 @@ func TestHandleLog(t *testing.T) {
9799
PlaybackID: "123456",
98100
ViewerHash: "abcdef",
99101
Protocol: "video/mp4",
100-
PageURL: "https://www.fishtank.live/",
102+
Domain: "www.fishtank.live",
103+
Path: "/some-path",
104+
Params: "a=1",
101105
SourceURL: "https://vod-cdn.lp-playback.studio/raw/jxf4iblf6wlsyor6526t4tcmtmqa/catalyst-vod-com/hls/362f9l7ekeoze518/1080p0.mp4?tkn=8b140ec6b404a",
102106
Player: "video",
103107
Version: "3.1.9",
@@ -137,7 +141,9 @@ func TestHandleLog(t *testing.T) {
137141
PlaybackID: "123456",
138142
ViewerHash: "abcdef",
139143
Protocol: "video/mp4",
140-
PageURL: "https://www.fishtank.live/",
144+
Domain: "www.fishtank.live",
145+
Path: "/some-path",
146+
Params: "a=1",
141147
SourceURL: "https://vod-cdn.lp-playback.studio/raw/jxf4iblf6wlsyor6526t4tcmtmqa/catalyst-vod-com/hls/362f9l7ekeoze518/1080p0.mp4?tkn=8b140ec6b404a",
142148
Player: "video",
143149
Version: "3.1.9",
@@ -164,9 +170,12 @@ func TestHandleLog(t *testing.T) {
164170
"session_id": "abcdef",
165171
"playback_id": "123456",
166172
"protocol": "video/mp4",
167-
"page_url": "https://www.fishtank.live/",
173+
"domain" :"www.fishtank.live",
174+
"path": "/some-path",
175+
"params": "a=1",
168176
"source_url": "https://vod-cdn.lp-playback.studio/raw/jxf4iblf6wlsyor6526t4tcmtmqa/catalyst-vod-com/hls/362f9l7ekeoze518/1080p0.mp4?tkn=8b140ec6b404a",
169177
"player": "video-@livepeer/[email protected]",
178+
"version": "3.1.9",
170179
"user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36",
171180
"uid": "abcdef",
172181
"events": [
@@ -188,9 +197,12 @@ func TestHandleLog(t *testing.T) {
188197
requestBody: `{
189198
"playback_id": "123456",
190199
"protocol": "video/mp4",
191-
"page_url": "https://www.fishtank.live/",
200+
"domain" :"www.fishtank.live",
201+
"path": "/some-path",
202+
"params: "a=1",
192203
"source_url": "https://vod-cdn.lp-playback.studio/raw/jxf4iblf6wlsyor6526t4tcmtmqa/catalyst-vod-com/hls/362f9l7ekeoze518/1080p0.mp4?tkn=8b140ec6b404a",
193204
"player": "video-@livepeer/[email protected]",
205+
"version": "3.1.9",
194206
"user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36",
195207
"uid": "abcdef",
196208
"events": [

handlers/schemas/AnalyticsLog.yaml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,20 @@ properties:
66
type: "string"
77
protocol:
88
type: "string"
9-
page_url:
10-
type: "string"
119
source_url:
1210
type: "string"
1311
player:
1412
type: "string"
13+
version:
14+
type: "string"
15+
domain:
16+
type: "string"
17+
path:
18+
type: "string"
19+
params:
20+
type: "string"
21+
hash:
22+
type: "string"
1523
user_agent:
1624
type: "string"
1725
uid:
@@ -46,8 +54,8 @@ required:
4654
- session_id
4755
- playback_id
4856
- protocol
49-
- page_url
5057
- source_url
5158
- player
59+
- version
5260
- user_agent
5361
- events

0 commit comments

Comments
 (0)