Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the Advanced Analytics compatible with Cloudflare #569

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions app/Helpers/ClickHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -23,13 +19,13 @@ static public function recordClick(Link $link, Request $request) {
* @return boolean
*/

$ip = $request->ip();
$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;
$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');
Expand Down