After re-enabling this module after a site migration, the site was not working, the following message was printed in the logs:

Error: [] operator not supported for strings in replace_google_analytics_counter_tags() (line 220 of /var/www/html/web/sites/all/modules/contrib/google_analytics_counter/google_analytics_counter.module).

The following patch seems to have solved the issue. I've initialized the variables $matchlink, $orig_match and $matches as arrays instead of strings.

Comments

felubra created an issue. See original summary.

felubra’s picture

Title: Error: [] operator not supported for strings em replace_google_analytics_counter_tags() » Error: [] operator not supported for strings in replace_google_analytics_counter_tags()
felubra’s picture

Issue summary: View changes
ktch_my’s picture

Version: 7.x-3.x-dev » 8.x-3.x-dev

I'm having the same error on Drupal 8 version of the module.
2 different server rule out PHP possibility.
Changing weight between Token Filter and GA Counter Token Filter in Text Formatter doesn't help.
Installed via composer ^3.0@alpha
Drupal 8.7

Error: [] operator not supported for strings in Drupal\google_analytics_counter\Plugin\Filter\GoogleAnalyticsCounterFilter->handleText() (line 121 of google_analytics_counter/src/Plugin/Filter/GoogleAnalyticsCounterFilter.php)

Applied the D7 patches
And I get a lot of errors such as:
Notice: Undefined variable: original_match in Drupal\google_analytics_counter\Plugin\Filter\GoogleAnalyticsCounterFilter->handleText() (line 157 of modules/contrib/google_analytics_counter/src/Plugin/Filter/GoogleAnalyticsCounterFilter.php).
Notice: Array to string conversion in Drupal\google_analytics_counter\Plugin\Filter\GoogleAnalyticsCounterFilter->handleText() (line 157 of modules/contrib/google_analytics_counter/src/Plugin/Filter/GoogleAnalyticsCounterFilter.php).

  • 10fabe4 committed on 7.x-3.x
    Issue #2980752 by felubra: Error: [] operator not supported for strings...
vacilando’s picture

FYI: fixed in the D7 version.

felubra’s picture

Thanks!

esod’s picture

Hi. I'll have a look at the Drupal 8.x version.

mazerrati’s picture

Just in case someone's still stuck with this...

For Drupal 8.x version, apply the patch to:

/modules/google_analytics_counter/src/Plugin/Filter/GoogleAnalyticsCounterFilter.php

esod’s picture

Thanks for the patch. Here's the 8.x-3.x-dev patch.

  • esod committed d1bec8b on 8.x-3.x
    Issue #2980752. operator not supported for strings
    
kaszarobert’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.