Customizing SMF > Modifications and Packages

Piwik Analytics Version 1.0.2

<< < (4/4)

Eclipse16V:
So far I do not know. As one would have to contact times of Piwik and ask there. This is an advantage to Piwik against Google Analytics.

kokett:
Hello,

will internal search tracking of piwik 1.9 be available? What's the difference between free and pro version?

Galatea:
Agreed, internal site search would be good. The quickest way to use it is not really viable for SMF users, as it expects the search results to be sent via GET and SMF sends them via POST. Would have to do some fancy capturing of results on the search results page in order for it to work.

scotty.at:

--- Quote from: maestrosite.ru on March 17, 2012, 02:21:31 PM ---This mod add <p><img .../></p> in HEAD-section.
And made pages invalid, you can check pages with installed mod

--- End quote ---

This can be fixed verry easy. Just replace the HEAD with a BODY in the stripos call. With this the tracking code will be inserted before the closing BODY tag.


--- Quote from: Galatea on November 04, 2012, 01:46:34 AM ---Agreed, internal site search would be good. The quickest way to use it is not really viable for SMF users, as it expects the search results to be sent via GET and SMF sends them via POST. Would have to do some fancy capturing of results on the search results page in order for it to work.

--- End quote ---

I coded a little addition to the sourcecode and get now the internal search tracked. Change the ob_piwik_analytics() function to the following code and you will get two things:
* Tracking code inserted before the closing </BODY> tag
* Tracking of internal search terms (no categories)Limitations/Notes:
* Search tracking works only if user has javascript enabled
* Piwik recommends not to track a page view if site search is tracked
therefore trackSiteSearch OR trackPageView depending on action
// Piwik Analytics Integration
function ob_piwik_analytics($buffer)
{
   global $modSettings;
   
   if (!empty($modSettings['PiwikAnalyticsID']) && !isset($_REQUEST['xml'])) {
      if(isset($_REQUEST['action']) && $_REQUEST['action'] == 'search2') {
         $piwik_search = addslashes($_REQUEST['search']);
         $piwik_track = 'piwikTracker.trackSiteSearch("' . $piwik_search . '", false, false);';
      } else {
         $piwik_track = 'piwikTracker.trackPageView();';
      }
      $piwik_code = '
   <!-- ' . $piwik_track . ' -->
   <script type="text/javascript">
      var pkBaseURL = (("https:" == document.location.protocol) ? "https://' . $modSettings['PiwikAnalyticsURL'] . '" : "http://' . $modSettings['PiwikAnalyticsURL'] . '");
      document.write(unescape("%3Cscript src=\'" + pkBaseURL + "piwik.js\' type=\'text/javascript\'%3E%3C/script%3E"));
      </script><script type="text/javascript">
      try {
      var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", ' . $modSettings['PiwikAnalyticsID'] . ');
      ' . $piwik_track . '
      piwikTracker.enableLinkTracking();
      } catch( err ) {}
   </script><noscript><p><img src="http://' . $modSettings['PiwikAnalyticsURL'] . 'piwik.php?idsite=' . $modSettings['PiwikAnalyticsID'] . '" style="border:0" alt="" /></p></noscript>';
     
      // add in the analytics code at the very end of the body section
      $buffer = substr_replace($buffer, $piwik_code . "\n" . '</body>', stripos($buffer, '</body>'), 7);
   }
   
   // All done
   return $buffer;
}

Navigation

[0] Message Index

[*] Previous page

Go to full version