Closed (fixed)
Project:
Google Analytics
Version:
4.x-dev
Component:
Code
Priority:
Major
Category:
Bug report
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
14 Jan 2022 at 12:54 UTC
Updated:
7 Jul 2023 at 16:51 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
vladimirausComment #3
patrickmichael commentedI am experiencing the same. Drupal 9.3.2, PHP 8.1.1, Google Analytics 4.0.0
Comment #4
vladimirausMerge request was opened here: https://git.drupalcode.org/issue/google_analytics-3258588/-/merge_reques...
But cannot use
Open merge requestbuttonComment #5
kalpaitch commentedOk this is quite an important issue for me as it blocks most of my ajax requests (with a verbose error_level), so I'm changing the priority.
I've tested this particular patch and it all works very well for me, I can't see any issues or complications would come from merging this.
Comment #6
patrickmichael commentedI have applied the following to src/Component/Render/GoogleAnalyticsJavaScriptSnippet.php
I have cleared cache
I still see the following in my logs
Am I missing something?
Edit: this may have been a cache issue on my side. I have cleared cache a few times and I have not been able to reproduce the above error.
Comment #7
la558 commentedHello,
I experienced the same issue on D8.1
And like the previous post; multiple CR and time. Before the error went away.
Comment #8
bigbaldy commentedIt may be better to add
#[\ReturnTypeWillChange]in front of the function to block the deprecation message.mixedwas introduced in PHP 8. The#[\ReturnTypeWillChange]attribute was introduced in PHP 8.1. Google Analytics 4.0.x has a Drupal 9 compatibility which has a minimum compatibility of PHP7.3. The other alternative would be to specify a minimum PHP version in the Google Analytics 4.0.x info file.Comment #9
bigbaldy commentedPatch with
#[\ReturnTypeWillChange]attribute for PHP 8.1. For other versions of PHP it is a comment.Comment #10
bigbaldy commentedComment #12
kalpaitch commentedI'd say updating the PHP dependency now might be a touch too premature. Certainly worth considering towards the end of year when D10 and PHP7 end-of-life comes up.
Tests need updating, can get to this later.
Side note, I'm intrigued by #3258588-7: Deprecated function: Return type of Drupal\google_analytics\Component\Render\GoogleAnalyticsJavaScriptSnippet::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be u, @PatrickMichael perhaps worth checking the js is being rendered as expected.
Comment #13
bigbaldy commentedFor reference this is the Drupal 9.3 core fix for this issue [PHP 8.1] Add ReturnTypeWillChange attribute where necessary.
@kalpaitch I'm not sure this is premature as Drupal 9.3 recommends PHP 8.0 or PHP 8.1 and does not recommend PHP 7.
Comment #14
kalpaitch commentedI guess I just mean that it's not necessary to specify a minimum php version to resolve this issue, and to maximise support your solution so far in #9 is the one used in core and works.
Comment #15
fonant commentedPatch #9 works for me, and seems to be a sensible trade-off for PHP 7 and PHP 8.1 support.
Comment #16
vzamko commentedPatch that fixed all my errors on PHP 8.1 with version 2.x.
Comment #17
kfolsom commentedPatch #9 worked for me. PHP 8.1.6, MySQL 8.0.29, D9.3.14, Google Analytics module 4.0.0.
Comment #18
sundharPatch that fixed this error on PHP 8.1.
Comment #19
sundharPatch that fixed this error & deprecated codes on PHP 8.1.
Comment #20
sundharPatch that fixed this error & deprecated codes on PHP 8.1. Few more code standard changes
Comment #21
sundharComment #23
bigbaldy commentedOne issue with the patch in #20 is that the patch also needs to be tested with PHP 7.3 to meet the minimum PHP requirements of Drupal 9. The other alternative is to start a new branch for Drupal 10 that has a minimum requirement of PHP 8.1. "mixed" is not available in PHP 7.3.
Comment #24
vuilComment #25
klemendev commentedThis is a major issue for us as it is seriously filling up log files
Patch #20 works fine on PHP 8.1.
I don't think separate D10 branch is ok, as D9 also supports and recommends PHP 8.1
Comment #26
vladimirausLooks good and applies to the latest stable branch.
Comment #27
alphawebgroupsorry but #20 is failed to apply.
Comment #28
sundharHi @alphawebgroup ,
This Patch for 4.x-dev branch not for released version 4.0.0
https://www.drupal.org/project/google_analytics/releases/4.x-dev
$ composer require 'drupal/google_analytics:4.x-dev@dev' and try that patch
Comment #29
alphawebgroupyes... #20 has been applied successfully to 4.x-dev
sorry.. I was trying to apply it to 3.x-dev
thank you
returning RTBC back as it was changed by my mistake
Comment #30
glynster commentedThe patch #20 resolves the issue! +1 RTBC
Comment #31
simgui8 commented#20 fixes multiple deprecation warning here too. Thanks
Comment #32
klemendev commentedBased on the number of confirmations of good operation, I think this is ready to be merged
Comment #33
bigbaldy commentedHas anyone tested the patch with php 7+ installed? I am using php 8.1 and don't have easy access for testing google_analytics under php 7+. I'm sure there are many sites out there still running Drupal with google_analytics that are still unable to upgrade to php 7+. The "mixed" type will generate errors if run with any php version less than 8.0. Is it the intent to require the current version of google_analytics to require php 8.0 or greater? If so, adding a php requirement to the info file may be appropriate.
Comment #34
klemendev commentedI think adding a requirement for 8+ is OK, as D9 requires PHP 8.0 or higher. Source: https://www.drupal.org/docs/system-requirements/php-requirements
Comment #35
bigbaldy commented@KlemenDEV I think you are misreading the requirements for D9. Even though php 7.4+ is not recommended it is still listed as supported in the table you reference. I am not objecting to the patch but I'm sure there are still plenty of sites running D9 and google_analytics that will start receiving errors with the #20 patch.
Comment #36
bserem commentedTests have passed with PHP 7.4 though, do we need more than that?
PHP 7.4 though is not recommended any more (so it is mostly ok for a module to go forward) and is reaching EOL soon.
Comment #37
gaele commentedPHP 7.4 community support is provided until 28 November 2022, four months from now. However, PHP 7.4 is part of Ubuntu 20.04 LTS, supported until 2025, and Debian 11, supported until 2026.
Comment #38
londova commented#gaele, #bigbaldy
What is the point to delay the update, while for PHP 7.4 there is available version 8.x-3.1?
At the end - if you consider it is really important to support the PHP 7.4 as well - why you don't do this test yourself?
It sounds like "You want it" and looking for "who can do".
Comment #39
bigbaldy commented@Lodova,
I submitted a patch that works with both PHP 7.4 and 8.0+. Another patch was submitted that uses features specific to PHP 8.1 that was gathering the most support from reviewers. At the time my websites were running PHP 7.4 with Drupal 9. I was in the process of converting to PHP 8.1 and Google Analytics was breaking. This was not only a PHP issue but also an issue with Google Analytics (Google) configuration changes. I have not changed the "Reviewed & tested by the Community". I am only pointing out issues that may break for sites stuck with using PHP 7.4. It is up to the site maintainers to decide what direction they wish to take with Google Analytics version 4.x.
Comment #40
gaele commented@Londova I didn't add an opinion, I added information. As bigbaldy said, it is up to the (module -, I guess?) maintainers to decide.
(I'm using PHP 8.1 myself.)
Comment #41
bserem commentedThe newer version can add a dependency on php 8.1, so it want be automatically updated to all installations once they run `composer update`
Comment #42
bkosborneThis issue got derailed quickly! I'm not the maintainer, and I don't think they've chimed in yet, but I suspect they will want:
The most recent patch will NOT work for sites running PHP 7.x because using the "mixed" return type was added in PHP 8.0.
The patch in #9 resolves the original issue and is compatible with both PHP 7 and PHP 8. The rest of the stuff in the later patches is unrelated. There's code style updates in there and other data being cast to strings, which may be an issue, but are not reflective of what this issue was created for.
Comment #43
rymcveighI propose escalating the priority of this issue now that PHP 8.0 or higher is now recommended for Drupal 9.4.
Comment #44
adrianm6254 commentedThis patch #20 works good for me.
Environment:
Drupal 9.4.5
php 8.1.6
Comment #45
fmb commentedI agree with @bkosborne the right patch for this issue is #9.
Comment #46
ericdsd commentedI agree with @FMB and @bkosborne, this patch does no harm and allows to fix the issue with no backward compatibility issue.
By the way i don't get why it didn't pass the tests, as it's only a comment addition (seen from php 7.4 perspective).
Comment #47
bigbaldy commented@ericdsd,
I believe the test failures are a result of Drupal coding standards not liking inline Doc Blocks. Though, that is what the PHP 8.1 standard uses to resolve this issue.
Comment #48
brtamas commentedPatch for version 2.5
Comment #49
japerryThis will get resolved in the D10 readiness issue here #3287765: Automated Drupal 10 compatibility fixes -- tempted to mark this as a duplicate, but could keep it around for earlier versions of GA which will not be D10 compatible (2.x and 3.x)
Comment #50
japerryAlso, note, the patch in #9 is what will get commited. Drupal 9 will always be Drupal 7.4+ compatible, so we're not introducing the `mixed` type to this module.
Comment #52
klemendev commentedDoes 4.0.2 contain this fix?
Comment #53
chris matthews commentedIt was included in 4.0.1
Comment #54
kenrbnsn commentedI'm still seeing this issue in v4.0.2
Drupal 9.4.5
PHP 8.1.2
Comment #55
japerryHmm, this is concerning, as the change is definitely there: https://git.drupalcode.org/project/google_analytics/-/blob/4.x/src/Compo...
I haven't been able to reproduce yet, but it seems like 2 people here have seen it?
Comment #56
fathima.asmat commentedI can confirm that I can no longer produce the issue on 4.0.2.
#[\ReturnTypeWillChange]is the key change for the method in question, +1.Comment #57
fabiansierra5191 commentedI attached the patch file for version 8.x-3.1
Comment #59
rajab natshahThanks for this fix
#57 is working with
8.x-3.xHoping to consider committing the fix to the
8.x-3.xbranchComment #60
wylbur commentedThere's already a separate issue and patch addressing this in 8.x-3.1
https://www.drupal.org/project/google_analytics/issues/3312418
Comment #61
fabiansierra5191 commented