function onAfterDispatch()
 {
     if (JFactory::getApplication()->isAdmin()) {
         return;
     }
     if (JFactory::getApplication()->getCfg('sef') == 0) {
         return;
     }
     if (JFactory::getURI()->getVar('tmpl') == 'component') {
         return;
     }
     $config = SEFConfig::getConfig();
     if (!$config->enabled) {
         return;
     }
     if ($config->google_enable == 0) {
         return;
     }
     if (JRequest::getInt('google_analytics_exclude', 0, 'cookie') == 1) {
         return;
     }
     $ips_exclude = explode("\r\n", $config->google_exclude_ip);
     if (in_array(IPAddressHelper::getip(), $ips_exclude)) {
         return;
     }
     $user = JFactory::getUser();
     if (in_array($user->gid, $config->google_exclude_level)) {
         return;
     }
     JFactory::getDocument()->addScriptDeclaration(" var _gaq = _gaq || [];\n  _gaq.push(['_setAccount', '" . $config->google_id . "']);\n  _gaq.push(['_trackPageview']);\n\n  (function() {\n    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;\n    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';\n    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);\n  })();\n");
 }
Beispiel #2
0
 function onAfterDispatch()
 {
     if (JFactory::getApplication()->isAdmin()) {
         return;
     }
     if (JFactory::getApplication()->getCfg('sef') == 0) {
         return;
     }
     if (JFactory::getURI()->getVar('tmpl') == 'component') {
         return;
     }
     $config = SEFConfig::getConfig();
     if (!$config->enabled) {
         return;
     }
     if ($config->google_enable == 0) {
         return;
     }
     if (JRequest::getInt('google_analytics_exclude', 0, 'cookie') == 1) {
         return;
     }
     $ips_exclude = explode("\r\n", $config->google_exclude_ip);
     if (in_array(IPAddressHelper::getip(), $ips_exclude)) {
         return;
     }
     $groups = null;
     $user = JFactory::getUser();
     if ($user) {
         $groups = $user->get('groups');
     }
     if (is_array($groups)) {
         foreach ($groups as $group) {
             if (in_array($group, $config->google_exclude_level)) {
                 return;
             }
         }
     }
     $script = "  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){\r\n  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),\r\n  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)\r\n  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');\r\n\r\n  ga('create', '" . htmlspecialchars($config->google_id) . "', 'auto');\n";
     if ($config->google_demographic_reports) {
         $script .= "  ga('require', 'displayfeatures');\n";
     }
     if ($config->google_link_attribution) {
         $script .= "  ga('require', 'linkid', 'linkid.js');\n";
     }
     $script .= "  ga('send', 'pageview');\n";
     JFactory::getDocument()->addScriptDeclaration($script);
 }