Skip to content

Commit

Permalink
feat(backend): added session's screen width/height to PG
Browse files Browse the repository at this point in the history
  • Loading branch information
zavorotynskiy committed Apr 8, 2024
1 parent b5d0770 commit 486a711
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 6 deletions.
6 changes: 3 additions & 3 deletions backend/internal/http/router/handlers-mobile.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,11 @@ func (e *Router) startSessionHandlerIOS(w http.ResponseWriter, r *http.Request)
r = r.WithContext(context.WithValue(r.Context(), "sessionID", fmt.Sprintf("%d", sessionID)))

geoInfo := e.ExtractGeoData(r)
deviceType, platform, os, screen := ios.GetIOSDeviceType(req.UserDevice), "ios", "IOS", ""
deviceType, platform, os := ios.GetIOSDeviceType(req.UserDevice), "ios", "IOS"
if req.Platform != "" && req.Platform != "ios" {
deviceType = req.UserDeviceType
platform = req.Platform
os = "Android"
screen = fmt.Sprintf("%d:%d", req.Width, req.Height)
e.log.Info(r.Context(), "mobile screen size: %s", screen)
}

if !req.DoNotRecord {
Expand All @@ -133,6 +131,8 @@ func (e *Router) startSessionHandlerIOS(w http.ResponseWriter, r *http.Request)
UserCity: geoInfo.City,
UserDeviceMemorySize: req.DeviceMemory,
UserDeviceHeapSize: req.DeviceMemory,
ScreenWidth: req.Width,
ScreenHeight: req.Height,
}); err != nil {
e.log.Warn(r.Context(), "failed to add mobile session to DB: %s", err)
}
Expand Down
2 changes: 2 additions & 0 deletions backend/internal/http/router/handlers-web.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,8 @@ func (e *Router) startSessionHandlerWeb(w http.ResponseWriter, r *http.Request)
UserDeviceMemorySize: sessionStart.UserDeviceMemorySize,
UserDeviceHeapSize: sessionStart.UserDeviceHeapSize,
UserID: &sessionStart.UserID,
ScreenWidth: req.Width,
ScreenHeight: req.Height,
}); err != nil {
e.log.Warn(r.Context(), "can't insert sessionStart to DB: %s", err)
}
Expand Down
2 changes: 2 additions & 0 deletions backend/internal/http/router/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ type StartSessionRequest struct {
BufferDiff uint64 `json:"bufferDiff"` // buffer diff in ms for start record session
IsOffline bool `json:"isOffline"` // to indicate that we have to use user's start timestamp
Condition string `json:"condition"` // condition for start record session
Width int `json:"width"`
Height int `json:"height"`
}

type StartSessionResponse struct {
Expand Down
2 changes: 2 additions & 0 deletions backend/pkg/sessions/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ type Session struct {
UserDeviceHeapSize uint64
SaveRequestPayload bool
EncryptionKey string
ScreenWidth int
ScreenHeight int
}

func (s *Session) SetMetadata(keyNo uint, value string) {
Expand Down
6 changes: 3 additions & 3 deletions backend/pkg/sessions/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (s *storageImpl) Add(sess *Session) error {
tracker_version, issue_score,
platform,
user_browser, user_browser_version, user_device_memory_size, user_device_heap_size,
user_id, user_state, user_city, timezone
user_id, user_state, user_city, timezone, screen_width, screen_height
) VALUES (
$1, $2, $3,
$4, $5, $6, $7,
Expand All @@ -50,7 +50,7 @@ func (s *storageImpl) Add(sess *Session) error {
$11, $12,
$13,
NULLIF($14, ''), NULLIF($15, ''), NULLIF($16, 0), NULLIF($17, 0::bigint),
NULLIF(LEFT($18, 8000), ''), NULLIF($19, ''), NULLIF($20, ''), $21
NULLIF(LEFT($18, 8000), ''), NULLIF($19, ''), NULLIF($20, ''), $21, $22, $23
)`,
sess.SessionID, sess.ProjectID, sess.Timestamp,
sess.UserUUID, sess.UserDevice, sess.UserDeviceType, sess.UserCountry,
Expand All @@ -59,7 +59,7 @@ func (s *storageImpl) Add(sess *Session) error {
sess.TrackerVersion, sess.Timestamp/1000,
sess.Platform,
sess.UserBrowser, sess.UserBrowserVersion, sess.UserDeviceMemorySize, sess.UserDeviceHeapSize,
sess.UserID, sess.UserState, sess.UserCity, sess.Timezone,
sess.UserID, sess.UserState, sess.UserCity, sess.Timezone, sess.ScreenWidth, sess.ScreenHeight,
)
}

Expand Down

0 comments on commit 486a711

Please sign in to comment.