diff options
| author | horus | 2022-11-15 15:52:30 +0100 |
|---|---|---|
| committer | horus | 2022-11-15 15:52:30 +0100 |
| commit | f4e8c78413b4f48ddb9910afa356c3d711188f2b (patch) | |
| tree | 4e7beab155100383dfe9a7516b932ccf7cf3f801 /app | |
| parent | 3314af96df7b72bf799fc2e776cbdbd4c4e6dbee (diff) | |
| download | kategorischeraperitif-f4e8c78413b4f48ddb9910afa356c3d711188f2b.tar.gz | |
integrate external linkshorter including matomo tracking
Diffstat (limited to 'app')
| -rw-r--r-- | app/Http/Controllers/LinkController.php | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/app/Http/Controllers/LinkController.php b/app/Http/Controllers/LinkController.php new file mode 100644 index 0000000..4515e04 --- /dev/null +++ b/app/Http/Controllers/LinkController.php @@ -0,0 +1,38 @@ +<?php +namespace App\Http\Controllers; +use Illuminate\Http\Request; +use App\Helpers\CryptoHelper; + +use Illuminate\Support\Facades\DB; +use App\Http\Controllers\Controller; + +class LinkController extends Controller { + /** + * Shows the index page. + * + * @return Response + */ + public function redirect(Request $request, $shortlink) { + + $matomo = new \MatomoTracker( env('MATOMO_LINK_SHORTER_ID'), env('MATOMO_URL')); + $matomo->setTokenAuth( env('MATOMO_LINK_SHORTER_AUTH_TOKEN') ); + #$matomo->setVisitorId( $matomo->getVisitorId() ); + $matomo->setIp( $request->header('X_REAL_IP') ); + $matomo->setUrl( $shortlink ); + $matomo->setUrlReferrer( $request->server('HTTP_REFERER') ); + $matomo->setBrowserLanguage( $request->server('HTTP_ACCEPT_LANGUAGE') ); + $matomo->setUserAgent( $request->server('HTTP_USER_AGENT') ); + + $data = DB::table('all_view')->select('name', 'shop', 'spirit_type', 'long_url')->where('url', "https://l.fuselkoenig.de/" . $shortlink)->limit(1)->get()->first(); + + $matomo->doTrackPageView( $data->name . " - " . $data->shop ); + $matomo->doTrackEvent("Redirect", "Shop", $data->shop); + $matomo->doTrackEvent("Redirect", "Name", $data->name); + $matomo->doTrackEvent("Redirect", "Spirit Type", $data->spirit_type); + $matomo->doTrackEvent("Redirect", "Short URL", $shortlink); + $matomo->doTrackEvent("Redirect", "Long URL", $data->long_url); + + #return response()->json($data); + return redirect()->away($data->long_url, 302); + } +} |
