From 9761b6a10b513ec17ae2adac0095393885181e96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ewilan=20Rivi=C3=A8re?= Date: Fri, 15 Mar 2024 15:13:29 +0100 Subject: [PATCH] Update window object initialization in JavaScript code --- src/Steward.php | 8 +++++--- src/Support/GdprSupport.php | 14 ++++++++------ src/Support/ViteDeferSupport.php | 14 ++++++++------ 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/Steward.php b/src/Steward.php index d541652c..83291f3a 100755 --- a/src/Steward.php +++ b/src/Steward.php @@ -12,9 +12,11 @@ public function embed(): string return << - window.appEnv = '$appEnv'; - window.appUrl = '$appUrl'; - window.appUrlStorage = '$appUrlStorage'; + if (typeof window !== 'undefined') { + window.appEnv = '$appEnv'; + window.appUrl = '$appUrl'; + window.appUrlStorage = '$appUrlStorage'; + } HTML; } diff --git a/src/Support/GdprSupport.php b/src/Support/GdprSupport.php index e69aab03..0883dee5 100644 --- a/src/Support/GdprSupport.php +++ b/src/Support/GdprSupport.php @@ -16,12 +16,14 @@ public function embed(): string return << HTML; diff --git a/src/Support/ViteDeferSupport.php b/src/Support/ViteDeferSupport.php index 11831c55..b9e7773d 100644 --- a/src/Support/ViteDeferSupport.php +++ b/src/Support/ViteDeferSupport.php @@ -31,12 +31,14 @@ public function embed(): string return << - window.gdprService = '$gdprService'; - window.gdprCookieName = '$gdprCookieName'; - window.gdprCookieLifetime = '$gdprCookieLifetime'; - window.gdrpMatomoEnabled = '$gdrpMatomoEnabled'; - window.gdprMatomoUrl = '$gdprMatomoUrl'; - window.gdprMatomoSiteId = '$gdprMatomoSiteId'; + if (typeof window !== 'undefined') { + window.gdprService = '$gdprService'; + window.gdprCookieName = '$gdprCookieName'; + window.gdprCookieLifetime = '$gdprCookieLifetime'; + window.gdrpMatomoEnabled = '$gdrpMatomoEnabled'; + window.gdprMatomoUrl = '$gdprMatomoUrl'; + window.gdprMatomoSiteId = '$gdprMatomoSiteId'; + } HTML; }