public function hash(Request $request, $key) { $link = DB::table('keys')->where('key', '=', $key)->get(); if ($link) { $current_ip = $request->getClientIp(); $test = app('Illuminate\\Routing\\UrlGenerator')->previous(); // $name = $this->get_title($test); $name = 'google.com'; $location = GeoIPFacade::getLocation('202.142.69.126'); $os_info = parser::detect(); //City data if (!City::where('city_name', $location['city'])->count()) { $city = new City(); $city_id = $city->insertGetId(['city_name' => $location['city']]); } else { $city_id = City::where('city_name', $location['city'])->value('id'); } //Country Data if (!Country::where('country_name', $location['country'])->count()) { $country = new Country(); $country_id = $country->insertGetId(['country_name' => $location['country']]); } else { $country_id = Country::where('country_name', $location['country'])->value('id'); } //Os Data if (!Operating_system::where('operating_system', $os_info['osFamily'])->count()) { $os = new Operating_system(); $os_id = $os->insertGetId(['operating_system' => $os_info['osFamily']]); } else { $os_id = Operating_system::where('operating_system', $os_info['osFamily'])->value('id'); } //Browser_data if (!Browser::where('browser_name', $os_info['browserFamily'])->count()) { $browser = new Browser(); $browser_id = $browser->insertGetId(['browser_name' => $os_info['browserFamily']]); } else { $browser_id = Browser::where('browser_name', $os_info['browserFamily'])->value('id'); } //Redirected Website data $website_hits = new Redirected_websites(); $website_hits->user_id = $link[0]->user_id; $website_hits->url_id = $link[0]->id; $website_hits->city_id = $city_id; $website_hits->country_id = $country_id; $website_hits->website_url = $test; $website_hits->website_name = $name; $website_hits->browser_id = $browser_id; $website_hits->os_id = $os_id; $website_hits->is_mobile = $os_info['isMobile']; $website_hits->is_tablet = $os_info['isTablet']; $website_hits->is_desktop = $os_info['isDesktop']; //Hits data $data = new Hit(); $data->url_ip = $current_ip; $data->url_id = $link[0]->id; $data->save(); $website_hits->save(); //Deep linking if (parser::isMobile()) { if (parser::osFamily() == 'Apple iOS') { //link for apple store } elseif (parser::osFamily() == 'Windows') { return redirect('https://www.microsoft.com/en-us/store/apps/google/9wzdncrfhx3w'); } elseif (parser::osFamily() == 'Blackberry') { //link for blackberry store } elseif (parser::osFamily() == 'AndroidOS') { return redirect('https://play.google.com/store/apps/details?id=com.facebook.katana&hl=en'); } } if (parser::isMobile()) { if (parser::osFamily() == 'Apple iOS') { //link for apple store } elseif (parser::osFamily() == 'Windows') { return redirect('https://www.microsoft.com/en-us/store/apps/google/9wzdncrfhx3w'); } elseif (parser::osFamily() == 'Blackberry') { //link for blackberry store } elseif (parser::osFamily() == 'AndroidOS') { return redirect('https://play.google.com/store/apps/details?id=com.facebook.katana&hl=en'); } } else { return redirect($link[0]->url); } } else { return redirect('/'); } }
/** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show($id) { $url = Key::findOrFail($id); $hits_count = Hit::all()->count(); //Jit vs time $hits = Hit::where('url_id', $url->id)->select(DB::raw('date(created_at) as date'), DB::raw('count(id) as hits'))->groupBy(DB::raw('date(created_at)'))->distinct()->get(); //Referral websites Data $referral_data = Redirected_websites::where('url_id', $url->id)->select(DB::raw('website_name as website'), DB::raw('count(website_name) as hits'))->groupBy('website_name')->distinct()->get(); //country vs hits graph $country_data = Redirected_websites::where('url_id', $url->id)->select(DB::raw('(select(country_name) from countries where id =country_id) as country'), DB::raw('count(country_id) as hits'))->groupBy('country')->distinct()->get(); //city vs hits graph $city_data = Redirected_websites::where('url_id', $url->id)->select(DB::raw('(select(city_name) from cities where id =city_id) as city'), DB::raw('count(city_id) as hits'))->groupBy('city')->distinct()->get(); //Browser vs hits graph $browser_data = Redirected_websites::where('url_id', $url->id)->select(DB::raw('(select(browser_name) from browsers where id =browser_id) as browser'), DB::raw('count(browser_id) as hits'))->groupBy('browser')->distinct()->get(); //Operating System vs hits graph $os_data = Redirected_websites::where('url_id', $url->id)->select(DB::raw('(select(operating_system) from operating_systems where id = os_id) as os'), DB::raw('count(os_id) as hits'))->groupBy('os')->distinct()->get(); //platform Data $query1 = Redirected_websites::where('url_id', $url->id)->select(DB::raw('"Desktop" as device'), DB::raw('count(is_desktop) as hit'))->where('is_desktop', 1)->groupBy('is_desktop')->get(); $query2 = Redirected_websites::where('url_id', $url->id)->select(DB::raw('"Mobile" as device'), DB::raw('count(is_mobile) as hits'))->where('is_mobile', 0)->groupBy('is_mobile')->get(); $query3 = Redirected_websites::where('url_id', $url->id)->select(DB::raw('"Tablet" as device'), DB::raw('count(is_tablet) as hits'))->where('is_tablet', 0)->groupBy('is_tablet')->get(); $platform = array(); array_push($platform, ['Desktop' => $query1, 'Mobile' => $query2, 'Tablet' => $query3]); return response()->json(['Total_hits' => $hits_count, 'Hits_data' => $this->hitsTransformer->transform($hits), 'City_data' => $this->cityTransformer->transform($city_data), 'Country_data' => $this->countryTransformer->transform($country_data), 'Browser_data' => $this->browserTransformer->transform($browser_data), 'Os_data' => $this->osTransformer->transform($os_data), 'Platforms_visit' => $platform]); }
public function getHits(Request $request, $id) { //$hits = DB::table('hits')->where('url_id','=','keys.id')->get(); $url = Key::findOrFail($id); //Hits Vs Time Graph Data $hits = Hit::where('url_id', $url->id)->select(DB::raw('date(created_at) as date'), DB::raw('count(id) as hits'))->groupBy(DB::raw('date(created_at)'))->distinct()->get(); //total number of hits $total_hit = count($hits); //Referral websites Data $referral_data = Redirected_websites::where('url_id', $url->id)->select(DB::raw('website_name as website'), DB::raw('count(website_name) as hits'))->groupBy('website_name')->distinct()->get(); //country vs hits graph $country_data = Redirected_websites::where('url_id', $url->id)->select(DB::raw('(select(country_name) from countries where id =country_id) as country'), DB::raw('count(country_id) as hits'))->groupBy('country')->distinct()->get(); //city vs hits graph $city_data = Redirected_websites::where('url_id', $url->id)->select(DB::raw('(select(city_name) from cities where id =city_id) as city'), DB::raw('count(city_id) as hits'))->groupBy('city')->distinct()->get(); //Browser vs hits graph $browser_data = Redirected_websites::where('url_id', $url->id)->select(DB::raw('(select(browser_name) from browsers where id =browser_id) as browser'), DB::raw('count(browser_id) as hits'))->groupBy('browser')->distinct()->get(); //Operating System vs hits graph $os_data = Redirected_websites::where('url_id', $url->id)->select(DB::raw('(select(operating_system) from operating_systems where id = os_id) as os'), DB::raw('count(os_id) as hits'))->groupBy('os')->distinct()->get(); //platform Data $query1 = Redirected_websites::where('url_id', $url->id)->select(DB::raw('"Desktop" as device'), DB::raw('count(is_desktop) as hit'))->where('is_desktop', 1)->groupBy('is_desktop')->get(); $query2 = Redirected_websites::where('url_id', $url->id)->select(DB::raw('"Mobile" as device'), DB::raw('count(is_mobile) as hits'))->where('is_mobile', 0)->groupBy('is_mobile')->get(); $query3 = Redirected_websites::where('url_id', $url->id)->select(DB::raw('"Tablet" as device'), DB::raw('count(is_tablet) as hits'))->where('is_tablet', 0)->groupBy('is_tablet')->get(); $platform = array(); array_push($platform, ['Desktop' => $query1, 'Mobile' => $query2, 'Tablet' => $query3]); return $platform; // return view('User.hits',compact('url','hits_data','url_stats','items')); }