From 40c378771106e4d534019543ec257c6821c27176 Mon Sep 17 00:00:00 2001 From: "Tchekda (ASUS)" Date: Wed, 21 Oct 2020 01:25:01 +0200 Subject: [PATCH 1/2] Make the Advanced Analytics compatible with Cloudflare --- app/Helpers/ClickHelper.php | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/app/Helpers/ClickHelper.php b/app/Helpers/ClickHelper.php index 474103f4d..346813b27 100644 --- a/app/Helpers/ClickHelper.php +++ b/app/Helpers/ClickHelper.php @@ -5,10 +5,6 @@ use Illuminate\Http\Request; class ClickHelper { - static private function getCountry($ip) { - $country_iso = geoip()->getLocation($ip)->iso_code; - return $country_iso; - } static private function getHost($url) { // Return host given URL; NULL if host is @@ -23,13 +19,13 @@ static public function recordClick(Link $link, Request $request) { * @return boolean */ - $ip = $request->ip(); + $location = geoip()->getLocation(); // Withour the IP specified, it will be detected automatically and use the real user IP if website is behind CloudFlare $referer = $request->server('HTTP_REFERER'); $click = new Click; $click->link_id = $link->id; - $click->ip = $ip; - $click->country = self::getCountry($ip); + $click->ip = $location->ip; + $click->country = $location->iso_code; $click->referer = $referer; $click->referer_host = ClickHelper::getHost($referer); $click->user_agent = $request->server('HTTP_USER_AGENT'); From 00520f7a8c8b37263f38f7bbf9e6167916a2ae12 Mon Sep 17 00:00:00 2001 From: Tchekda Date: Wed, 21 Oct 2020 01:34:31 +0200 Subject: [PATCH 2/2] Comment typo --- app/Helpers/ClickHelper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Helpers/ClickHelper.php b/app/Helpers/ClickHelper.php index 346813b27..e7d34e9c0 100644 --- a/app/Helpers/ClickHelper.php +++ b/app/Helpers/ClickHelper.php @@ -19,7 +19,7 @@ static public function recordClick(Link $link, Request $request) { * @return boolean */ - $location = geoip()->getLocation(); // Withour the IP specified, it will be detected automatically and use the real user IP if website is behind CloudFlare + $location = geoip()->getLocation(); // Without the IP specified, it will be detected automatically and use the real user IP if website is behind CloudFlare or other Proxy (Nginx, ...) $referer = $request->server('HTTP_REFERER'); $click = new Click;