tra('Google Analytics'), 'documentation' => 'PluginGoogleAnalytics', 'description' => tra('Add the tracking code for Google Analytics'), 'prefs' => [ 'wikiplugin_googleanalytics' ], 'iconname' => 'chart', 'format' => 'html', 'introduced' => 14, 'params' => [ 'account' => [ 'required' => true, 'name' => tra('Account Number'), 'description' => tr('The account number for the site. Your account number from Google looks like %0. All you need to enter is %1', 'UA-XXXXXXX-YY', 'XXXXXXX-YY'), 'since' => '3.0', 'filter' => 'text', 'default' => '' ], 'group_option' => [ 'required' => true, 'name' => tra('Groups Option'), 'description' => tr('Define option for Google Analytics groups, include or exclude'), 'filter' => 'text', 'default' => '' ], 'groups' => [ 'required' => true, 'name' => tra('Available Groups'), 'description' => tr('User groups for which Google Analytics will be available'), 'default' => '' ], ], ]; } function wikiplugin_googleanalytics($data, $params) { global $feature_no_cookie_analytics, $prefs; // set according to cookie_consent_feature pref in tiki-setup.php $showCode = WikiPlugin_Helper::showAnalyticsCode($params); if (! $showCode) { return; } if (empty($params['account'])) { return tra('Missing parameter'); } if ($feature_no_cookie_analytics) { return ''; } $account = htmlspecialchars($params['account'], ENT_QUOTES); if ($prefs['site_google_analytics_gtag'] !== 'y') { $ret = << (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-$account', 'auto'); // Replace with your property ID. ga('send', 'pageview'); HTML; } else { $ret = << HTML; } return $ret; }