Created
September 29, 2022 17:25
-
-
Save ivangrozni/ef7e15ff3923a51bfb7aeeed00bbceda to your computer and use it in GitHub Desktop.
Google analytics 3.x php8.1 compatibility
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/google_analytics.module b/google_analytics.module | |
index 0182a5d..83184ff 100644 | |
--- a/google_analytics.module | |
+++ b/google_analytics.module | |
@@ -270,7 +270,7 @@ function google_analytics_page_attachments(array &$page) { | |
// Per RFC 2109, cookie domains must contain at least one dot other than the | |
// first. For hosts such as 'localhost' or IP Addresses we don't set a | |
// cookie domain. | |
- if ($domain_mode == 1 && count(explode('.', $cookie_domain)) > 2 && !is_numeric(str_replace('.', '', $cookie_domain))) { | |
+ if ($domain_mode == 1 && count(explode('.', $cookie_domain ?? '')) > 2 && !is_numeric(str_replace('.', '', $cookie_domain))) { | |
$arguments = array_merge($arguments, ['cookie_domain' => $cookie_domain]); | |
$googleanalytics_adsense_script .= 'window.google_analytics_domain_name = ' . Json::encode($cookie_domain) . ';'; | |
} | |
diff --git a/src/Form/GoogleAnalyticsAdminSettingsForm.php b/src/Form/GoogleAnalyticsAdminSettingsForm.php | |
index 2ab6e17..467e78c 100644 | |
--- a/src/Form/GoogleAnalyticsAdminSettingsForm.php | |
+++ b/src/Form/GoogleAnalyticsAdminSettingsForm.php | |
@@ -110,7 +110,7 @@ class GoogleAnalyticsAdminSettingsForm extends ConfigFormBase { | |
global $cookie_domain; | |
$multiple_sub_domains = []; | |
foreach (['www', 'app', 'shop'] as $subdomain) { | |
- if (count(explode('.', $cookie_domain)) > 2 && !is_numeric(str_replace('.', '', $cookie_domain))) { | |
+ if (count(explode('.', $cookie_domain ?? '')) > 2 && !is_numeric(str_replace('.', '', $cookie_domain))) { | |
$multiple_sub_domains[] = $subdomain . $cookie_domain; | |
} | |
// IP addresses or localhost. | |
@@ -123,7 +123,7 @@ class GoogleAnalyticsAdminSettingsForm extends ConfigFormBase { | |
foreach (['.com', '.net', '.org'] as $tldomain) { | |
$host = $_SERVER['HTTP_HOST']; | |
$domain = substr($host, 0, strrpos($host, '.')); | |
- if (count(explode('.', $host)) > 2 && !is_numeric(str_replace('.', '', $host))) { | |
+ if (count(explode('.', $host ?? '')) > 2 && !is_numeric(str_replace('.', '', $host))) { | |
$multiple_toplevel_domains[] = $domain . $tldomain; | |
} | |
// IP addresses or localhost. | |
@@ -884,7 +884,7 @@ class GoogleAnalyticsAdminSettingsForm extends ConfigFormBase { | |
protected static function extractParameterValues($string) { | |
$values = []; | |
- $list = explode("\n", $string); | |
+ $list = explode("\n", $string ?? ''); | |
$list = array_map('trim', $list); | |
$list = array_filter($list, 'strlen'); | |
diff --git a/tests/src/Functional/GoogleAnalyticsBasicTest.php b/tests/src/Functional/GoogleAnalyticsBasicTest.php | |
index 3e1de41..d6c96f4 100644 | |
--- a/tests/src/Functional/GoogleAnalyticsBasicTest.php | |
+++ b/tests/src/Functional/GoogleAnalyticsBasicTest.php | |
@@ -273,7 +273,7 @@ class GoogleAnalyticsBasicTest extends BrowserTestBase { | |
// TODO: Workaround to run tests successfully. This feature cannot tested | |
// reliable. | |
global $cookie_domain; | |
- if (count(explode('.', $cookie_domain)) > 2 && !is_numeric(str_replace('.', '', $cookie_domain))) { | |
+ if (count(explode('.', $cookie_domain ?? '')) > 2 && !is_numeric(str_replace('.', '', $cookie_domain))) { | |
$this->assertRaw('"cookie_domain":"' . $cookie_domain . '"'); | |
} | |
else { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment