Skip to content

Commit

Permalink
chore(go): refactor cookie max age to use a duration (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshdk committed Oct 5, 2021
1 parent 8f1c6e7 commit a8123dc
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions analytics/cookie.go
Expand Up @@ -6,11 +6,12 @@ package analytics

import (
"net/http"
"time"

"github.com/gofrs/uuid"
)

const twoYearsInSeconds = 63072000
const twoYears = time.Hour * 24 * 365 * 2

func getCookie(request *http.Request, name string) (string, *http.Cookie) {
// Check if the named cookie was provided along with the request and return
Expand All @@ -29,7 +30,7 @@ func getCookie(request *http.Request, name string) (string, *http.Cookie) {

// Set the cookie expiration to two years (in seconds).
// See: https://developers.google.com/analytics/devguides/collection/analyticsjs/cookies-user-id#configuring_cookie_field_settings
MaxAge: twoYearsInSeconds,
MaxAge: int(twoYears.Seconds()),
}

return cookie.Value, cookie
Expand Down

0 comments on commit a8123dc

Please sign in to comment.