]> _ Git - bastide-resah.git/commitdiff
wip #6889 @0.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 30 Apr 2024 16:24:12 +0000 (18:24 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 30 Apr 2024 16:24:12 +0000 (18:24 +0200)
app/Http/Controllers/CatalogController.php
app/Http/Controllers/LandingController.php

index 6bfff96e37bd0ef1fdfaa7fec4176f6a1c2707b0..231ce90957b0740300b80293c32313d70ae7e263 100644 (file)
@@ -3,7 +3,7 @@
 namespace App\Http\Controllers;
 
 use Cubist\Backpack\Http\Controllers\Base\XSendFileController;
-use Cubist\Util\PHP;
+use Illuminate\Support\Facades\Auth;
 
 class CatalogController extends Controller
 {
@@ -19,6 +19,15 @@ class CatalogController extends Controller
         $cpath = $forceGuest || auth()->guard('client')->guest() ? 'fluidbooks/catalogue_invite' : 'fluidbooks/catalogue';
 
         $relayPath = base_path($cpath) . '/' . $path;
+
+        $user = Auth::guard('client')->user();
+        if ($path === 'index.html' && $user) {
+            $html = file_get_contents($relayPath);
+            $html = str_replace('</head>', '<script>MATOMO_USER_ID="' . $user->email . '";</script></head>', $html);
+            return response($html)->header('Content-Type', 'text/html');
+
+        }
+
         return XSendFileController::sendfileNoCache($relayPath);
     }
 
index 461603daf09b5cc8ccecef330482c97626062305..ecbd126ac4691d4a0f5a254b45de40a318aea310 100644 (file)
@@ -7,7 +7,7 @@ use Illuminate\Support\Facades\Auth;
 
 class LandingController extends Controller
 {
-  use ForgotPassword;
+    use ForgotPassword;
 
     public function catchall($path = '')
     {
@@ -22,7 +22,7 @@ class LandingController extends Controller
         $relayPath = resource_path('webflow') . '/' . $path;
         if (str_ends_with($path, '.html')) {
             $html = file_get_contents($relayPath);
-            $html = str_replace('</head>', '<meta name="csrf-token" content="' . csrf_token() . '"/></head>', $html);
+            $html = str_replace('</head>', '<meta name="csrf-token" content="' . csrf_token() . '"/>' . self::matomoTag() . '</head>', $html);
             $user = Auth::guard('client')->user();
             if ($user) {
                 $html = str_replace('PrĂ©nom Nom', $user->firstname . ' ' . $user->name, $html);
@@ -33,6 +33,33 @@ class LandingController extends Controller
         return XSendFileController::sendfile($relayPath);
     }
 
+    public static function matomoTag()
+    {
+        $guard = Auth::guard('client');
+
+        $user = '';
+        if (!$guard->guest()) {
+            $user = "_paq.push(['setUserId', '" . $guard->user()->email . "']);";
+        }
+
+        return "<!-- Matomo -->
+<script>
+  var _paq = window._paq = window._paq || [];
+  /* tracker methods like \"setCustomDimension\" should be called before \"trackPageView\" */
+  _paq.push(['trackPageView']);
+  $user
+  _paq.push(['enableLinkTracking']);
+  (function() {
+    var u=\"//matomo.bastide-resah.fluidbook.com/\";
+    _paq.push(['setTrackerUrl', u+'matomo.php']);
+    _paq.push(['setSiteId', '1']);
+    var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
+    g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
+  })();
+</script>
+<!-- End Matomo Code -->";
+    }
+
     public function login()
     {
         $request = request();