powerthazan / YOURLS-GA-MP-Tracking

Track YOURLS link clicks with Google Analytics Measurement protocol in Real Time
MIT License
38 stars 7 forks source link

PHP 7, YOURLS 2.0 #5

Open seventhsite opened 8 years ago

seventhsite commented 8 years ago

Not working with PHP 7.0. I recieve an error when tried to Activate plugin:

Fatal error: Uncaught Error: Call to undefined function split() in /var/www/ali.onl/user/plugins/ga-measurement-protocol/plugin.php:40 Stack trace: #0 /var/www/ali.onl/user/plugins/ga-measurement-protocol/plugin.php(69): power_ga_mp_gaParseCookie() #1 /var/www/ali.onl/includes/functions-plugins.php(152): power_ga_mp(Array) #2 /var/www/ali.onl/includes/functions-plugins.php(191): yourls_apply_filter('pre_redirect', Array) #3 /var/www/ali.onl/includes/functions.php(684): yourls_do_action('pre_redirect', 'http://ali.onl/...', 302) #4 /var/www/ali.onl/includes/admin/plugins.php(37): yourls_redirect('http://ali.onl/...', 302) #5 /var/www/ali.onl/yourls-loader.php(28): require_once('/var/www/ali.on...') #6 {main} thrown in /var/www/ali.onl/user/plugins/ga-measurement-protocol/plugin.php on line 40

Same error on each link click.

Ubuntu 14.04.5 LTS Apache/2.4.7 PHP 7.0.9-1+deb.sury.org~trusty+1 YOURLS 2.0

seventhsite commented 8 years ago

I tried to modify line 40 in plugin.php from list($version,$domainDepth, $cid1, $cid2) = split('[\.]', $_COOKIE["_ga"],4); to list($version,$domainDepth, $cid1, $cid2) = explode('[\.]', $_COOKIE["_ga"],4); All work allright and error is gone. But I don't sure is it right way?

powerthazan commented 8 years ago

Yes. Your are right.It was happened by PHP 7 Incompatibility.

thomas-richter commented 7 years ago

I do not think this fix is correct. split() uses a (non-perl) regular expression, while explode() uses a constant string. split('[.]') seems to be an elaborate way to simply split on a dot - which makes sense, as a _ga cookie looks like this: GA1.2.1858301290.1402971173

So the line should probably read: list($version,$domainDepth, $cid1, $cid2) = explode('.', $_COOKIE["_ga"],4);