diff --git a/metager/app/Http/Controllers/StatisticsController.php b/metager/app/Http/Controllers/StatisticsController.php index e66c903cf3c17d5e83c47d65e3cc1b7ee6087d09..dc0c252c26c2e191b82ec8862aa512825140d6ca 100644 --- a/metager/app/Http/Controllers/StatisticsController.php +++ b/metager/app/Http/Controllers/StatisticsController.php @@ -10,9 +10,6 @@ class StatisticsController extends Controller { public function pageLoad(Request $request) { - if (!config("metager.matomo.enabled") || config("metager.matomo.url") === null) - return; - $params = [ "idsite" => config("metager.matomo.site_id"), "token_auth" => config("metager.matomo.token_auth"), @@ -30,6 +27,24 @@ class StatisticsController extends Controller $params["lang"] = $request->header("Accept-Language"); $params = array_merge($http_params, $params); // Merge arrays keeping our serverside defined options if key is set multiple times + self::LOG_STATISTICS($params); + } + + public static function LOG_STATISTICS(array $params) + { + if (!config("metager.matomo.enabled") || config("metager.matomo.url") === null) + return; + + $params = array_merge($params, [ + "idsite" => config("metager.matomo.site_id"), + "token_auth" => config("metager.matomo.token_auth"), + "rand" => md5(microtime(true)), + "rec" => "1", + "send_image" => "0", + "cip" => \Request::ip(), + "_id" => substr(md5(\Request::ip() . now()->format("Y-m-d")), 0, 16) + ]); + $url = config("metager.matomo.url") . "/matomo.php?" . http_build_query($params); // Submit fetch job to worker @@ -47,4 +62,5 @@ class StatisticsController extends Controller Redis::rpush(\App\MetaGer::FETCHQUEUE_KEY, $mission); } + } diff --git a/metager/app/Http/Controllers/TilesController.php b/metager/app/Http/Controllers/TilesController.php index 9cef7309bfea640afa088efb4a7790d7021256bd..d0a5f975b801c43a4e1b4f9dee52baaf62cf2a17 100644 --- a/metager/app/Http/Controllers/TilesController.php +++ b/metager/app/Http/Controllers/TilesController.php @@ -25,6 +25,12 @@ class TilesController extends Controller $count = $request->input("count", 4); $tiles = []; $tiles = self::TAKE_TILES($ckey, $count); + StatisticsController::LOG_STATISTICS([ + "e_c" => "Take Tiles", + "e_a" => "Load", + "e_n" => "Take Tiles", + "e_v" => sizeof($tiles), + ]); return response()->json($tiles); } diff --git a/metager/resources/js/startpage/tiles.js b/metager/resources/js/startpage/tiles.js index 9838eb2dd5f17936219b9c5c04cbd83860ff0982..891eb2821a5dafda358c0f8c5833cc98668f7cd2 100644 --- a/metager/resources/js/startpage/tiles.js +++ b/metager/resources/js/startpage/tiles.js @@ -1,3 +1,5 @@ +import { statistics } from "../statistics"; + (async () => { let tile_container = document.querySelector("#tiles"); let tile_count = tile_container.querySelectorAll("a").length; @@ -38,6 +40,10 @@ let container = document.createElement("div"); container.innerHTML = advertisements[i].html; + container.firstChild.addEventListener("click", e => { + statistics.takeTilesClick(e.target.closest("a").href); + }); + tile_container.appendChild(container.firstChild); } } diff --git a/metager/resources/js/statistics.js b/metager/resources/js/statistics.js index 4b2f8df60f80003e83bbeb477b2ff6ee446aca87..02707a0a89d89d0aa7a47f9aaa6ebab07bee3ffa 100644 --- a/metager/resources/js/statistics.js +++ b/metager/resources/js/statistics.js @@ -7,6 +7,18 @@ class Statistics { #load_time = new Date(); constructor() { + + } + + #init() { + setTimeout(this.pageLoad.bind(this), 60000); + document.addEventListener("visibilitychange", this.pageLoad.bind(this)); + document.querySelectorAll("a").forEach(anchor => { + anchor.addEventListener("click", e => this.pageLeave(e.target.closest("a").href)); + }); + } + + registerPageLoadEvents() { let performance = window.performance.getEntriesByType('navigation')[0]; try { let statistics_enabled = document.querySelector("meta[name=statistics-enabled]").content; @@ -26,14 +38,6 @@ class Statistics { } } - #init() { - setTimeout(this.pageLoad.bind(this), 60000); - document.addEventListener("visibilitychange", this.pageLoad.bind(this)); - document.querySelectorAll("a").forEach(anchor => { - anchor.addEventListener("click", e => this.pageLeave(e.target.closest("a").href)); - }); - } - pageLeave(target) { let params = {}; @@ -96,5 +100,17 @@ class Statistics { navigator.sendBeacon("/stats/pl", new URLSearchParams(params)); } + + takeTilesClick(url) { + let params = {}; + if (this.#load_complete && !overwrite_params.hasOwnProperty("link")) return; + + params.e_c = "Take Tiles"; + params.e_a = "Click"; + params.e_n = "Take Tiles"; + params.e_v = url; + + navigator.sendBeacon("/stats/pl", new URLSearchParams(params)); + } } export const statistics = new Statistics(); \ No newline at end of file diff --git a/metager/resources/js/utility.js b/metager/resources/js/utility.js index 1ffad047fc834b7ae96c4dbf10c64ebbb28b3ed4..510896a17407a357d226cdd09bfaefd607729766 100644 --- a/metager/resources/js/utility.js +++ b/metager/resources/js/utility.js @@ -73,4 +73,8 @@ function backButtons() { history.back(); }); }); -} \ No newline at end of file +} + +(async () => { + statistics.registerPageLoadEvents(); +})(); \ No newline at end of file