diff --git a/app/controllers/concerns/ahoy_controller_patch.rb b/app/controllers/concerns/ahoy_controller_patch.rb index 242210d63..15cf0d018 100644 --- a/app/controllers/concerns/ahoy_controller_patch.rb +++ b/app/controllers/concerns/ahoy_controller_patch.rb @@ -10,6 +10,27 @@ def set_ahoy_cookies end def tracking_enabled? - Subdomain.current.tracking_enabled && request.cookies['cookies_accepted'] == 'true' + locations = Geocoder.search(request.ip) + location = locations.first + track_by_default_country_codes = ['CA', 'US'] + + if Subdomain.current.tracking_enabled + if request.cookies['cookies_accepted'] == 'true' + return true + else + if track_by_default_country_codes.include?(location&.country_code&.upcase) + cookies[:cookies_accepted] = { + value: params[:cookies].presence, + httponly: true, + expires: 1.year + } + return true + else + return false + end + end + else + return false + end end end