Including Flash Player version in AWStats

I was interested in what Flash Player version people are using when visiting my site. So i looked around the web for a solution including AWStats. At first i was out of luck until i noticed that AWStats has a discussion forum on sourceforge as well.
Someone there came up with a solution which was almost perfect for me.

First of all you're gonna want to put this in your awstats config file for your site:

CODE:
  1. ExtraSectionName1="Flash Player Version"
  2. ExtraSectionCodeFilter1="200 304"
  3. ExtraSectionCondition1="URL,\/flash_player_version\.php"
  4. ExtraSectionFirstColumnTitle1="Version"
  5. ExtraSectionFirstColumnValues1="QUERY_STRING,version=([^&]+)"
  6. ExtraSectionFirstColumnFormat1="%s"
  7. ExtraSectionStatTypes1=PL
  8. ExtraSectionAddAverageRow1=0
  9. ExtraSectionAddSumRow1=1
  10. MaxNbOfExtra1=100
  11. MinHitExtra1=1

Note that i made some slight adjustments to some strings compared to the original version.
Now you need to add some JavaScript to make appropriate URL requests that AWStats can read from.
Note that this is the original code, not the one i finally ended up with.

JavaScript:
  1. <script language="javascript" type="text/javascript" src="../swfobject/swfobject.js"></script>
  2.  
  3. <script type="text/javascript">
  4. var version = deconcept.SWFObjectUtil.getPlayerVersion();
  5. if (document.getElementById && version["major"]> 0) {
  6. var flash_version = version['major'] +"."+ version['minor'] +"."+ version['rev'];
  7. document.getElementById('flashversion').innerHTML = "<iframe src=\"../version.php?version=" + flash_version + "\" style=\"display: none;\"></iframe>";
  8. }
  9. </script>

As i did not want to just jam this into my theme files, i wrote a little Wordpress plugin to do the above task.

PHP:
  1. <?php
  2. /*
  3. Plugin Name: Flash Player Version Detection
  4. Plugin URI: http://www.dirty-motherfucker.org/
  5. Description: Detects flash version
  6. Version: 0.1
  7. Author: gencha
  8. Author URI: http://www.dirty-motherfucker.org
  9. */
  10.  
  11. $plugin_root = get_settings('siteurl') . '/wp-content/plugins/'.dirname(plugin_basename(__FILE__));
  12.  
  13. if( preg_match("/(\/\?feed=|\/feed)/i",$_SERVER['REQUEST_URI']) ) {
  14.         // RSS Feeds
  15.         // do nothing
  16. } else {
  17.         add_action('wp_head', 'add_head');
  18. }
  19.  
  20. function add_head() {
  21.     global $plugin_root;
  22.     echo '
  23.         <!-- Flash player version detection -->
  24.         <script src="' . $plugin_root . '/swfobject.js" type="text/javascript"></script>
  25.         <script src="' . $plugin_root . '/flash_version.js" type="text/javascript"></script>
  26.     ';
  27. }
  28. ?>

I took some small bits from the KML Flash Embed plugin. This will include the appropriate JavaScript files in your blog. Obviously, if you're not using Wordpress, this is of no use to you. You can just directly include SWFObject in the head section of your site.

Now the important bit is the JavaScript file that actually performs the URL request which AWStats will later see.

JavaScript:
  1. window.onload = function() {
  2.     var version = deconcept.SWFObjectUtil.getPlayerVersion();
  3.     if( document.getElementById && version["major"]> 0 ) {
  4.         var flash_version = version['major'] +"."+ version['minor'] +"."+ version['rev'];
  5.         document.getElementById("flashversion").innerHTML = "<iframe src=\"../flash_player_version.php?version=" + flash_version + "\" style=\"display: none;\"></iframe>";
  6.     }
  7. }

Now the only thing that is left is that you include an empty div tag with the id "flashversion" somewhere in your site. Now THIS i did just jam into my theme :P
Although i am sure there is some hook i can use in the Wordpress plugin architecture. But i'm lazy. So there you have it.

Leave a Reply

You must be logged in to post a comment.